| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync_driver/glue/sync_backend_registrar.h" | 5 #include "components/sync_driver/glue/sync_backend_registrar.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "components/sync_driver/change_processor.h" | 13 #include "components/sync_driver/change_processor.h" |
| 13 #include "components/sync_driver/sync_client.h" | 14 #include "components/sync_driver/sync_client.h" |
| 14 #include "sync/internal_api/public/user_share.h" | 15 #include "sync/internal_api/public/user_share.h" |
| 15 | 16 |
| 16 namespace browser_sync { | 17 namespace browser_sync { |
| 17 | 18 |
| 18 SyncBackendRegistrar::SyncBackendRegistrar( | 19 SyncBackendRegistrar::SyncBackendRegistrar( |
| 19 const std::string& name, | 20 const std::string& name, |
| 20 sync_driver::SyncClient* sync_client, | 21 sync_driver::SyncClient* sync_client, |
| 21 scoped_ptr<base::Thread> sync_thread, | 22 scoped_ptr<base::Thread> sync_thread, |
| 22 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 23 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
| 23 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 24 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
| 24 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread) | 25 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread) |
| 25 : name_(name), | 26 : name_(name), |
| 26 sync_client_(sync_client), | 27 sync_client_(sync_client), |
| 27 ui_thread_(ui_thread), | 28 ui_thread_(ui_thread), |
| 28 db_thread_(db_thread), | 29 db_thread_(db_thread), |
| 29 file_thread_(file_thread) { | 30 file_thread_(file_thread) { |
| 30 DCHECK(ui_thread_->BelongsToCurrentThread()); | 31 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 31 DCHECK(sync_client_); | 32 DCHECK(sync_client_); |
| 32 | 33 |
| 33 sync_thread_ = sync_thread.Pass(); | 34 sync_thread_ = std::move(sync_thread); |
| 34 if (!sync_thread_) { | 35 if (!sync_thread_) { |
| 35 sync_thread_.reset(new base::Thread("Chrome_SyncThread")); | 36 sync_thread_.reset(new base::Thread("Chrome_SyncThread")); |
| 36 base::Thread::Options options; | 37 base::Thread::Options options; |
| 37 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 38 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 38 CHECK(sync_thread_->StartWithOptions(options)); | 39 CHECK(sync_thread_->StartWithOptions(options)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 MaybeAddWorker(syncer::GROUP_DB); | 42 MaybeAddWorker(syncer::GROUP_DB); |
| 42 MaybeAddWorker(syncer::GROUP_FILE); | 43 MaybeAddWorker(syncer::GROUP_FILE); |
| 43 MaybeAddWorker(syncer::GROUP_UI); | 44 MaybeAddWorker(syncer::GROUP_UI); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 324 |
| 324 if (last_worker) { | 325 if (last_worker) { |
| 325 // Self-destruction after last worker. | 326 // Self-destruction after last worker. |
| 326 DVLOG(1) << "Destroy registrar on loop of " | 327 DVLOG(1) << "Destroy registrar on loop of " |
| 327 << ModelSafeGroupToString(group); | 328 << ModelSafeGroupToString(group); |
| 328 delete this; | 329 delete this; |
| 329 } | 330 } |
| 330 } | 331 } |
| 331 | 332 |
| 332 scoped_ptr<base::Thread> SyncBackendRegistrar::ReleaseSyncThread() { | 333 scoped_ptr<base::Thread> SyncBackendRegistrar::ReleaseSyncThread() { |
| 333 return sync_thread_.Pass(); | 334 return std::move(sync_thread_); |
| 334 } | 335 } |
| 335 | 336 |
| 336 void SyncBackendRegistrar::Shutdown() { | 337 void SyncBackendRegistrar::Shutdown() { |
| 337 // All data types should have been deactivated by now. | 338 // All data types should have been deactivated by now. |
| 338 DCHECK(processors_.empty()); | 339 DCHECK(processors_.empty()); |
| 339 | 340 |
| 340 // Unregister worker from observing loop destruction. | 341 // Unregister worker from observing loop destruction. |
| 341 base::AutoLock al(lock_); | 342 base::AutoLock al(lock_); |
| 342 for (WorkerMap::iterator it = workers_.begin(); it != workers_.end(); ++it) { | 343 for (WorkerMap::iterator it = workers_.begin(); it != workers_.end(); ++it) { |
| 343 it->second->UnregisterForLoopDestruction( | 344 it->second->UnregisterForLoopDestruction( |
| 344 base::Bind(&SyncBackendRegistrar::OnWorkerUnregistrationDone, | 345 base::Bind(&SyncBackendRegistrar::OnWorkerUnregistrationDone, |
| 345 base::Unretained(this))); | 346 base::Unretained(this))); |
| 346 } | 347 } |
| 347 } | 348 } |
| 348 | 349 |
| 349 base::Thread* SyncBackendRegistrar::sync_thread() { | 350 base::Thread* SyncBackendRegistrar::sync_thread() { |
| 350 return sync_thread_.get(); | 351 return sync_thread_.get(); |
| 351 } | 352 } |
| 352 | 353 |
| 353 } // namespace browser_sync | 354 } // namespace browser_sync |
| OLD | NEW |