diff options
author | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-02 14:03:55 +0000 |
---|---|---|
committer | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-02 14:03:55 +0000 |
commit | d99b7b889b86660e19d1c2417a2146832342ae7e (patch) | |
tree | 93e03a476c1b8eb574e59199a523076cfe6a0bb6 /chrome | |
parent | b70459e42c60ef87b09e5191977a73530889f85b (diff) | |
download | chromium_src-d99b7b889b86660e19d1c2417a2146832342ae7e.zip chromium_src-d99b7b889b86660e19d1c2417a2146832342ae7e.tar.gz chromium_src-d99b7b889b86660e19d1c2417a2146832342ae7e.tar.bz2 |
[SyncFS] Add SyncEngine skelton behind flag
* Add SyncEngine and its entry point.
BUG=240165
Review URL: https://chromiumcodereview.appspot.com/23503024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 332 insertions, 2 deletions
diff --git a/chrome/browser/sync_file_system/drive_backend/sync_engine.cc b/chrome/browser/sync_file_system/drive_backend/sync_engine.cc new file mode 100644 index 0000000..fae08f2 --- /dev/null +++ b/chrome/browser/sync_file_system/drive_backend/sync_engine.cc @@ -0,0 +1,162 @@ +// Copyright 2013 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. + +#include "chrome/browser/sync_file_system/drive_backend/sync_engine.h" + +#include "base/values.h" +#include "chrome/browser/drive/drive_api_service.h" + +namespace sync_file_system { +namespace drive_backend { + +SyncEngine::SyncEngine( + const base::FilePath& base_dir, + scoped_ptr<drive::DriveAPIService> drive_api, + drive::DriveNotificationManager* notification_manager, + ExtensionService* extension_service) + : base_dir_(base_dir), + drive_api_(drive_api.Pass()), + notification_manager_(notification_manager), + extension_service_(extension_service), + weak_ptr_factory_(this), + task_manager_(weak_ptr_factory_.GetWeakPtr()) { +} + +SyncEngine::~SyncEngine() { + NOTIMPLEMENTED(); +} + +void SyncEngine::Initialize(const SyncStatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::AddServiceObserver(SyncServiceObserver* observer) { + service_observers_.AddObserver(observer); +} + +void SyncEngine::AddFileStatusObserver(FileStatusObserver* observer) { + file_status_observers_.AddObserver(observer); +} + +void SyncEngine::RegisterOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::UnregisterOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::EnableOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::DisableOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::UninstallOrigin( + const GURL& origin, + const SyncStatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::ProcessRemoteChange( + const SyncFileCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::SetRemoteChangeProcessor( + RemoteChangeProcessor* processor) { + remote_change_processor_ = processor; +} + +LocalChangeProcessor* SyncEngine::GetLocalChangeProcessor() { + return this; +} + +bool SyncEngine::IsConflicting(const fileapi::FileSystemURL& url) { + NOTIMPLEMENTED(); + return false; +} + +RemoteServiceState SyncEngine::GetCurrentState() const { + NOTIMPLEMENTED(); + return REMOTE_SERVICE_OK; +} + +void SyncEngine::GetOriginStatusMap(OriginStatusMap* status_map) { + DCHECK(status_map); + status_map->clear(); + NOTIMPLEMENTED(); +} + +scoped_ptr<base::ListValue> SyncEngine::DumpFiles(const GURL& origin) { + NOTIMPLEMENTED(); + return make_scoped_ptr(new base::ListValue()); +} + +void SyncEngine::SetSyncEnabled(bool enabled) { + NOTIMPLEMENTED(); +} + +SyncStatusCode SyncEngine::SetConflictResolutionPolicy( + ConflictResolutionPolicy policy) { + NOTIMPLEMENTED(); + return SYNC_STATUS_OK; +} + +ConflictResolutionPolicy +SyncEngine::GetConflictResolutionPolicy() const { + NOTIMPLEMENTED(); + return CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN; +} + +void SyncEngine::GetRemoteVersions( + const fileapi::FileSystemURL& url, + const RemoteVersionsCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::DownloadRemoteVersion( + const fileapi::FileSystemURL& url, + const std::string& version_id, + const DownloadVersionCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::ApplyLocalChange( + const FileChange& local_file_change, + const base::FilePath& local_file_path, + const SyncFileMetadata& local_file_metadata, + const fileapi::FileSystemURL& url, + const SyncStatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void SyncEngine::MaybeScheduleNextTask() { + NOTIMPLEMENTED(); +} + +void SyncEngine::NotifyLastOperationStatus(SyncStatusCode sync_status) { + NOTIMPLEMENTED(); +} + +void SyncEngine::OnNotificationReceived() { + NOTIMPLEMENTED(); +} + +void SyncEngine::OnPushNotificationEnabled(bool enabled) { + NOTIMPLEMENTED(); +} + +} // namespace drive_backend +} // namespace sync_file_system diff --git a/chrome/browser/sync_file_system/drive_backend/sync_engine.h b/chrome/browser/sync_file_system/drive_backend/sync_engine.h new file mode 100644 index 0000000..76a2167 --- /dev/null +++ b/chrome/browser/sync_file_system/drive_backend/sync_engine.h @@ -0,0 +1,126 @@ +// Copyright 2013 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_DRIVE_BACKEND_SYNC_ENGINE_H_ +#define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_H_ + +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "base/observer_list.h" +#include "chrome/browser/drive/drive_notification_observer.h" +#include "chrome/browser/sync_file_system/local_change_processor.h" +#include "chrome/browser/sync_file_system/remote_file_sync_service.h" +#include "chrome/browser/sync_file_system/sync_task_manager.h" + +class ExtensionService; + +namespace drive { +class DriveAPIService; +class DriveNotificationManager; +} + +namespace sync_file_system { +namespace drive_backend { + +class SyncEngineInitializer; +class LocalToRemoteSyncer; +class RemoteToLocalSyncer; + +class SyncEngine : public RemoteFileSyncService, + public LocalChangeProcessor, + public SyncTaskManager::Client, + public drive::DriveNotificationObserver { + public: + typedef Observer SyncServiceObserver; + + SyncEngine(const base::FilePath& base_dir, + scoped_ptr<drive::DriveAPIService> drive_api, + drive::DriveNotificationManager* notification_manager, + ExtensionService* extension_service); + virtual ~SyncEngine(); + + void Initialize(const SyncStatusCallback& callback); + + // RemoteFileSyncService overrides. + virtual void AddServiceObserver(SyncServiceObserver* observer) OVERRIDE; + virtual void AddFileStatusObserver(FileStatusObserver* observer) OVERRIDE; + virtual void RegisterOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) OVERRIDE; + virtual void UnregisterOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) OVERRIDE; + virtual void EnableOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) OVERRIDE; + virtual void DisableOriginForTrackingChanges( + const GURL& origin, + const SyncStatusCallback& callback) OVERRIDE; + virtual void UninstallOrigin( + const GURL& origin, + const SyncStatusCallback& callback) OVERRIDE; + virtual void ProcessRemoteChange(const SyncFileCallback& callback) OVERRIDE; + virtual void SetRemoteChangeProcessor( + RemoteChangeProcessor* processor) OVERRIDE; + virtual LocalChangeProcessor* GetLocalChangeProcessor() OVERRIDE; + virtual bool IsConflicting(const fileapi::FileSystemURL& url) OVERRIDE; + virtual RemoteServiceState GetCurrentState() const OVERRIDE; + virtual void GetOriginStatusMap(OriginStatusMap* status_map) OVERRIDE; + virtual scoped_ptr<base::ListValue> DumpFiles(const GURL& origin) OVERRIDE; + virtual void SetSyncEnabled(bool enabled) OVERRIDE; + virtual SyncStatusCode SetConflictResolutionPolicy( + ConflictResolutionPolicy policy) OVERRIDE; + virtual ConflictResolutionPolicy GetConflictResolutionPolicy() const OVERRIDE; + virtual void GetRemoteVersions( + const fileapi::FileSystemURL& url, + const RemoteVersionsCallback& callback) OVERRIDE; + virtual void DownloadRemoteVersion( + const fileapi::FileSystemURL& url, + const std::string& version_id, + const DownloadVersionCallback& callback) OVERRIDE; + + // LocalChangeProcessor overrides. + virtual void ApplyLocalChange( + const FileChange& change, + const base::FilePath& local_file_path, + const SyncFileMetadata& local_file_metadata, + const fileapi::FileSystemURL& url, + const SyncStatusCallback& callback) OVERRIDE; + + // SyncTaskManager::Client overrides. + virtual void MaybeScheduleNextTask() OVERRIDE; + virtual void NotifyLastOperationStatus(SyncStatusCode sync_status) OVERRIDE; + + // drive::DriveNotificationObserver implementation. + virtual void OnNotificationReceived() OVERRIDE; + virtual void OnPushNotificationEnabled(bool enabled) OVERRIDE; + + private: + base::FilePath base_dir_; + base::FilePath temporary_file_dir_; + + scoped_ptr<drive::DriveAPIService> drive_api_; + + // These external services are not owned by SyncEngine. + // The owner of the SyncEngine is responsible for their lifetime. + // I.e. the owner should declare the dependency explicitly by calling + // BrowserContextKeyedService::DependsOn(). + drive::DriveNotificationManager* notification_manager_; + ExtensionService* extension_service_; + + ObserverList<SyncServiceObserver> service_observers_; + ObserverList<FileStatusObserver> file_status_observers_; + RemoteChangeProcessor* remote_change_processor_; + + base::WeakPtrFactory<SyncEngine> weak_ptr_factory_; + SyncTaskManager task_manager_; + + DISALLOW_COPY_AND_ASSIGN(SyncEngine); +}; + +} // namespace drive_backend +} // namespace sync_file_system + +#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_H_ diff --git a/chrome/browser/sync_file_system/sync_file_system_service_factory.cc b/chrome/browser/sync_file_system/sync_file_system_service_factory.cc index 1aaaef4..6dee668 100644 --- a/chrome/browser/sync_file_system/sync_file_system_service_factory.cc +++ b/chrome/browser/sync_file_system/sync_file_system_service_factory.cc @@ -5,11 +5,17 @@ #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" #include "base/command_line.h" +#include "chrome/browser/drive/drive_api_service.h" #include "chrome/browser/drive/drive_notification_manager_factory.h" +#include "chrome/browser/extensions/extension_system_factory.h" +#include "chrome/browser/google_apis/drive_api_url_generator.h" +#include "chrome/browser/google_apis/gdata_wapi_url_generator.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync_file_system/drive_backend/drive_file_sync_service.h" +#include "chrome/browser/sync_file_system/drive_backend/sync_engine.h" #include "chrome/browser/sync_file_system/sync_file_system_service.h" #include "chrome/browser/sync_file_system/syncable_file_system_util.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" @@ -18,6 +24,7 @@ namespace sync_file_system { namespace { const char kDisableLastWriteWin[] = "disable-syncfs-last-write-win"; +const char kEnableSyncFileSystemV2[] = "enable-syncfs-v2"; } // static @@ -43,6 +50,7 @@ SyncFileSystemServiceFactory::SyncFileSystemServiceFactory() BrowserContextDependencyManager::GetInstance()) { DependsOn(drive::DriveNotificationManagerFactory::GetInstance()); DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); + DependsOn(extensions::ExtensionSystemFactory::GetInstance()); } SyncFileSystemServiceFactory::~SyncFileSystemServiceFactory() {} @@ -50,7 +58,7 @@ SyncFileSystemServiceFactory::~SyncFileSystemServiceFactory() {} BrowserContextKeyedService* SyncFileSystemServiceFactory::BuildServiceInstanceFor( content::BrowserContext* context) const { - Profile* profile = static_cast<Profile*>(context); + Profile* profile = Profile::FromBrowserContext(context); SyncFileSystemService* service = new SyncFileSystemService(profile); @@ -60,6 +68,38 @@ SyncFileSystemServiceFactory::BuildServiceInstanceFor( scoped_ptr<RemoteFileSyncService> remote_file_service; if (mock_remote_file_service_) { remote_file_service = mock_remote_file_service_.Pass(); + } else if (CommandLine::ForCurrentProcess()->HasSwitch( + kEnableSyncFileSystemV2)) { + RegisterSyncableFileSystem(); + + GURL base_drive_url( + google_apis::DriveApiUrlGenerator::kBaseUrlForProduction); + GURL base_download_url( + google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction); + GURL wapi_base_url( + google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction); + + scoped_ptr<drive::DriveAPIService> drive_api_service( + new drive::DriveAPIService( + ProfileOAuth2TokenServiceFactory::GetForProfile(profile), + context->GetRequestContext(), + content::BrowserThread::GetBlockingPool(), + base_drive_url, base_download_url, wapi_base_url, + std::string() /* custom_user_agent */)); + + drive::DriveNotificationManager* notification_manager = + drive::DriveNotificationManagerFactory::GetForProfile(profile); + ExtensionService* extension_service = + extensions::ExtensionSystem::Get(profile)->extension_service(); + + scoped_ptr<drive_backend::SyncEngine> sync_engine( + new drive_backend::SyncEngine( + context->GetPath(), + drive_api_service.Pass(), + notification_manager, + extension_service)); + + remote_file_service = sync_engine.PassAs<RemoteFileSyncService>(); } else { // FileSystem needs to be registered before DriveFileSyncService runs // its initialization code. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index da54423..042f81f 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2225,12 +2225,13 @@ 'browser/sync_file_system/drive_backend/remote_sync_delegate.h', 'browser/sync_file_system/drive_backend/remote_sync_operation_resolver.cc', 'browser/sync_file_system/drive_backend/remote_sync_operation_resolver.h', + 'browser/sync_file_system/drive_backend/sync_engine.cc', + 'browser/sync_file_system/drive_backend/sync_engine.h', 'browser/sync_file_system/drive_backend/tracker_set.cc', 'browser/sync_file_system/drive_backend/tracker_set.h', 'browser/sync_file_system/file_change.cc', 'browser/sync_file_system/file_change.h', 'browser/sync_file_system/file_status_observer.h', - 'browser/sync_file_system/local_change_processor.h', 'browser/sync_file_system/local/local_file_change_tracker.cc', 'browser/sync_file_system/local/local_file_change_tracker.h', 'browser/sync_file_system/local/local_file_sync_context.cc', @@ -2246,6 +2247,7 @@ 'browser/sync_file_system/local/syncable_file_operation_runner.h', 'browser/sync_file_system/local/syncable_file_system_operation.cc', 'browser/sync_file_system/local/syncable_file_system_operation.h', + 'browser/sync_file_system/local_change_processor.h', 'browser/sync_file_system/logger.cc', 'browser/sync_file_system/logger.h', 'browser/sync_file_system/remote_change_processor.h', |