OLD | NEW |
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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 factory_(this) {} | 151 factory_(this) {} |
152 | 152 |
153 void StartSync(const SyncStatusCallback& callback) override { | 153 void StartSync(const SyncStatusCallback& callback) override { |
154 GetSyncService()->local_service_->ProcessLocalChange( | 154 GetSyncService()->local_service_->ProcessLocalChange( |
155 base::Bind(&LocalSyncRunner::DidProcessLocalChange, | 155 base::Bind(&LocalSyncRunner::DidProcessLocalChange, |
156 factory_.GetWeakPtr(), callback)); | 156 factory_.GetWeakPtr(), callback)); |
157 } | 157 } |
158 | 158 |
159 // LocalFileSyncService::Observer overrides. | 159 // LocalFileSyncService::Observer overrides. |
160 void OnLocalChangeAvailable(int64 pending_changes) override { | 160 void OnLocalChangeAvailable(int64 pending_changes) override { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 161 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
162 | 162 |
163 OnChangesUpdated(pending_changes); | 163 OnChangesUpdated(pending_changes); |
164 | 164 |
165 // Kick other sync runners just in case they're not running. | 165 // Kick other sync runners just in case they're not running. |
166 GetSyncService()->RunForEachSyncRunners(&SyncProcessRunner::Schedule); | 166 GetSyncService()->RunForEachSyncRunners(&SyncProcessRunner::Schedule); |
167 } | 167 } |
168 | 168 |
169 private: | 169 private: |
170 void DidProcessLocalChange( | 170 void DidProcessLocalChange( |
171 const SyncStatusCallback& callback, | 171 const SyncStatusCallback& callback, |
(...skipping 29 matching lines...) Expand all Loading... |
201 base::Bind(&RemoteSyncRunner::DidProcessRemoteChange, | 201 base::Bind(&RemoteSyncRunner::DidProcessRemoteChange, |
202 factory_.GetWeakPtr(), callback)); | 202 factory_.GetWeakPtr(), callback)); |
203 } | 203 } |
204 | 204 |
205 SyncServiceState GetServiceState() override { | 205 SyncServiceState GetServiceState() override { |
206 return RemoteStateToSyncServiceState(last_state_); | 206 return RemoteStateToSyncServiceState(last_state_); |
207 } | 207 } |
208 | 208 |
209 // RemoteFileSyncService::Observer overrides. | 209 // RemoteFileSyncService::Observer overrides. |
210 void OnRemoteChangeQueueUpdated(int64 pending_changes) override { | 210 void OnRemoteChangeQueueUpdated(int64 pending_changes) override { |
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 211 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
212 | 212 |
213 OnChangesUpdated(pending_changes); | 213 OnChangesUpdated(pending_changes); |
214 | 214 |
215 // Kick other sync runners just in case they're not running. | 215 // Kick other sync runners just in case they're not running. |
216 GetSyncService()->RunForEachSyncRunners(&SyncProcessRunner::Schedule); | 216 GetSyncService()->RunForEachSyncRunners(&SyncProcessRunner::Schedule); |
217 } | 217 } |
218 | 218 |
219 void OnRemoteServiceStateUpdated(RemoteServiceState state, | 219 void OnRemoteServiceStateUpdated(RemoteServiceState state, |
220 const std::string& description) override { | 220 const std::string& description) override { |
221 // Just forward to SyncFileSystemService. | 221 // Just forward to SyncFileSystemService. |
(...skipping 22 matching lines...) Expand all Loading... |
244 RemoteFileSyncService* remote_service_; | 244 RemoteFileSyncService* remote_service_; |
245 RemoteServiceState last_state_; | 245 RemoteServiceState last_state_; |
246 base::WeakPtrFactory<RemoteSyncRunner> factory_; | 246 base::WeakPtrFactory<RemoteSyncRunner> factory_; |
247 DISALLOW_COPY_AND_ASSIGN(RemoteSyncRunner); | 247 DISALLOW_COPY_AND_ASSIGN(RemoteSyncRunner); |
248 }; | 248 }; |
249 | 249 |
250 //----------------------------------------------------------------------------- | 250 //----------------------------------------------------------------------------- |
251 // SyncFileSystemService | 251 // SyncFileSystemService |
252 | 252 |
253 void SyncFileSystemService::Shutdown() { | 253 void SyncFileSystemService::Shutdown() { |
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 254 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
255 | 255 |
256 local_sync_runners_.clear(); | 256 local_sync_runners_.clear(); |
257 remote_sync_runners_.clear(); | 257 remote_sync_runners_.clear(); |
258 | 258 |
259 local_service_->Shutdown(); | 259 local_service_->Shutdown(); |
260 local_service_.reset(); | 260 local_service_.reset(); |
261 | 261 |
262 remote_service_.reset(); | 262 remote_service_.reset(); |
263 | 263 |
264 sync_driver::SyncService* profile_sync_service = | 264 sync_driver::SyncService* profile_sync_service = |
265 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile_); | 265 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile_); |
266 if (profile_sync_service) | 266 if (profile_sync_service) |
267 profile_sync_service->RemoveObserver(this); | 267 profile_sync_service->RemoveObserver(this); |
268 | 268 |
269 ExtensionRegistry::Get(profile_)->RemoveObserver(this); | 269 ExtensionRegistry::Get(profile_)->RemoveObserver(this); |
270 | 270 |
271 profile_ = nullptr; | 271 profile_ = nullptr; |
272 } | 272 } |
273 | 273 |
274 SyncFileSystemService::~SyncFileSystemService() { | 274 SyncFileSystemService::~SyncFileSystemService() { |
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
276 DCHECK(!profile_); | 276 DCHECK(!profile_); |
277 } | 277 } |
278 | 278 |
279 void SyncFileSystemService::InitializeForApp( | 279 void SyncFileSystemService::InitializeForApp( |
280 storage::FileSystemContext* file_system_context, | 280 storage::FileSystemContext* file_system_context, |
281 const GURL& app_origin, | 281 const GURL& app_origin, |
282 const SyncStatusCallback& callback) { | 282 const SyncStatusCallback& callback) { |
283 DCHECK(local_service_); | 283 DCHECK(local_service_); |
284 DCHECK(remote_service_); | 284 DCHECK(remote_service_); |
285 DCHECK(app_origin == app_origin.GetOrigin()); | 285 DCHECK(app_origin == app_origin.GetOrigin()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 439 |
440 SyncFileSystemService::SyncFileSystemService(Profile* profile) | 440 SyncFileSystemService::SyncFileSystemService(Profile* profile) |
441 : profile_(profile), | 441 : profile_(profile), |
442 sync_enabled_(true), | 442 sync_enabled_(true), |
443 promoting_demoted_changes_(false) { | 443 promoting_demoted_changes_(false) { |
444 } | 444 } |
445 | 445 |
446 void SyncFileSystemService::Initialize( | 446 void SyncFileSystemService::Initialize( |
447 scoped_ptr<LocalFileSyncService> local_service, | 447 scoped_ptr<LocalFileSyncService> local_service, |
448 scoped_ptr<RemoteFileSyncService> remote_service) { | 448 scoped_ptr<RemoteFileSyncService> remote_service) { |
449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 449 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
450 DCHECK(local_service); | 450 DCHECK(local_service); |
451 DCHECK(remote_service); | 451 DCHECK(remote_service); |
452 DCHECK(profile_); | 452 DCHECK(profile_); |
453 | 453 |
454 local_service_ = local_service.Pass(); | 454 local_service_ = local_service.Pass(); |
455 remote_service_ = remote_service.Pass(); | 455 remote_service_ = remote_service.Pass(); |
456 | 456 |
457 scoped_ptr<LocalSyncRunner> local_syncer( | 457 scoped_ptr<LocalSyncRunner> local_syncer( |
458 new LocalSyncRunner(kLocalSyncName, this)); | 458 new LocalSyncRunner(kLocalSyncName, this)); |
459 scoped_ptr<RemoteSyncRunner> remote_syncer( | 459 scoped_ptr<RemoteSyncRunner> remote_syncer( |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 bool has_pending_local_changes) { | 628 bool has_pending_local_changes) { |
629 callback.Run( | 629 callback.Run( |
630 status, | 630 status, |
631 has_pending_local_changes ? | 631 has_pending_local_changes ? |
632 SYNC_FILE_STATUS_HAS_PENDING_CHANGES : SYNC_FILE_STATUS_SYNCED); | 632 SYNC_FILE_STATUS_HAS_PENDING_CHANGES : SYNC_FILE_STATUS_SYNCED); |
633 } | 633 } |
634 | 634 |
635 void SyncFileSystemService::OnRemoteServiceStateUpdated( | 635 void SyncFileSystemService::OnRemoteServiceStateUpdated( |
636 RemoteServiceState state, | 636 RemoteServiceState state, |
637 const std::string& description) { | 637 const std::string& description) { |
638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 638 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
639 util::Log(logging::LOG_VERBOSE, FROM_HERE, | 639 util::Log(logging::LOG_VERBOSE, FROM_HERE, |
640 "OnRemoteServiceStateChanged: %d %s", state, description.c_str()); | 640 "OnRemoteServiceStateChanged: %d %s", state, description.c_str()); |
641 | 641 |
642 FOR_EACH_OBSERVER( | 642 FOR_EACH_OBSERVER( |
643 SyncEventObserver, observers_, | 643 SyncEventObserver, observers_, |
644 OnSyncStateUpdated(GURL(), | 644 OnSyncStateUpdated(GURL(), |
645 RemoteStateToSyncServiceState(state), | 645 RemoteStateToSyncServiceState(state), |
646 description)); | 646 description)); |
647 | 647 |
648 RunForEachSyncRunners(&SyncProcessRunner::Schedule); | 648 RunForEachSyncRunners(&SyncProcessRunner::Schedule); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 local_sync_runners_.begin(); | 758 local_sync_runners_.begin(); |
759 iter != local_sync_runners_.end(); ++iter) | 759 iter != local_sync_runners_.end(); ++iter) |
760 ((*iter)->*method)(); | 760 ((*iter)->*method)(); |
761 for (ScopedVector<SyncProcessRunner>::iterator iter = | 761 for (ScopedVector<SyncProcessRunner>::iterator iter = |
762 remote_sync_runners_.begin(); | 762 remote_sync_runners_.begin(); |
763 iter != remote_sync_runners_.end(); ++iter) | 763 iter != remote_sync_runners_.end(); ++iter) |
764 ((*iter)->*method)(); | 764 ((*iter)->*method)(); |
765 } | 765 } |
766 | 766 |
767 } // namespace sync_file_system | 767 } // namespace sync_file_system |
OLD | NEW |