1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_SERVICE_H_
#define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_SERVICE_H_
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
#include "chrome/browser/sync_file_system/conflict_resolution_policy.h"
#include "chrome/browser/sync_file_system/file_status_observer.h"
#include "chrome/browser/sync_file_system/remote_file_sync_service.h"
#include "chrome/browser/sync_file_system/sync_callbacks.h"
#include "chrome/browser/sync_file_system/sync_process_runner.h"
#include "chrome/browser/sync_file_system/sync_service_state.h"
#include "chrome/browser/sync_file_system/task_logger.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/extension_registry_observer.h"
#include "url/gurl.h"
class Profile;
class ProfileSyncServiceBase;
namespace storage {
class FileSystemContext;
}
namespace sync_file_system {
class LocalFileSyncService;
class LocalSyncRunner;
class RemoteSyncRunner;
class SyncEventObserver;
class SyncFileSystemService
: public KeyedService,
public SyncProcessRunner::Client,
public ProfileSyncServiceObserver,
public FileStatusObserver,
public extensions::ExtensionRegistryObserver,
public base::SupportsWeakPtr<SyncFileSystemService> {
public:
typedef base::Callback<void(const base::ListValue&)> DumpFilesCallback;
typedef base::Callback<void(const RemoteFileSyncService::OriginStatusMap&)>
ExtensionStatusMapCallback;
// KeyedService implementation.
void Shutdown() override;
void InitializeForApp(storage::FileSystemContext* file_system_context,
const GURL& app_origin,
const SyncStatusCallback& callback);
void GetExtensionStatusMap(const ExtensionStatusMapCallback& callback);
void DumpFiles(const GURL& origin, const DumpFilesCallback& callback);
void DumpDatabase(const DumpFilesCallback& callback);
// Returns the file |url|'s sync status.
void GetFileSyncStatus(const storage::FileSystemURL& url,
const SyncFileStatusCallback& callback);
void AddSyncEventObserver(SyncEventObserver* observer);
void RemoveSyncEventObserver(SyncEventObserver* observer);
LocalChangeProcessor* GetLocalChangeProcessor(const GURL& origin);
// SyncProcessRunner::Client implementations.
void OnSyncIdle() override;
SyncServiceState GetSyncServiceState() override;
SyncFileSystemService* GetSyncService() override;
void OnPromotionCompleted(int* num_running_jobs);
void CheckIfIdle();
TaskLogger* task_logger() { return &task_logger_; }
void CallOnIdleForTesting(const base::Closure& callback);
private:
friend class SyncFileSystemServiceFactory;
friend class SyncFileSystemServiceTest;
friend class SyncFileSystemTest;
friend struct base::DefaultDeleter<SyncFileSystemService>;
friend class LocalSyncRunner;
friend class RemoteSyncRunner;
explicit SyncFileSystemService(Profile* profile);
~SyncFileSystemService() override;
void Initialize(scoped_ptr<LocalFileSyncService> local_file_service,
scoped_ptr<RemoteFileSyncService> remote_file_service);
// Callbacks for InitializeForApp.
void DidInitializeFileSystem(const GURL& app_origin,
const SyncStatusCallback& callback,
SyncStatusCode status);
void DidRegisterOrigin(const GURL& app_origin,
const SyncStatusCallback& callback,
SyncStatusCode status);
void DidInitializeFileSystemForDump(const GURL& app_origin,
const DumpFilesCallback& callback,
SyncStatusCode status);
void DidDumpFiles(const GURL& app_origin,
const DumpFilesCallback& callback,
scoped_ptr<base::ListValue> files);
void DidDumpDatabase(const DumpFilesCallback& callback,
scoped_ptr<base::ListValue> list);
void DidGetExtensionStatusMap(
const ExtensionStatusMapCallback& callback,
scoped_ptr<RemoteFileSyncService::OriginStatusMap> status_map);
// Overrides sync_enabled_ setting. This should be called only by tests.
void SetSyncEnabledForTesting(bool enabled);
void DidGetLocalChangeStatus(const SyncFileStatusCallback& callback,
SyncStatusCode status,
bool has_pending_local_changes);
void OnRemoteServiceStateUpdated(RemoteServiceState state,
const std::string& description);
// extensions::ExtensionRegistryObserver implementations.
void OnExtensionInstalled(content::BrowserContext* browser_context,
const extensions::Extension* extension,
bool is_update) override;
void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) override;
void OnExtensionUninstalled(content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UninstallReason reason) override;
void OnExtensionLoaded(content::BrowserContext* browser_context,
const extensions::Extension* extension) override;
// ProfileSyncServiceObserver implementation.
void OnStateChanged() override;
// SyncFileStatusObserver implementation.
void OnFileStatusChanged(const storage::FileSystemURL& url,
SyncFileType file_type,
SyncFileStatus sync_status,
SyncAction action_taken,
SyncDirection direction) override;
// Check the profile's sync preference settings and call
// remote_file_service_->SetSyncEnabled() to update the status.
// |profile_sync_service| must be non-null.
void UpdateSyncEnabledStatus(ProfileSyncServiceBase* profile_sync_service);
// Runs the SyncProcessRunner method of all sync runners (e.g. for Local sync
// and Remote sync).
void RunForEachSyncRunners(void(SyncProcessRunner::*method)());
// Returns the appropriate RemoteFileSyncService for the given origin/app.
// (crbug.com/324215)
RemoteFileSyncService* GetRemoteService(const GURL& origin);
Profile* profile_;
scoped_ptr<LocalFileSyncService> local_service_;
scoped_ptr<RemoteFileSyncService> remote_service_;
// Holds all SyncProcessRunners.
ScopedVector<SyncProcessRunner> local_sync_runners_;
ScopedVector<SyncProcessRunner> remote_sync_runners_;
// Indicates if sync is currently enabled or not.
bool sync_enabled_;
TaskLogger task_logger_;
ObserverList<SyncEventObserver> observers_;
bool promoting_demoted_changes_;
base::Closure idle_callback_;
DISALLOW_COPY_AND_ASSIGN(SyncFileSystemService);
};
} // namespace sync_file_system
#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_SERVICE_H_
|