BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / sync_worker.h
blob7ae7606d7e41b2113e400ef8317ead1ca1aafdef
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.
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.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 "chrome/browser/sync_file_system/task_logger.h"
20 class ExtensionServiceInterface;
21 class GURL;
23 namespace base {
24 class ListValue;
27 namespace drive {
28 class DriveServiceInterface;
29 class DriveUploaderInterface;
32 namespace storage {
33 class FileSystemURL;
36 namespace leveldb {
37 class Env;
40 namespace sync_file_system {
42 class FileChange;
43 class SyncFileMetadata;
45 namespace drive_backend {
47 class LocalToRemoteSyncer;
48 class MetadataDatabase;
49 class RemoteChangeProcessorOnWorker;
50 class RemoteToLocalSyncer;
51 class SyncEngineContext;
52 class SyncEngineInitializer;
54 class SyncWorker : public SyncWorkerInterface,
55 public SyncTaskManager::Client {
56 public:
57 SyncWorker(const base::FilePath& base_dir,
58 const base::WeakPtr<ExtensionServiceInterface>& extension_service,
59 leveldb::Env* env_override);
61 ~SyncWorker() override;
63 void Initialize(scoped_ptr<SyncEngineContext> context) override;
65 // SyncTaskManager::Client overrides
66 void MaybeScheduleNextTask() override;
67 void NotifyLastOperationStatus(SyncStatusCode sync_status,
68 bool used_network) override;
69 void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) override;
71 // SyncWorkerInterface overrides
72 void RegisterOrigin(const GURL& origin,
73 const SyncStatusCallback& callback) override;
74 void EnableOrigin(const GURL& origin,
75 const SyncStatusCallback& callback) override;
76 void DisableOrigin(const GURL& origin,
77 const SyncStatusCallback& callback) override;
78 void UninstallOrigin(const GURL& origin,
79 RemoteFileSyncService::UninstallFlag flag,
80 const SyncStatusCallback& callback) override;
81 void ProcessRemoteChange(const SyncFileCallback& callback) override;
82 void SetRemoteChangeProcessor(RemoteChangeProcessorOnWorker*
83 remote_change_processor_on_worker) override;
84 RemoteServiceState GetCurrentState() const override;
85 void GetOriginStatusMap(
86 const RemoteFileSyncService::StatusMapCallback& callback) override;
87 scoped_ptr<base::ListValue> DumpFiles(const GURL& origin) override;
88 scoped_ptr<base::ListValue> DumpDatabase() override;
89 void SetSyncEnabled(bool enabled) override;
90 void PromoteDemotedChanges(const base::Closure& callback) override;
91 void ApplyLocalChange(const FileChange& local_change,
92 const base::FilePath& local_path,
93 const SyncFileMetadata& local_metadata,
94 const storage::FileSystemURL& url,
95 const SyncStatusCallback& callback) override;
96 void ActivateService(RemoteServiceState service_state,
97 const std::string& description) override;
98 void DeactivateService(const std::string& description) override;
99 void DetachFromSequence() override;
100 void AddObserver(Observer* observer) override;
102 private:
103 friend class DriveBackendSyncTest;
104 friend class SyncWorkerTest;
106 enum AppStatus {
107 APP_STATUS_ENABLED,
108 APP_STATUS_DISABLED,
109 APP_STATUS_UNINSTALLED,
112 typedef base::hash_map<std::string, AppStatus> AppStatusMap;
114 void DoDisableApp(const std::string& app_id,
115 const SyncStatusCallback& callback);
116 void DoEnableApp(const std::string& app_id,
117 const SyncStatusCallback& callback);
119 void PostInitializeTask();
120 void DidInitialize(SyncEngineInitializer* initializer,
121 SyncStatusCode status);
122 void UpdateRegisteredApps();
123 static void QueryAppStatusOnUIThread(
124 const base::WeakPtr<ExtensionServiceInterface>& extension_service_ptr,
125 const std::vector<std::string>* app_ids,
126 AppStatusMap* status,
127 const base::Closure& callback);
128 void DidQueryAppStatus(const AppStatusMap* app_status);
129 void DidProcessRemoteChange(RemoteToLocalSyncer* syncer,
130 const SyncFileCallback& callback,
131 SyncStatusCode status);
132 void DidApplyLocalChange(LocalToRemoteSyncer* syncer,
133 const SyncStatusCallback& callback,
134 SyncStatusCode status);
136 // Returns true if a FetchChanges task is scheduled.
137 bool MaybeStartFetchChanges();
138 void DidResolveConflict(SyncStatusCode status);
139 void DidFetchChanges(SyncStatusCode status);
141 void UpdateServiceStateFromSyncStatusCode(SyncStatusCode state,
142 bool used_network);
143 void UpdateServiceState(RemoteServiceState state,
144 const std::string& description);
146 void CallOnIdleForTesting(const base::Closure& callback);
148 drive::DriveServiceInterface* GetDriveService();
149 drive::DriveUploaderInterface* GetDriveUploader();
150 MetadataDatabase* GetMetadataDatabase();
152 base::FilePath base_dir_;
154 leveldb::Env* env_override_;
156 // Sync with SyncEngine.
157 RemoteServiceState service_state_;
159 bool should_check_conflict_;
160 bool should_check_remote_change_;
161 bool listing_remote_changes_;
162 base::TimeTicks time_to_check_changes_;
164 bool sync_enabled_;
165 base::Closure call_on_idle_callback_;
167 scoped_ptr<SyncTaskManager> task_manager_;
169 base::WeakPtr<ExtensionServiceInterface> extension_service_;
171 scoped_ptr<SyncEngineContext> context_;
172 base::ObserverList<Observer> observers_;
174 base::SequenceChecker sequence_checker_;
176 base::WeakPtrFactory<SyncWorker> weak_ptr_factory_;
177 DISALLOW_COPY_AND_ASSIGN(SyncWorker);
180 } // namespace drive_backend
181 } // namespace sync_file_system
183 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_