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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 566623003: Refactor syncable DEVICE_INFO type from ChangeProcessor to SyncableService - part 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More CR feedback addressed in DeviceInfoSyncService. Created 6 years, 3 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
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/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 29 matching lines...) Expand all
40 #include "chrome/browser/signin/chrome_signin_client_factory.h" 40 #include "chrome/browser/signin/chrome_signin_client_factory.h"
41 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 41 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
42 #include "chrome/browser/signin/signin_manager_factory.h" 42 #include "chrome/browser/signin/signin_manager_factory.h"
43 #include "chrome/browser/sync/backend_migrator.h" 43 #include "chrome/browser/sync/backend_migrator.h"
44 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" 44 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
45 #include "chrome/browser/sync/glue/device_info.h" 45 #include "chrome/browser/sync/glue/device_info.h"
46 #include "chrome/browser/sync/glue/favicon_cache.h" 46 #include "chrome/browser/sync/glue/favicon_cache.h"
47 #include "chrome/browser/sync/glue/sync_backend_host.h" 47 #include "chrome/browser/sync/glue/sync_backend_host.h"
48 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" 48 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
49 #include "chrome/browser/sync/glue/sync_start_util.h" 49 #include "chrome/browser/sync/glue/sync_start_util.h"
50 #include "chrome/browser/sync/glue/synced_device_tracker.h"
51 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" 50 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
52 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" 51 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
53 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" 52 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h"
54 #include "chrome/browser/sync/sessions/sessions_sync_manager.h"
55 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" 53 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
56 #include "chrome/browser/sync/sync_error_controller.h" 54 #include "chrome/browser/sync/sync_error_controller.h"
57 #include "chrome/browser/sync/sync_type_preference_provider.h" 55 #include "chrome/browser/sync/sync_type_preference_provider.h"
58 #include "chrome/browser/ui/browser.h" 56 #include "chrome/browser/ui/browser.h"
59 #include "chrome/browser/ui/browser_list.h" 57 #include "chrome/browser/ui/browser_list.h"
60 #include "chrome/browser/ui/browser_window.h" 58 #include "chrome/browser/ui/browser_window.h"
61 #include "chrome/browser/ui/global_error/global_error_service.h" 59 #include "chrome/browser/ui/global_error/global_error_service.h"
62 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 60 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
63 #include "chrome/common/chrome_switches.h" 61 #include "chrome/common/chrome_switches.h"
64 #include "chrome/common/chrome_version_info.h" 62 #include "chrome/common/chrome_version_info.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 DCHECK(profile); 250 DCHECK(profile);
253 syncer::SyncableService::StartSyncFlare flare( 251 syncer::SyncableService::StartSyncFlare flare(
254 sync_start_util::GetFlareForSyncableService(profile->GetPath())); 252 sync_start_util::GetFlareForSyncableService(profile->GetPath()));
255 scoped_ptr<browser_sync::LocalSessionEventRouter> router( 253 scoped_ptr<browser_sync::LocalSessionEventRouter> router(
256 new NotificationServiceSessionsRouter(profile, flare)); 254 new NotificationServiceSessionsRouter(profile, flare));
257 255
258 DCHECK(factory_.get()); 256 DCHECK(factory_.get());
259 local_device_ = factory_->CreateLocalDeviceInfoProvider(); 257 local_device_ = factory_->CreateLocalDeviceInfoProvider();
260 sessions_sync_manager_.reset( 258 sessions_sync_manager_.reset(
261 new SessionsSyncManager(profile, local_device_.get(), router.Pass())); 259 new SessionsSyncManager(profile, local_device_.get(), router.Pass()));
260 device_info_sync_service_.reset(
261 new DeviceInfoSyncService(local_device_.get()));
262 } 262 }
263 263
264 ProfileSyncService::~ProfileSyncService() { 264 ProfileSyncService::~ProfileSyncService() {
265 sync_prefs_.RemoveSyncPrefObserver(this); 265 sync_prefs_.RemoveSyncPrefObserver(this);
266 // Shutdown() should have been called before destruction. 266 // Shutdown() should have been called before destruction.
267 CHECK(!backend_initialized_); 267 CHECK(!backend_initialized_);
268 } 268 }
269 269
270 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { 270 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() {
271 // Exit if sync is disabled. 271 // Exit if sync is disabled.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 419 }
420 420
421 void ProfileSyncService::InitializeNonBlockingType( 421 void ProfileSyncService::InitializeNonBlockingType(
422 syncer::ModelType type, 422 syncer::ModelType type,
423 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 423 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
424 const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) { 424 const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) {
425 non_blocking_data_type_manager_.InitializeType( 425 non_blocking_data_type_manager_.InitializeType(
426 type, task_runner, type_sync_proxy); 426 type, task_runner, type_sync_proxy);
427 } 427 }
428 428
429 bool ProfileSyncService::IsSessionsDataTypeControllerRunning() const { 429 bool ProfileSyncService::IsDataTypeControllerRunning(
430 return directory_data_type_controllers_.find(syncer::SESSIONS) != 430 syncer::ModelType type) const {
431 directory_data_type_controllers_.end() && 431 DataTypeController::TypeMap::const_iterator iter =
432 (directory_data_type_controllers_.find(syncer::SESSIONS)-> 432 directory_data_type_controllers_.find(type);
433 second->state() == DataTypeController::RUNNING); 433 if (iter == directory_data_type_controllers_.end()) {
434 return false;
435 }
436 return iter->second->state() == DataTypeController::RUNNING;
434 } 437 }
435 438
436 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { 439 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() {
437 if (!IsSessionsDataTypeControllerRunning()) 440 if (!IsDataTypeControllerRunning(syncer::SESSIONS))
438 return NULL; 441 return NULL;
439 return sessions_sync_manager_.get(); 442 return sessions_sync_manager_.get();
440 } 443 }
441 444
442 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() { 445 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() {
443 return sessions_sync_manager_->GetFaviconCache(); 446 return sessions_sync_manager_->GetFaviconCache();
444 } 447 }
445 448
446 browser_sync::SyncedWindowDelegatesGetter* 449 browser_sync::SyncedWindowDelegatesGetter*
447 ProfileSyncService::GetSyncedWindowDelegatesGetter() const { 450 ProfileSyncService::GetSyncedWindowDelegatesGetter() const {
448 return sessions_sync_manager_->GetSyncedWindowDelegatesGetter(); 451 return sessions_sync_manager_->GetSyncedWindowDelegatesGetter();
449 } 452 }
450 453
454 browser_sync::DeviceInfoTracker* ProfileSyncService::GetDeviceInfoTracker()
455 const {
456 if (!IsDataTypeControllerRunning(syncer::DEVICE_INFO))
457 return NULL;
458
459 return device_info_sync_service_.get();
460 }
461
451 browser_sync::LocalDeviceInfoProvider* 462 browser_sync::LocalDeviceInfoProvider*
452 ProfileSyncService::GetLocalDeviceInfoProvider() { 463 ProfileSyncService::GetLocalDeviceInfoProvider() {
453 return local_device_.get(); 464 return local_device_.get();
454 } 465 }
455 466
456 scoped_ptr<browser_sync::DeviceInfo>
457 ProfileSyncService::GetDeviceInfo(const std::string& client_id) const {
458 if (HasSyncingBackend()) {
459 browser_sync::SyncedDeviceTracker* device_tracker =
460 backend_->GetSyncedDeviceTracker();
461 if (device_tracker)
462 return device_tracker->ReadDeviceInfo(client_id);
463 }
464 return scoped_ptr<browser_sync::DeviceInfo>();
465 }
466
467 ScopedVector<browser_sync::DeviceInfo>
468 ProfileSyncService::GetAllSignedInDevices() const {
469 ScopedVector<browser_sync::DeviceInfo> devices;
470 if (HasSyncingBackend()) {
471 browser_sync::SyncedDeviceTracker* device_tracker =
472 backend_->GetSyncedDeviceTracker();
473 if (device_tracker) {
474 // TODO(lipalani) - Make device tracker return a scoped vector.
475 device_tracker->GetAllSyncedDeviceInfo(&devices);
476 }
477 }
478 return devices.Pass();
479 }
480
481 // Notifies the observer of any device info changes.
482 void ProfileSyncService::AddObserverForDeviceInfoChange(
483 browser_sync::SyncedDeviceTracker::Observer* observer) {
484 if (HasSyncingBackend()) {
485 browser_sync::SyncedDeviceTracker* device_tracker =
486 backend_->GetSyncedDeviceTracker();
487 if (device_tracker) {
488 device_tracker->AddObserver(observer);
489 }
490 }
491 }
492
493 // Removes the observer from device info change notification.
494 void ProfileSyncService::RemoveObserverForDeviceInfoChange(
495 browser_sync::SyncedDeviceTracker::Observer* observer) {
496 if (HasSyncingBackend()) {
497 browser_sync::SyncedDeviceTracker* device_tracker =
498 backend_->GetSyncedDeviceTracker();
499 if (device_tracker) {
500 device_tracker->RemoveObserver(observer);
501 }
502 }
503 }
504
505 void ProfileSyncService::GetDataTypeControllerStates( 467 void ProfileSyncService::GetDataTypeControllerStates(
506 DataTypeController::StateMap* state_map) const { 468 DataTypeController::StateMap* state_map) const {
507 for (DataTypeController::TypeMap::const_iterator iter = 469 for (DataTypeController::TypeMap::const_iterator iter =
508 directory_data_type_controllers_.begin(); 470 directory_data_type_controllers_.begin();
509 iter != directory_data_type_controllers_.end(); 471 iter != directory_data_type_controllers_.end();
510 ++iter) 472 ++iter)
511 (*state_map)[iter->first] = iter->second.get()->state(); 473 (*state_map)[iter->first] = iter->second.get()->state();
512 } 474 }
513 475
514 SyncCredentials ProfileSyncService::GetCredentials() { 476 SyncCredentials ProfileSyncService::GetCredentials() {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 } else { 1003 } else {
1042 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); 1004 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta);
1043 } 1005 }
1044 } 1006 }
1045 1007
1046 void ProfileSyncService::PostBackendInitialization() { 1008 void ProfileSyncService::PostBackendInitialization() {
1047 // Never get here for backup / restore. 1009 // Never get here for backup / restore.
1048 DCHECK_EQ(backend_mode_, SYNC); 1010 DCHECK_EQ(backend_mode_, SYNC);
1049 1011
1050 if (last_backup_time_) { 1012 if (last_backup_time_) {
1051 browser_sync::SyncedDeviceTracker* device_tracker = 1013 DCHECK(device_info_sync_service_);
1052 backend_->GetSyncedDeviceTracker(); 1014 device_info_sync_service_->UpdateLocalDeviceBackupTime(*last_backup_time_);
1053 if (device_tracker)
1054 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
1055 } 1015 }
1056 1016
1057 if (protocol_event_observers_.might_have_observers()) { 1017 if (protocol_event_observers_.might_have_observers()) {
1058 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); 1018 backend_->RequestBufferedProtocolEventsAndEnableForwarding();
1059 } 1019 }
1060 1020
1061 non_blocking_data_type_manager_.ConnectSyncBackend( 1021 non_blocking_data_type_manager_.ConnectSyncBackend(
1062 backend_->GetSyncContextProxy()); 1022 backend_->GetSyncContextProxy());
1063 1023
1064 if (type_debug_info_observers_.might_have_observers()) { 1024 if (type_debug_info_observers_.might_have_observers()) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 } 1110 }
1151 1111
1152 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) 1112 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK)
1153 ConfigureDataTypeManager(); 1113 ConfigureDataTypeManager();
1154 else 1114 else
1155 PostBackendInitialization(); 1115 PostBackendInitialization();
1156 } 1116 }
1157 1117
1158 void ProfileSyncService::OnSyncCycleCompleted() { 1118 void ProfileSyncService::OnSyncCycleCompleted() {
1159 UpdateLastSyncedTime(); 1119 UpdateLastSyncedTime();
1160 if (IsSessionsDataTypeControllerRunning()) { 1120 if (IsDataTypeControllerRunning(syncer::SESSIONS)) {
1161 // Trigger garbage collection of old sessions now that we've downloaded 1121 // Trigger garbage collection of old sessions now that we've downloaded
1162 // any new session data. 1122 // any new session data.
1163 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 1123 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
1164 &browser_sync::SessionsSyncManager::DoGarbageCollection, 1124 &browser_sync::SessionsSyncManager::DoGarbageCollection,
1165 base::AsWeakPtr(sessions_sync_manager_.get()))); 1125 base::AsWeakPtr(sessions_sync_manager_.get())));
1166 } 1126 }
1167 DVLOG(2) << "Notifying observers sync cycle completed"; 1127 DVLOG(2) << "Notifying observers sync cycle completed";
1168 NotifySyncCycleCompleted(); 1128 NotifySyncCycleCompleted();
1169 } 1129 }
1170 1130
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 } 2561 }
2602 2562
2603 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { 2563 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() {
2604 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); 2564 return MakeWeakHandle(sync_js_controller_.AsWeakPtr());
2605 } 2565 }
2606 2566
2607 syncer::SyncableService* ProfileSyncService::GetSessionsSyncableService() { 2567 syncer::SyncableService* ProfileSyncService::GetSessionsSyncableService() {
2608 return sessions_sync_manager_.get(); 2568 return sessions_sync_manager_.get();
2609 } 2569 }
2610 2570
2571 syncer::SyncableService* ProfileSyncService::GetDeviceInfoSyncableService() {
2572 return device_info_sync_service_.get();
2573 }
2574
2611 ProfileSyncService::SyncTokenStatus::SyncTokenStatus() 2575 ProfileSyncService::SyncTokenStatus::SyncTokenStatus()
2612 : connection_status(syncer::CONNECTION_NOT_ATTEMPTED), 2576 : connection_status(syncer::CONNECTION_NOT_ATTEMPTED),
2613 last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {} 2577 last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {}
2614 ProfileSyncService::SyncTokenStatus::~SyncTokenStatus() {} 2578 ProfileSyncService::SyncTokenStatus::~SyncTokenStatus() {}
2615 2579
2616 ProfileSyncService::SyncTokenStatus 2580 ProfileSyncService::SyncTokenStatus
2617 ProfileSyncService::GetSyncTokenStatus() const { 2581 ProfileSyncService::GetSyncTokenStatus() const {
2618 SyncTokenStatus status; 2582 SyncTokenStatus status;
2619 status.connection_status_update_time = connection_status_update_time_; 2583 status.connection_status_update_time = connection_status_update_time_;
2620 status.connection_status = connection_status_; 2584 status.connection_status = connection_status_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 base::Bind(&ProfileSyncService::CheckSyncBackupCallback, 2695 base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
2732 weak_factory_.GetWeakPtr()))); 2696 weak_factory_.GetWeakPtr())));
2733 } 2697 }
2734 } 2698 }
2735 #endif 2699 #endif
2736 } 2700 }
2737 2701
2738 void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) { 2702 void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) {
2739 last_backup_time_.reset(new base::Time(backup_time)); 2703 last_backup_time_.reset(new base::Time(backup_time));
2740 2704
2741 if (HasSyncingBackend() && backend_initialized_) { 2705 DCHECK(device_info_sync_service_);
2742 browser_sync::SyncedDeviceTracker* device_tracker = 2706 device_info_sync_service_->UpdateLocalDeviceBackupTime(*last_backup_time_);
2743 backend_->GetSyncedDeviceTracker();
2744 if (device_tracker)
2745 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
2746 }
2747 } 2707 }
2748 2708
2749 void ProfileSyncService::TryStartSyncAfterBackup() { 2709 void ProfileSyncService::TryStartSyncAfterBackup() {
2750 startup_controller_.Reset(GetRegisteredDataTypes()); 2710 startup_controller_.Reset(GetRegisteredDataTypes());
2751 startup_controller_.TryStart(); 2711 startup_controller_.TryStart();
2752 } 2712 }
2753 2713
2754 void ProfileSyncService::CleanUpBackup() { 2714 void ProfileSyncService::CleanUpBackup() {
2755 sync_prefs_.ClearFirstSyncTime(); 2715 sync_prefs_.ClearFirstSyncTime();
2756 profile_->GetIOTaskRunner()->PostTask( 2716 profile_->GetIOTaskRunner()->PostTask(
2757 FROM_HERE, 2717 FROM_HERE,
2758 base::Bind(base::IgnoreResult(base::DeleteFile), 2718 base::Bind(base::IgnoreResult(base::DeleteFile),
2759 profile_->GetPath().Append(kSyncBackupDataFolderName), 2719 profile_->GetPath().Append(kSyncBackupDataFolderName),
2760 true)); 2720 true));
2761 } 2721 }
2762 2722
2763 bool ProfileSyncService::NeedBackup() const { 2723 bool ProfileSyncService::NeedBackup() const {
2764 return need_backup_; 2724 return need_backup_;
2765 } 2725 }
2766 2726
2767 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { 2727 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
2768 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); 2728 return device_info_sync_service_->GetLocalDeviceBackupTime();
2769 } 2729 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698