fake_sync_worker.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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 drive::DriveServiceInterface* GetDriveService() OVERRIDE;
89  virtual drive::DriveUploaderInterface* GetDriveUploader() OVERRIDE;
90  virtual MetadataDatabase* GetMetadataDatabase() OVERRIDE;
91  virtual SyncTaskManager* GetSyncTaskManager() OVERRIDE;
92  virtual void DetachFromSequence() OVERRIDE;
93  virtual void AddObserver(Observer* observer) OVERRIDE;
94
95 private:
96  friend class SyncEngineTest;
97
98  enum AppStatus {
99    REGISTERED,
100    ENABLED,
101    DISABLED,
102    UNINSTALLED,
103  };
104  typedef std::map<GURL, AppStatus> StatusMap;
105
106  // TODO(peria): Change this method to be non-virtual.
107  virtual void SetHasRefreshToken(bool has_refresh_token) OVERRIDE;
108
109  void UpdateServiceState(RemoteServiceState state,
110                          const std::string& description);
111
112  bool sync_enabled_;
113  StatusMap status_map_;
114  bool has_refresh_token_;
115  bool network_available_;
116
117  scoped_ptr<SyncEngineContext> sync_engine_context_;
118
119  ObserverList<Observer> observers_;
120  base::SequenceChecker sequence_checker_;
121
122  DISALLOW_COPY_AND_ASSIGN(FakeSyncWorker);
123};
124
125}  // namespace drive_backend
126}  // namespace sync_file_system
127
128#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_SYNC_WORKER_H_
129