Chromium Code Reviews| Index: chrome/browser/sync_file_system/sync_file_system_service.cc |
| diff --git a/chrome/browser/sync_file_system/sync_file_system_service.cc b/chrome/browser/sync_file_system/sync_file_system_service.cc |
| index e4df2aa917bdf65d93ee6fde6f7831edf4c15180..795325e5249494dbc6f0cff81ff8bf618743b487 100644 |
| --- a/chrome/browser/sync_file_system/sync_file_system_service.cc |
| +++ b/chrome/browser/sync_file_system/sync_file_system_service.cc |
| @@ -7,12 +7,14 @@ |
| #include "base/bind.h" |
| #include "base/logging.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/stl_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_dependency_manager.h" |
| #include "chrome/browser/sync_file_system/local_file_sync_service.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "googleurl/src/gurl.h" |
| #include "webkit/fileapi/file_system_context.h" |
| +#include "webkit/fileapi/file_system_url.h" |
| #include "webkit/fileapi/syncable/sync_status_code.h" |
| using content::BrowserThread; |
| @@ -25,12 +27,21 @@ void SyncFileSystemService::Shutdown() { |
| local_file_service_->Shutdown(); |
| local_file_service_.reset(); |
| + remote_file_provider_.reset(); |
| + |
| profile_ = NULL; |
| } |
| SyncFileSystemService::~SyncFileSystemService() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(!profile_); |
| + DCHECK(!local_file_service_); |
| + DCHECK(!remote_file_provider_); |
| +} |
| + |
| +void SyncFileSystemService::OnRemoteChangeAvailable() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + MaybeStartRemoteSync(); |
| } |
| void SyncFileSystemService::InitializeForApp( |
| @@ -38,27 +49,79 @@ void SyncFileSystemService::InitializeForApp( |
| const std::string& service_name, |
| const GURL& app_url, |
| const StatusCallback& callback) { |
| - DCHECK(local_file_service_.get()); |
| - |
| - // TODO(kinuko,tzik): Instantiate the remote_file_service for the given |
| - // |service_name| if it hasn't been initialized. |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(local_file_service_); |
| + DCHECK(remote_file_provider_); |
|
kinuko
2012/10/18 13:54:32
Until we resolve the TODO on line 158 don't we hit
|
| local_file_service_->MaybeInitializeFileSystemContext( |
| app_url, file_system_context, callback); |
|
kinuko
2012/10/18 13:54:32
Hmm... while you're there can you also change this
tzik
2012/10/23 04:19:32
Done.
|
| - // TODO(tzik): Hook up remote service initialization code. |
| + remote_file_provider_->change_provider()->RegisterOrigin(app_url.GetOrigin()); |
| } |
| SyncFileSystemService::SyncFileSystemService(Profile* profile) |
| - : profile_(profile) {} |
| + : profile_(profile), |
| + sync_is_running_(false) {} |
| void SyncFileSystemService::Initialize( |
| - scoped_ptr<LocalFileSyncService> local_file_service) { |
| + scoped_ptr<LocalFileSyncService> local_file_service, |
| + scoped_ptr<RemoteFileProvider> remote_file_provider) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - DCHECK(local_file_service.get()); |
| + DCHECK(local_file_service); |
| + DCHECK(remote_file_provider); |
| DCHECK(profile_); |
| local_file_service_ = local_file_service.Pass(); |
| + remote_file_provider_ = remote_file_provider.Pass(); |
| +} |
| + |
| +void SyncFileSystemService::MaybeStartRemoteSync() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + RemoteChangeProvider* change_provider = |
| + remote_file_provider_->change_provider(); |
| + DCHECK(change_provider); |
| + |
| + if (sync_is_running_ || !change_provider->HasRemoteChange()) |
| + return; |
| + |
| + sync_is_running_ = true; |
| + |
| + // TODO(tzik): Disable writing for |url|. |
| + fileapi::FileSystemURL url = change_provider->GetURLForCurrentChange(); |
| + if (change_provider->IsDeletionChange()) { |
| + // TODO(tzik): Do follows on correct thread. |
| + // On FILE thread: |
| + // Delete local file identified by |url|. |
| + // On UI thread: |
| + // remote_file_provider->change_provider()->DidProcessRemoteChange(); |
| + // EnableWriting(change->url); |
| + // sync_is_running_ = false; |
| + // MaybeStartRemoteSync(); |
| + NOTIMPLEMENTED(); |
| + } else { |
| + remote_file_provider_->DownloadFile( |
| + url, |
| + base::Bind(&SyncFileSystemService::DidDownloadFile, AsWeakPtr())); |
|
kinuko
2012/10/18 13:54:32
We also need to handle directory cases.
|
| + } |
| +} |
| + |
| +void SyncFileSystemService::DidDownloadFile( |
| + fileapi::SyncStatusCode status, |
| + const FilePath& file_path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + // TODO(tzik): Do follows on correct thread. |
| + // On FILE thread: |
| + // CopyInForeightFile(file_path, change->url()); |
| + // DeleteFile(file_path); |
| + // |
| + // On UI thread: |
| + // remote_file_provider->change_provider()->DidProcessRemoteChange(); |
| + // EnableWriting(change->url); |
| + // sync_is_running_ = false; |
| + // MaybeStartRemoteSync(); |
| + NOTIMPLEMENTED(); |
| } |
| // SyncFileSystemServiceFactory ----------------------------------------------- |
| @@ -91,7 +154,12 @@ ProfileKeyedService* SyncFileSystemServiceFactory::BuildServiceInstanceFor( |
| scoped_ptr<LocalFileSyncService> local_file_service( |
| new LocalFileSyncService); |
| - service->Initialize(local_file_service.Pass()); |
| + scoped_ptr<RemoteFileProvider> remote_file_provider; |
| + // TODO(tzik): Instantiate DriveFileProvider. |
| + |
| + service->Initialize(local_file_service.Pass(), |
| + remote_file_provider.Pass()); |
| + |
| return service; |
| } |