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

Side by Side Diff: chrome/browser/sync_file_system/sync_file_system_service.cc

Issue 11187021: Add RemoteFileSyncService interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/sync_file_system/sync_file_system_service.h" 5 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/stl_util.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_dependency_manager.h" 12 #include "chrome/browser/profiles/profile_dependency_manager.h"
12 #include "chrome/browser/sync_file_system/local_file_sync_service.h" 13 #include "chrome/browser/sync_file_system/local_file_sync_service.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
15 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
17 #include "webkit/fileapi/file_system_url.h"
16 #include "webkit/fileapi/syncable/sync_status_code.h" 18 #include "webkit/fileapi/syncable/sync_status_code.h"
17 19
18 using content::BrowserThread; 20 using content::BrowserThread;
19 21
20 namespace sync_file_system { 22 namespace sync_file_system {
21 23
22 void SyncFileSystemService::Shutdown() { 24 void SyncFileSystemService::Shutdown() {
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
24 26
25 local_file_service_->Shutdown(); 27 local_file_service_->Shutdown();
26 local_file_service_.reset(); 28 local_file_service_.reset();
27 29
30 remote_file_provider_.reset();
31
28 profile_ = NULL; 32 profile_ = NULL;
29 } 33 }
30 34
31 SyncFileSystemService::~SyncFileSystemService() { 35 SyncFileSystemService::~SyncFileSystemService() {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33 DCHECK(!profile_); 37 DCHECK(!profile_);
38 DCHECK(!local_file_service_);
39 DCHECK(!remote_file_provider_);
40 }
41
42 void SyncFileSystemService::OnRemoteChangeAvailable() {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
44 MaybeStartRemoteSync();
34 } 45 }
35 46
36 void SyncFileSystemService::InitializeForApp( 47 void SyncFileSystemService::InitializeForApp(
37 fileapi::FileSystemContext* file_system_context, 48 fileapi::FileSystemContext* file_system_context,
38 const std::string& service_name, 49 const std::string& service_name,
39 const GURL& app_url, 50 const GURL& app_url,
40 const StatusCallback& callback) { 51 const StatusCallback& callback) {
41 DCHECK(local_file_service_.get()); 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42 53 DCHECK(local_file_service_);
43 // TODO(kinuko,tzik): Instantiate the remote_file_service for the given 54 DCHECK(remote_file_provider_);
kinuko 2012/10/18 13:54:32 Until we resolve the TODO on line 158 don't we hit
44 // |service_name| if it hasn't been initialized.
45 55
46 local_file_service_->MaybeInitializeFileSystemContext( 56 local_file_service_->MaybeInitializeFileSystemContext(
47 app_url, file_system_context, callback); 57 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.
48 58
49 // TODO(tzik): Hook up remote service initialization code. 59 remote_file_provider_->change_provider()->RegisterOrigin(app_url.GetOrigin());
50 } 60 }
51 61
52 SyncFileSystemService::SyncFileSystemService(Profile* profile) 62 SyncFileSystemService::SyncFileSystemService(Profile* profile)
53 : profile_(profile) {} 63 : profile_(profile),
64 sync_is_running_(false) {}
54 65
55 void SyncFileSystemService::Initialize( 66 void SyncFileSystemService::Initialize(
56 scoped_ptr<LocalFileSyncService> local_file_service) { 67 scoped_ptr<LocalFileSyncService> local_file_service,
68 scoped_ptr<RemoteFileProvider> remote_file_provider) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58 DCHECK(local_file_service.get()); 70 DCHECK(local_file_service);
71 DCHECK(remote_file_provider);
59 DCHECK(profile_); 72 DCHECK(profile_);
60 73
61 local_file_service_ = local_file_service.Pass(); 74 local_file_service_ = local_file_service.Pass();
75 remote_file_provider_ = remote_file_provider.Pass();
76 }
77
78 void SyncFileSystemService::MaybeStartRemoteSync() {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
80
81 RemoteChangeProvider* change_provider =
82 remote_file_provider_->change_provider();
83 DCHECK(change_provider);
84
85 if (sync_is_running_ || !change_provider->HasRemoteChange())
86 return;
87
88 sync_is_running_ = true;
89
90 // TODO(tzik): Disable writing for |url|.
91 fileapi::FileSystemURL url = change_provider->GetURLForCurrentChange();
92 if (change_provider->IsDeletionChange()) {
93 // TODO(tzik): Do follows on correct thread.
94 // On FILE thread:
95 // Delete local file identified by |url|.
96 // On UI thread:
97 // remote_file_provider->change_provider()->DidProcessRemoteChange();
98 // EnableWriting(change->url);
99 // sync_is_running_ = false;
100 // MaybeStartRemoteSync();
101 NOTIMPLEMENTED();
102 } else {
103 remote_file_provider_->DownloadFile(
104 url,
105 base::Bind(&SyncFileSystemService::DidDownloadFile, AsWeakPtr()));
kinuko 2012/10/18 13:54:32 We also need to handle directory cases.
106 }
107 }
108
109 void SyncFileSystemService::DidDownloadFile(
110 fileapi::SyncStatusCode status,
111 const FilePath& file_path) {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
113
114 // TODO(tzik): Do follows on correct thread.
115 // On FILE thread:
116 // CopyInForeightFile(file_path, change->url());
117 // DeleteFile(file_path);
118 //
119 // On UI thread:
120 // remote_file_provider->change_provider()->DidProcessRemoteChange();
121 // EnableWriting(change->url);
122 // sync_is_running_ = false;
123 // MaybeStartRemoteSync();
124 NOTIMPLEMENTED();
62 } 125 }
63 126
64 // SyncFileSystemServiceFactory ----------------------------------------------- 127 // SyncFileSystemServiceFactory -----------------------------------------------
65 128
66 // static 129 // static
67 SyncFileSystemService* SyncFileSystemServiceFactory::GetForProfile( 130 SyncFileSystemService* SyncFileSystemServiceFactory::GetForProfile(
68 Profile* profile) { 131 Profile* profile) {
69 return static_cast<SyncFileSystemService*>( 132 return static_cast<SyncFileSystemService*>(
70 GetInstance()->GetServiceForProfile(profile, true)); 133 GetInstance()->GetServiceForProfile(profile, true));
71 } 134 }
(...skipping 12 matching lines...) Expand all
84 147
85 ProfileKeyedService* SyncFileSystemServiceFactory::BuildServiceInstanceFor( 148 ProfileKeyedService* SyncFileSystemServiceFactory::BuildServiceInstanceFor(
86 Profile* profile) const { 149 Profile* profile) const {
87 SyncFileSystemService* service = new SyncFileSystemService(profile); 150 SyncFileSystemService* service = new SyncFileSystemService(profile);
88 151
89 // TODO(kinuko): Set up mock services if it is called for testing. 152 // TODO(kinuko): Set up mock services if it is called for testing.
90 153
91 scoped_ptr<LocalFileSyncService> local_file_service( 154 scoped_ptr<LocalFileSyncService> local_file_service(
92 new LocalFileSyncService); 155 new LocalFileSyncService);
93 156
94 service->Initialize(local_file_service.Pass()); 157 scoped_ptr<RemoteFileProvider> remote_file_provider;
158 // TODO(tzik): Instantiate DriveFileProvider.
159
160 service->Initialize(local_file_service.Pass(),
161 remote_file_provider.Pass());
162
95 return service; 163 return service;
96 } 164 }
97 165
98 } // namespace chrome 166 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698