Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/fake_sync_worker.h

Issue 327323006: [SyncFS] Create FakeSyncWorker class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_SYNC_WORKER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_SYNC_WORKER_H_
7 7
8 #include <map>
8 #include <string> 9 #include <string>
9 10
10 #include "base/files/file_path.h" 11 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" 15 #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/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/remote_file_sync_service.h"
17 #include "chrome/browser/sync_file_system/sync_callbacks.h" 18 #include "chrome/browser/sync_file_system/sync_callbacks.h"
18 #include "chrome/browser/sync_file_system/task_logger.h"
19 #include "net/base/network_change_notifier.h" 19 #include "net/base/network_change_notifier.h"
20 20
21 class ExtensionServiceInterface; 21 class ExtensionServiceInterface;
22 class GURL; 22 class GURL;
23 23
24 namespace base { 24 namespace base {
25 class FilePath;
25 class ListValue; 26 class ListValue;
26 } 27 }
27 28
28 namespace drive { 29 namespace drive {
29 class DriveServiceInterface; 30 class DriveServiceInterface;
30 class DriveUploaderInterface; 31 class DriveUploaderInterface;
31 } 32 }
32 33
33 namespace fileapi { 34 namespace fileapi {
34 class FileSystemURL; 35 class FileSystemURL;
35 } 36 }
36 37
37 namespace leveldb { 38 namespace leveldb {
38 class Env; 39 class Env;
39 } 40 }
40 41
41 namespace sync_file_system { 42 namespace sync_file_system {
42 43
43 class FileChange; 44 class FileChange;
44 class SyncFileMetadata; 45 class SyncFileMetadata;
45 46
46 namespace drive_backend { 47 namespace drive_backend {
47 48
48 class LocalToRemoteSyncer;
49 class MetadataDatabase; 49 class MetadataDatabase;
50 class RemoteChangeProcessorOnWorker; 50 class RemoteChangeProcessorOnWorker;
51 class RemoteToLocalSyncer;
52 class SyncEngineContext; 51 class SyncEngineContext;
53 class SyncEngineInitializer; 52 class SyncEngineInitializer;
53 class SyncTaskManager;
54 54
55 class SyncWorker : public SyncWorkerInterface, 55 class FakeSyncWorker : public SyncWorkerInterface {
56 public SyncTaskManager::Client {
57 public: 56 public:
58 SyncWorker(const base::FilePath& base_dir, 57 FakeSyncWorker(
59 const base::WeakPtr<ExtensionServiceInterface>& extension_service, 58 const base::FilePath& base_dir,
60 scoped_ptr<SyncEngineContext> sync_engine_context, 59 scoped_ptr<SyncEngineContext> sync_engine_context,
61 leveldb::Env* env_override); 60 leveldb::Env* env_override);
61 virtual ~FakeSyncWorker();
62 62
63 virtual ~SyncWorker(); 63 // Initializes SyncWorkerInterface after constructions of some member classes.
64
65 virtual void Initialize() OVERRIDE; 64 virtual void Initialize() OVERRIDE;
66 65
67 // SyncTaskManager::Client overrides 66 // See RemoteFileSyncService for the details.
nhiroki 2014/06/12 08:00:08 I think you don't have to repeat these comments wr
peria 2014/06/12 10:49:30 Done.
68 virtual void MaybeScheduleNextTask() OVERRIDE;
69 virtual void NotifyLastOperationStatus(
70 SyncStatusCode sync_status, bool used_network) OVERRIDE;
71 virtual void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) OVERRIDE;
72
73 // SyncWorkerInterface overrides
74 virtual void RegisterOrigin(const GURL& origin, 67 virtual void RegisterOrigin(const GURL& origin,
75 const SyncStatusCallback& callback) OVERRIDE; 68 const SyncStatusCallback& callback) OVERRIDE;
76 virtual void EnableOrigin(const GURL& origin, 69 virtual void EnableOrigin(const GURL& origin,
77 const SyncStatusCallback& callback) OVERRIDE; 70 const SyncStatusCallback& callback) OVERRIDE;
78 virtual void DisableOrigin(const GURL& origin, 71 virtual void DisableOrigin(const GURL& origin,
79 const SyncStatusCallback& callback) OVERRIDE; 72 const SyncStatusCallback& callback) OVERRIDE;
80 virtual void UninstallOrigin(const GURL& origin, 73 virtual void UninstallOrigin(
81 RemoteFileSyncService::UninstallFlag flag, 74 const GURL& origin,
82 const SyncStatusCallback& callback) OVERRIDE; 75 RemoteFileSyncService::UninstallFlag flag,
76 const SyncStatusCallback& callback) OVERRIDE;
83 virtual void ProcessRemoteChange(const SyncFileCallback& callback) OVERRIDE; 77 virtual void ProcessRemoteChange(const SyncFileCallback& callback) OVERRIDE;
84 virtual void SetRemoteChangeProcessor( 78 virtual void SetRemoteChangeProcessor(
85 RemoteChangeProcessorOnWorker* remote_change_processor_on_worker) 79 RemoteChangeProcessorOnWorker* remote_change_processor_on_worker)
86 OVERRIDE; 80 OVERRIDE;
87 virtual RemoteServiceState GetCurrentState() const OVERRIDE; 81 virtual RemoteServiceState GetCurrentState() const OVERRIDE;
88 virtual void GetOriginStatusMap( 82 virtual void GetOriginStatusMap(
89 const RemoteFileSyncService::StatusMapCallback& callback) OVERRIDE; 83 const RemoteFileSyncService::StatusMapCallback& callback) OVERRIDE;
90 virtual scoped_ptr<base::ListValue> DumpFiles(const GURL& origin) OVERRIDE; 84 virtual scoped_ptr<base::ListValue> DumpFiles(const GURL& origin) OVERRIDE;
91 virtual scoped_ptr<base::ListValue> DumpDatabase() OVERRIDE; 85 virtual scoped_ptr<base::ListValue> DumpDatabase() OVERRIDE;
92 virtual void SetSyncEnabled(bool enabled) OVERRIDE; 86 virtual void SetSyncEnabled(bool enabled) OVERRIDE;
93 virtual void PromoteDemotedChanges() OVERRIDE; 87 virtual void PromoteDemotedChanges() OVERRIDE;
94 88
89 // See LocalChangeProcessor for the details.
95 virtual void ApplyLocalChange( 90 virtual void ApplyLocalChange(
96 const FileChange& local_change, 91 const FileChange& local_change,
97 const base::FilePath& local_path, 92 const base::FilePath& local_path,
98 const SyncFileMetadata& local_metadata, 93 const SyncFileMetadata& local_metadata,
99 const fileapi::FileSystemURL& url, 94 const fileapi::FileSystemURL& url,
100 const SyncStatusCallback& callback) OVERRIDE; 95 const SyncStatusCallback& callback) OVERRIDE;
101 96
97 // See drive::DriveNotificationObserver for the details.
102 virtual void OnNotificationReceived() OVERRIDE; 98 virtual void OnNotificationReceived() OVERRIDE;
103 99
100 // See drive::DriveServiceObserver for the details.
104 virtual void OnReadyToSendRequests(const std::string& account_id) OVERRIDE; 101 virtual void OnReadyToSendRequests(const std::string& account_id) OVERRIDE;
105 virtual void OnRefreshTokenInvalid() OVERRIDE; 102 virtual void OnRefreshTokenInvalid() OVERRIDE;
106 103
104 // See net::NetworkChangeNotifier::NetworkChangeObserver for the details.
107 virtual void OnNetworkChanged( 105 virtual void OnNetworkChanged(
108 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 106 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
109 107
110 virtual drive::DriveServiceInterface* GetDriveService() OVERRIDE; 108 virtual drive::DriveServiceInterface* GetDriveService() OVERRIDE;
111 virtual drive::DriveUploaderInterface* GetDriveUploader() OVERRIDE; 109 virtual drive::DriveUploaderInterface* GetDriveUploader() OVERRIDE;
112 virtual MetadataDatabase* GetMetadataDatabase() OVERRIDE; 110 virtual MetadataDatabase* GetMetadataDatabase() OVERRIDE;
113 virtual SyncTaskManager* GetSyncTaskManager() OVERRIDE; 111 virtual SyncTaskManager* GetSyncTaskManager() OVERRIDE;
114 112
115 virtual void DetachFromSequence() OVERRIDE; 113 virtual void DetachFromSequence() OVERRIDE;
116 114
117 virtual void AddObserver(Observer* observer) OVERRIDE; 115 virtual void AddObserver(Observer* observer) OVERRIDE;
118 116
117 void UpdateServiceStateForTesting(RemoteServiceState state,
118 const std::string& description,
119 const base::Closure& closure);
120
119 private: 121 private:
120 friend class DriveBackendSyncTest; 122 typedef std::map<GURL, bool> StatusMap;
121 friend class SyncWorkerTest;
122 123
123 enum AppStatus {
124 APP_STATUS_ENABLED,
125 APP_STATUS_DISABLED,
126 APP_STATUS_UNINSTALLED,
127 };
128
129 typedef base::hash_map<std::string, AppStatus> AppStatusMap;
130
131 // SyncWorkerInterface overrides.
132 // TODO(peria): Remove this interface after making FakeSyncWorker class. 124 // TODO(peria): Remove this interface after making FakeSyncWorker class.
133 virtual void SetHasRefreshToken(bool has_refresh_token) OVERRIDE; 125 virtual void SetHasRefreshToken(bool has_refresh_token) OVERRIDE;
134 126
135 void DoDisableApp(const std::string& app_id,
136 const SyncStatusCallback& callback);
137 void DoEnableApp(const std::string& app_id,
138 const SyncStatusCallback& callback);
139
140 void PostInitializeTask();
141 void DidInitialize(SyncEngineInitializer* initializer,
142 SyncStatusCode status);
143 void UpdateRegisteredApps();
144 static void QueryAppStatusOnUIThread(
145 const base::WeakPtr<ExtensionServiceInterface>& extension_service_ptr,
146 const std::vector<std::string>* app_ids,
147 AppStatusMap* status,
148 const base::Closure& callback);
149 void DidQueryAppStatus(const AppStatusMap* app_status);
150 void DidProcessRemoteChange(RemoteToLocalSyncer* syncer,
151 const SyncFileCallback& callback,
152 SyncStatusCode status);
153 void DidApplyLocalChange(LocalToRemoteSyncer* syncer,
154 const SyncStatusCallback& callback,
155 SyncStatusCode status);
156
157 void MaybeStartFetchChanges();
158 void DidResolveConflict(SyncStatusCode status);
159 void DidFetchChanges(SyncStatusCode status);
160
161 void UpdateServiceStateFromSyncStatusCode(SyncStatusCode state,
162 bool used_network);
163 void UpdateServiceState(RemoteServiceState state, 127 void UpdateServiceState(RemoteServiceState state,
164 const std::string& description); 128 const std::string& description);
129 void DidCreateMetadataDatabase(
130 SyncStatusCode status,
131 scoped_ptr<MetadataDatabase> metadata_database);
165 132
166 base::FilePath base_dir_; 133 const base::FilePath base_dir_;
167 134 scoped_ptr<SyncEngineContext> sync_engine_context_;
168 leveldb::Env* env_override_; 135 leveldb::Env* env_override_;
169 136
170 // Sync with SyncEngine.
171 RemoteServiceState service_state_;
172
173 bool should_check_conflict_;
174 bool should_check_remote_change_;
175 bool listing_remote_changes_;
176 base::TimeTicks time_to_check_changes_;
177
178 bool sync_enabled_; 137 bool sync_enabled_;
179 ConflictResolutionPolicy default_conflict_resolution_policy_; 138 StatusMap status_map_;
139 bool has_refresh_token_;
180 bool network_available_; 140 bool network_available_;
181 141
182 scoped_ptr<SyncTaskManager> task_manager_;
183
184 base::WeakPtr<ExtensionServiceInterface> extension_service_;
185
186 scoped_ptr<SyncEngineContext> context_;
187 ObserverList<Observer> observers_; 142 ObserverList<Observer> observers_;
188
189 bool has_refresh_token_;
190
191 base::SequenceChecker sequence_checker_; 143 base::SequenceChecker sequence_checker_;
192 144
193 base::WeakPtrFactory<SyncWorker> weak_ptr_factory_; 145 base::WeakPtrFactory<FakeSyncWorker> weak_ptr_factory_;
194 DISALLOW_COPY_AND_ASSIGN(SyncWorker); 146 DISALLOW_COPY_AND_ASSIGN(FakeSyncWorker);
195 }; 147 };
196 148
197 } // namespace drive_backend 149 } // namespace drive_backend
198 } // namespace sync_file_system 150 } // namespace sync_file_system
199 151
200 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ 152 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_SYNC_WORKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698