fake_sync_worker.h revision 116680a4aac90f2aa7413d9095a592090648e557
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_SYNC_WORKER_H_
6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_SYNC_WORKER_H_
7
8#include <map>
9#include <string>
10
11#include "base/callback.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/observer_list.h"
14#include "base/sequence_checker.h"
15#include "chrome/browser/sync_file_system/drive_backend/sync_worker_interface.h"
16#include "chrome/browser/sync_file_system/remote_file_sync_service.h"
17#include "chrome/browser/sync_file_system/sync_callbacks.h"
18#include "net/base/network_change_notifier.h"
19
20class GURL;
21
22namespace base {
23class FilePath;
24class ListValue;
25}
26
27namespace drive {
28class DriveServiceInterface;
29class DriveUploaderInterface;
30}
31
32namespace fileapi {
33class FileSystemURL;
34}
35
36namespace sync_file_system {
37
38class FileChange;
39class SyncFileMetadata;
40
41namespace drive_backend {
42
43class MetadataDatabase;
44class RemoteChangeProcessorOnWorker;
45class SyncEngineContext;
46class SyncTaskManager;
47
48class FakeSyncWorker : public SyncWorkerInterface {
49 public:
50  FakeSyncWorker();
51  virtual ~FakeSyncWorker();
52
53  // SyncWorkerInterface overrides.
54  virtual void Initialize(
55      scoped_ptr<SyncEngineContext> sync_engine_context) OVERRIDE;
56  virtual void RegisterOrigin(const GURL& origin,
57                              const SyncStatusCallback& callback) OVERRIDE;
58  virtual void EnableOrigin(const GURL& origin,
59                            const SyncStatusCallback& callback) OVERRIDE;
60  virtual void DisableOrigin(const GURL& origin,
61                             const SyncStatusCallback& callback) OVERRIDE;
62  virtual void UninstallOrigin(
63      const GURL& origin,
64      RemoteFileSyncService::UninstallFlag flag,
65      const SyncStatusCallback& callback) OVERRIDE;
66  virtual void ProcessRemoteChange(const SyncFileCallback& callback) OVERRIDE;
67  virtual void SetRemoteChangeProcessor(
68      RemoteChangeProcessorOnWorker* remote_change_processor_on_worker)
69      OVERRIDE;
70  virtual RemoteServiceState GetCurrentState() const OVERRIDE;
71  virtual void GetOriginStatusMap(
72      const RemoteFileSyncService::StatusMapCallback& callback) OVERRIDE;
73  virtual scoped_ptr<base::ListValue> DumpFiles(const GURL& origin) OVERRIDE;
74  virtual scoped_ptr<base::ListValue> DumpDatabase() OVERRIDE;
75  virtual void SetSyncEnabled(bool enabled) OVERRIDE;
76  virtual void PromoteDemotedChanges() OVERRIDE;
77  virtual void ApplyLocalChange(
78      const FileChange& local_change,
79      const base::FilePath& local_path,
80      const SyncFileMetadata& local_metadata,
81      const fileapi::FileSystemURL& url,
82      const SyncStatusCallback& callback) OVERRIDE;
83  virtual void OnNotificationReceived() OVERRIDE;
84  virtual void OnReadyToSendRequests() OVERRIDE;
85  virtual void OnRefreshTokenInvalid() OVERRIDE;
86  virtual void OnNetworkChanged(
87      net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
88  virtual void DetachFromSequence() OVERRIDE;
89  virtual void AddObserver(Observer* observer) OVERRIDE;
90
91 private:
92  friend class SyncEngineTest;
93
94  enum AppStatus {
95    REGISTERED,
96    ENABLED,
97    DISABLED,
98    UNINSTALLED,
99  };
100  typedef std::map<GURL, AppStatus> StatusMap;
101
102  // TODO(peria): Change this method to be non-virtual.
103  virtual void SetHasRefreshToken(bool has_refresh_token) OVERRIDE;
104
105  void UpdateServiceState(RemoteServiceState state,
106                          const std::string& description);
107
108  bool sync_enabled_;
109  StatusMap status_map_;
110  bool has_refresh_token_;
111  bool network_available_;
112
113  scoped_ptr<SyncEngineContext> sync_engine_context_;
114
115  ObserverList<Observer> observers_;
116  base::SequenceChecker sequence_checker_;
117
118  DISALLOW_COPY_AND_ASSIGN(FakeSyncWorker);
119};
120
121}  // namespace drive_backend
122}  // namespace sync_file_system
123
124#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_SYNC_WORKER_H_
125