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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
21 #include "base/timer.h" | 21 #include "base/timer.h" |
22 #include "base/tracked_objects.h" | 22 #include "base/tracked_objects.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
26 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" | 26 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" |
27 #include "chrome/browser/sync/glue/change_processor.h" | 27 #include "chrome/browser/sync/glue/change_processor.h" |
28 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 28 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 29 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
29 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 30 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
30 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 31 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
31 #include "chrome/browser/sync/sync_prefs.h" | 32 #include "chrome/browser/sync/sync_prefs.h" |
32 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/chrome_version_info.h" | 35 #include "chrome/common/chrome_version_info.h" |
35 #include "chrome/common/net/gaia/gaia_constants.h" | 36 #include "chrome/common/net/gaia/gaia_constants.h" |
36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
38 #include "content/public/common/content_client.h" | 39 #include "content/public/common/content_client.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 const base::WeakPtr<InvalidatorStorage>& invalidator_storage) | 286 const base::WeakPtr<InvalidatorStorage>& invalidator_storage) |
286 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 287 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
287 sync_thread_("Chrome_SyncThread"), | 288 sync_thread_("Chrome_SyncThread"), |
288 frontend_loop_(MessageLoop::current()), | 289 frontend_loop_(MessageLoop::current()), |
289 profile_(profile), | 290 profile_(profile), |
290 name_(name), | 291 name_(name), |
291 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), | 292 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), |
292 weak_ptr_factory_.GetWeakPtr())), | 293 weak_ptr_factory_.GetWeakPtr())), |
293 initialization_state_(NOT_ATTEMPTED), | 294 initialization_state_(NOT_ATTEMPTED), |
294 sync_prefs_(sync_prefs), | 295 sync_prefs_(sync_prefs), |
295 chrome_sync_notification_bridge_(profile_), | |
296 sync_notifier_factory_( | 296 sync_notifier_factory_( |
297 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 297 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
298 profile_->GetRequestContext()), | 298 profile_->GetRequestContext()), |
299 content::GetUserAgent(GURL()), | 299 content::GetUserAgent(GURL()), |
300 invalidator_storage), | 300 invalidator_storage), |
301 frontend_(NULL) { | 301 frontend_(NULL) { |
302 } | 302 } |
303 | 303 |
304 SyncBackendHost::SyncBackendHost(Profile* profile) | 304 SyncBackendHost::SyncBackendHost(Profile* profile) |
305 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 305 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
306 sync_thread_("Chrome_SyncThread"), | 306 sync_thread_("Chrome_SyncThread"), |
307 frontend_loop_(MessageLoop::current()), | 307 frontend_loop_(MessageLoop::current()), |
308 profile_(profile), | 308 profile_(profile), |
309 name_("Unknown"), | 309 name_("Unknown"), |
310 initialization_state_(NOT_ATTEMPTED), | 310 initialization_state_(NOT_ATTEMPTED), |
311 chrome_sync_notification_bridge_(profile_), | |
312 sync_notifier_factory_( | 311 sync_notifier_factory_( |
313 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 312 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
314 profile_->GetRequestContext()), | 313 profile_->GetRequestContext()), |
315 content::GetUserAgent(GURL()), | 314 content::GetUserAgent(GURL()), |
316 base::WeakPtr<syncer::InvalidationStateTracker>()), | 315 base::WeakPtr<syncer::InvalidationStateTracker>()), |
317 frontend_(NULL) { | 316 frontend_(NULL) { |
318 } | 317 } |
319 | 318 |
320 SyncBackendHost::~SyncBackendHost() { | 319 SyncBackendHost::~SyncBackendHost() { |
321 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 320 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 syncer::ModelTypeSet initial_types, | 370 syncer::ModelTypeSet initial_types, |
372 const SyncCredentials& credentials, | 371 const SyncCredentials& credentials, |
373 bool delete_sync_data_folder, | 372 bool delete_sync_data_folder, |
374 syncer::SyncManagerFactory* sync_manager_factory, | 373 syncer::SyncManagerFactory* sync_manager_factory, |
375 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 374 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
376 syncer::ReportUnrecoverableErrorFunction | 375 syncer::ReportUnrecoverableErrorFunction |
377 report_unrecoverable_error_function) { | 376 report_unrecoverable_error_function) { |
378 if (!sync_thread_.Start()) | 377 if (!sync_thread_.Start()) |
379 return; | 378 return; |
380 | 379 |
| 380 chrome_sync_notification_bridge_.reset( |
| 381 new ChromeSyncNotificationBridge( |
| 382 profile_, sync_thread_.message_loop_proxy())); |
| 383 |
381 frontend_ = frontend; | 384 frontend_ = frontend; |
382 DCHECK(frontend); | 385 DCHECK(frontend); |
383 | 386 |
384 syncer::ModelTypeSet initial_types_with_nigori(initial_types); | 387 syncer::ModelTypeSet initial_types_with_nigori(initial_types); |
385 CHECK(sync_prefs_.get()); | 388 CHECK(sync_prefs_.get()); |
386 if (sync_prefs_->HasSyncSetupCompleted()) { | 389 if (sync_prefs_->HasSyncSetupCompleted()) { |
387 initial_types_with_nigori.Put(syncer::NIGORI); | 390 initial_types_with_nigori.Put(syncer::NIGORI); |
388 } | 391 } |
389 | 392 |
390 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori, | 393 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori, |
(...skipping 10 matching lines...) Expand all Loading... |
401 sync_thread_.message_loop(), | 404 sync_thread_.message_loop(), |
402 registrar_.get(), | 405 registrar_.get(), |
403 routing_info, | 406 routing_info, |
404 workers, | 407 workers, |
405 &extensions_activity_monitor_, | 408 &extensions_activity_monitor_, |
406 event_handler, | 409 event_handler, |
407 sync_service_url, | 410 sync_service_url, |
408 base::Bind(&MakeHttpBridgeFactory, | 411 base::Bind(&MakeHttpBridgeFactory, |
409 make_scoped_refptr(profile_->GetRequestContext())), | 412 make_scoped_refptr(profile_->GetRequestContext())), |
410 credentials, | 413 credentials, |
411 &chrome_sync_notification_bridge_, | 414 chrome_sync_notification_bridge_.get(), |
412 &sync_notifier_factory_, | 415 &sync_notifier_factory_, |
413 sync_manager_factory, | 416 sync_manager_factory, |
414 delete_sync_data_folder, | 417 delete_sync_data_folder, |
415 sync_prefs_->GetEncryptionBootstrapToken(), | 418 sync_prefs_->GetEncryptionBootstrapToken(), |
416 new InternalComponentsFactoryImpl(), | 419 new InternalComponentsFactoryImpl(), |
417 unrecoverable_error_handler, | 420 unrecoverable_error_handler, |
418 report_unrecoverable_error_function)); | 421 report_unrecoverable_error_function)); |
419 } | 422 } |
420 | 423 |
421 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 424 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 base::ThreadRestrictions::ScopedAllowIO allow_io; | 581 base::ThreadRestrictions::ScopedAllowIO allow_io; |
579 sync_thread_.Stop(); | 582 sync_thread_.Stop(); |
580 } | 583 } |
581 base::TimeDelta stop_sync_thread_time = base::Time::Now() - | 584 base::TimeDelta stop_sync_thread_time = base::Time::Now() - |
582 stop_thread_start_time; | 585 stop_thread_start_time; |
583 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", | 586 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", |
584 stop_sync_thread_time); | 587 stop_sync_thread_time); |
585 | 588 |
586 registrar_.reset(); | 589 registrar_.reset(); |
587 frontend_ = NULL; | 590 frontend_ = NULL; |
| 591 chrome_sync_notification_bridge_.reset(); |
588 core_ = NULL; // Releases reference to core_. | 592 core_ = NULL; // Releases reference to core_. |
589 } | 593 } |
590 | 594 |
591 void SyncBackendHost::ConfigureDataTypes( | 595 void SyncBackendHost::ConfigureDataTypes( |
592 syncer::ConfigureReason reason, | 596 syncer::ConfigureReason reason, |
593 syncer::ModelTypeSet types_to_add, | 597 syncer::ModelTypeSet types_to_add, |
594 syncer::ModelTypeSet types_to_remove, | 598 syncer::ModelTypeSet types_to_remove, |
595 NigoriState nigori_state, | 599 NigoriState nigori_state, |
596 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 600 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
597 const base::Callback<void()>& retry_callback) { | 601 const base::Callback<void()>& retry_callback) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 SDVLOG(1) | 753 SDVLOG(1) |
750 << "Added types: " | 754 << "Added types: " |
751 << syncer::ModelTypeSetToString(types_to_configure) | 755 << syncer::ModelTypeSetToString(types_to_configure) |
752 << ", configured types: " | 756 << ", configured types: " |
753 << syncer::ModelTypeSetToString(configured_types) | 757 << syncer::ModelTypeSetToString(configured_types) |
754 << ", failed configuration types: " | 758 << ", failed configuration types: " |
755 << syncer::ModelTypeSetToString(failed_configuration_types); | 759 << syncer::ModelTypeSetToString(failed_configuration_types); |
756 | 760 |
757 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has | 761 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has |
758 // to happen on the UI thread. | 762 // to happen on the UI thread. |
759 chrome_sync_notification_bridge_.UpdateEnabledTypes(configured_types); | 763 chrome_sync_notification_bridge_->UpdateEnabledTypes(configured_types); |
760 | 764 |
761 // Notify SyncManager (especially the notification listener) about new types. | 765 // Notify SyncManager (especially the notification listener) about new types. |
762 sync_thread_.message_loop()->PostTask(FROM_HERE, | 766 sync_thread_.message_loop()->PostTask(FROM_HERE, |
763 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(), | 767 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(), |
764 configured_types)); | 768 configured_types)); |
765 | 769 |
766 if (!ready_task.is_null()) | 770 if (!ready_task.is_null()) |
767 ready_task.Run(failed_configuration_types); | 771 ready_task.Run(failed_configuration_types); |
768 } | 772 } |
769 | 773 |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 FROM_HERE, | 1375 FROM_HERE, |
1372 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1376 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
1373 core_.get(), sync_thread_done_callback)); | 1377 core_.get(), sync_thread_done_callback)); |
1374 } | 1378 } |
1375 | 1379 |
1376 #undef SDVLOG | 1380 #undef SDVLOG |
1377 | 1381 |
1378 #undef SLOG | 1382 #undef SLOG |
1379 | 1383 |
1380 } // namespace browser_sync | 1384 } // namespace browser_sync |
OLD | NEW |