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

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

Issue 401433003: Revert of Sync: Refactoring of DEVICE_INFO syncable type - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } // anonymous namespace 179 } // anonymous namespace
180 180
181 bool ShouldShowActionOnUI( 181 bool ShouldShowActionOnUI(
182 const syncer::SyncProtocolError& error) { 182 const syncer::SyncProtocolError& error) {
183 return (error.action != syncer::UNKNOWN_ACTION && 183 return (error.action != syncer::UNKNOWN_ACTION &&
184 error.action != syncer::DISABLE_SYNC_ON_CLIENT && 184 error.action != syncer::DISABLE_SYNC_ON_CLIENT &&
185 error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT); 185 error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT);
186 } 186 }
187 187
188 ProfileSyncService::ProfileSyncService( 188 ProfileSyncService::ProfileSyncService(
189 scoped_ptr<ProfileSyncComponentsFactory> factory, 189 ProfileSyncComponentsFactory* factory,
190 Profile* profile, 190 Profile* profile,
191 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, 191 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
192 ProfileOAuth2TokenService* oauth2_token_service, 192 ProfileOAuth2TokenService* oauth2_token_service,
193 ProfileSyncServiceStartBehavior start_behavior) 193 ProfileSyncServiceStartBehavior start_behavior)
194 : OAuth2TokenService::Consumer("sync"), 194 : OAuth2TokenService::Consumer("sync"),
195 last_auth_error_(AuthError::AuthErrorNone()), 195 last_auth_error_(AuthError::AuthErrorNone()),
196 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), 196 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED),
197 factory_(factory.Pass()), 197 factory_(factory),
198 profile_(profile), 198 profile_(profile),
199 sync_prefs_(profile_->GetPrefs()), 199 sync_prefs_(profile_->GetPrefs()),
200 sync_service_url_(GetSyncServiceURL(*CommandLine::ForCurrentProcess())), 200 sync_service_url_(GetSyncServiceURL(*CommandLine::ForCurrentProcess())),
201 is_first_time_sync_configure_(false), 201 is_first_time_sync_configure_(false),
202 backend_initialized_(false), 202 backend_initialized_(false),
203 sync_disabled_by_admin_(false), 203 sync_disabled_by_admin_(false),
204 is_auth_in_progress_(false), 204 is_auth_in_progress_(false),
205 signin_(signin_wrapper.Pass()), 205 signin_(signin_wrapper.Pass()),
206 unrecoverable_error_reason_(ERROR_REASON_UNSET), 206 unrecoverable_error_reason_(ERROR_REASON_UNSET),
207 expect_sync_configuration_aborted_(false), 207 expect_sync_configuration_aborted_(false),
(...skipping 26 matching lines...) Expand all
234 startup_controller_weak_factory_.GetWeakPtr(), 234 startup_controller_weak_factory_.GetWeakPtr(),
235 ROLLBACK)), 235 ROLLBACK)),
236 backend_mode_(IDLE), 236 backend_mode_(IDLE),
237 backup_start_delay_(base::TimeDelta::FromSeconds(kBackupStartDelay)), 237 backup_start_delay_(base::TimeDelta::FromSeconds(kBackupStartDelay)),
238 clear_browsing_data_(base::Bind(&ClearBrowsingData)) { 238 clear_browsing_data_(base::Bind(&ClearBrowsingData)) {
239 DCHECK(profile); 239 DCHECK(profile);
240 syncer::SyncableService::StartSyncFlare flare( 240 syncer::SyncableService::StartSyncFlare flare(
241 sync_start_util::GetFlareForSyncableService(profile->GetPath())); 241 sync_start_util::GetFlareForSyncableService(profile->GetPath()));
242 scoped_ptr<browser_sync::LocalSessionEventRouter> router( 242 scoped_ptr<browser_sync::LocalSessionEventRouter> router(
243 new NotificationServiceSessionsRouter(profile, flare)); 243 new NotificationServiceSessionsRouter(profile, flare));
244
245 DCHECK(factory_.get());
246 local_device_ = factory_->CreateLocalDeviceInfoProvider();
247 sessions_sync_manager_.reset( 244 sessions_sync_manager_.reset(
248 new SessionsSyncManager(profile, local_device_.get(), router.Pass())); 245 new SessionsSyncManager(profile, this, router.Pass()));
249 } 246 }
250 247
251 ProfileSyncService::~ProfileSyncService() { 248 ProfileSyncService::~ProfileSyncService() {
252 sync_prefs_.RemoveSyncPrefObserver(this); 249 sync_prefs_.RemoveSyncPrefObserver(this);
253 // Shutdown() should have been called before destruction. 250 // Shutdown() should have been called before destruction.
254 CHECK(!backend_initialized_); 251 CHECK(!backend_initialized_);
255 } 252 }
256 253
257 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { 254 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() {
258 // Exit if sync is disabled. 255 // Exit if sync is disabled.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { 415 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() {
419 if (!IsSessionsDataTypeControllerRunning()) 416 if (!IsSessionsDataTypeControllerRunning())
420 return NULL; 417 return NULL;
421 return sessions_sync_manager_.get(); 418 return sessions_sync_manager_.get();
422 } 419 }
423 420
424 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() { 421 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() {
425 return sessions_sync_manager_->GetFaviconCache(); 422 return sessions_sync_manager_->GetFaviconCache();
426 } 423 }
427 424
428 browser_sync::SyncedWindowDelegatesGetter* 425 scoped_ptr<browser_sync::DeviceInfo>
429 ProfileSyncService::GetSyncedWindowDelegatesGetter() const { 426 ProfileSyncService::GetLocalDeviceInfo() const {
430 return sessions_sync_manager_->GetSyncedWindowDelegatesGetter(); 427 if (HasSyncingBackend()) {
431 } 428 browser_sync::SyncedDeviceTracker* device_tracker =
432 429 backend_->GetSyncedDeviceTracker();
433 browser_sync::LocalDeviceInfoProvider* 430 if (device_tracker)
434 ProfileSyncService::GetLocalDeviceInfoProvider() { 431 return device_tracker->ReadLocalDeviceInfo();
435 return local_device_.get(); 432 }
433 return scoped_ptr<browser_sync::DeviceInfo>();
436 } 434 }
437 435
438 scoped_ptr<browser_sync::DeviceInfo> 436 scoped_ptr<browser_sync::DeviceInfo>
439 ProfileSyncService::GetDeviceInfo(const std::string& client_id) const { 437 ProfileSyncService::GetDeviceInfo(const std::string& client_id) const {
440 if (HasSyncingBackend()) { 438 if (HasSyncingBackend()) {
441 browser_sync::SyncedDeviceTracker* device_tracker = 439 browser_sync::SyncedDeviceTracker* device_tracker =
442 backend_->GetSyncedDeviceTracker(); 440 backend_->GetSyncedDeviceTracker();
443 if (device_tracker) 441 if (device_tracker)
444 return device_tracker->ReadDeviceInfo(client_id); 442 return device_tracker->ReadDeviceInfo(client_id);
445 } 443 }
446 return scoped_ptr<browser_sync::DeviceInfo>(); 444 return scoped_ptr<browser_sync::DeviceInfo>();
447 } 445 }
448 446
449 ScopedVector<browser_sync::DeviceInfo> 447 ScopedVector<browser_sync::DeviceInfo>
450 ProfileSyncService::GetAllSignedInDevices() const { 448 ProfileSyncService::GetAllSignedInDevices() const {
451 ScopedVector<browser_sync::DeviceInfo> devices; 449 ScopedVector<browser_sync::DeviceInfo> devices;
452 if (HasSyncingBackend()) { 450 if (HasSyncingBackend()) {
453 browser_sync::SyncedDeviceTracker* device_tracker = 451 browser_sync::SyncedDeviceTracker* device_tracker =
454 backend_->GetSyncedDeviceTracker(); 452 backend_->GetSyncedDeviceTracker();
455 if (device_tracker) { 453 if (device_tracker) {
456 // TODO(lipalani) - Make device tracker return a scoped vector. 454 // TODO(lipalani) - Make device tracker return a scoped vector.
457 device_tracker->GetAllSyncedDeviceInfo(&devices); 455 device_tracker->GetAllSyncedDeviceInfo(&devices);
458 } 456 }
459 } 457 }
460 return devices.Pass(); 458 return devices.Pass();
461 } 459 }
462 460
461 std::string ProfileSyncService::GetLocalSyncCacheGUID() const {
462 if (HasSyncingBackend()) {
463 browser_sync::SyncedDeviceTracker* device_tracker =
464 backend_->GetSyncedDeviceTracker();
465 if (device_tracker) {
466 return device_tracker->cache_guid();
467 }
468 }
469 return std::string();
470 }
471
463 // Notifies the observer of any device info changes. 472 // Notifies the observer of any device info changes.
464 void ProfileSyncService::AddObserverForDeviceInfoChange( 473 void ProfileSyncService::AddObserverForDeviceInfoChange(
465 browser_sync::SyncedDeviceTracker::Observer* observer) { 474 browser_sync::SyncedDeviceTracker::Observer* observer) {
466 if (HasSyncingBackend()) { 475 if (HasSyncingBackend()) {
467 browser_sync::SyncedDeviceTracker* device_tracker = 476 browser_sync::SyncedDeviceTracker* device_tracker =
468 backend_->GetSyncedDeviceTracker(); 477 backend_->GetSyncedDeviceTracker();
469 if (device_tracker) { 478 if (device_tracker) {
470 device_tracker->AddObserver(observer); 479 device_tracker->AddObserver(observer);
471 } 480 }
472 } 481 }
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 DCHECK(FirstSetupInProgress()); 1061 DCHECK(FirstSetupInProgress());
1053 } 1062 }
1054 1063
1055 NotifyObservers(); 1064 NotifyObservers();
1056 } 1065 }
1057 1066
1058 void ProfileSyncService::OnBackendInitialized( 1067 void ProfileSyncService::OnBackendInitialized(
1059 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 1068 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
1060 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 1069 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
1061 debug_info_listener, 1070 debug_info_listener,
1062 const std::string& cache_guid,
1063 bool success) { 1071 bool success) {
1064 UpdateBackendInitUMA(success); 1072 UpdateBackendInitUMA(success);
1065 1073
1066 if (!success) { 1074 if (!success) {
1067 // Something went unexpectedly wrong. Play it safe: stop syncing at once 1075 // Something went unexpectedly wrong. Play it safe: stop syncing at once
1068 // and surface error UI to alert the user sync has stopped. 1076 // and surface error UI to alert the user sync has stopped.
1069 // Keep the directory around for now so that on restart we will retry 1077 // Keep the directory around for now so that on restart we will retry
1070 // again and potentially succeed in presence of transient file IO failures 1078 // again and potentially succeed in presence of transient file IO failures
1071 // or permissions issues, etc. 1079 // or permissions issues, etc.
1072 // 1080 //
1073 // TODO(rlarocque): Consider making this UnrecoverableError less special. 1081 // TODO(rlarocque): Consider making this UnrecoverableError less special.
1074 // Unlike every other UnrecoverableError, it does not delete our sync data. 1082 // Unlike every other UnrecoverableError, it does not delete our sync data.
1075 // This exception made sense at the time it was implemented, but our new 1083 // This exception made sense at the time it was implemented, but our new
1076 // directory corruption recovery mechanism makes it obsolete. By the time 1084 // directory corruption recovery mechanism makes it obsolete. By the time
1077 // we get here, we will have already tried and failed to delete the 1085 // we get here, we will have already tried and failed to delete the
1078 // directory. It would be no big deal if we tried to delete it again. 1086 // directory. It would be no big deal if we tried to delete it again.
1079 OnInternalUnrecoverableError(FROM_HERE, 1087 OnInternalUnrecoverableError(FROM_HERE,
1080 "BackendInitialize failure", 1088 "BackendInitialize failure",
1081 false, 1089 false,
1082 ERROR_REASON_BACKEND_INIT_FAILURE); 1090 ERROR_REASON_BACKEND_INIT_FAILURE);
1083 return; 1091 return;
1084 } 1092 }
1085 1093
1086 backend_initialized_ = true; 1094 backend_initialized_ = true;
1087 1095
1088 sync_js_controller_.AttachJsBackend(js_backend); 1096 sync_js_controller_.AttachJsBackend(js_backend);
1089 debug_info_listener_ = debug_info_listener; 1097 debug_info_listener_ = debug_info_listener;
1090 1098
1091 // Initialize local device info.
1092 local_device_->Initialize(cache_guid);
1093
1094 // Give the DataTypeControllers a handle to the now initialized backend 1099 // Give the DataTypeControllers a handle to the now initialized backend
1095 // as a UserShare. 1100 // as a UserShare.
1096 for (DataTypeController::TypeMap::iterator it = 1101 for (DataTypeController::TypeMap::iterator it =
1097 directory_data_type_controllers_.begin(); 1102 directory_data_type_controllers_.begin();
1098 it != directory_data_type_controllers_.end(); ++it) { 1103 it != directory_data_type_controllers_.end(); ++it) {
1099 it->second->OnUserShareReady(GetUserShare()); 1104 it->second->OnUserShareReady(GetUserShare());
1100 } 1105 }
1101 1106
1102 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) 1107 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK)
1103 ConfigureDataTypeManager(); 1108 ConfigureDataTypeManager();
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 } 2590 }
2586 return result; 2591 return result;
2587 } 2592 }
2588 2593
2589 void ProfileSyncService::StartStopBackupForTesting() { 2594 void ProfileSyncService::StartStopBackupForTesting() {
2590 if (backend_mode_ == BACKUP) 2595 if (backend_mode_ == BACKUP)
2591 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 2596 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD);
2592 else 2597 else
2593 backup_rollback_controller_.Start(base::TimeDelta()); 2598 backup_rollback_controller_.Start(base::TimeDelta());
2594 } 2599 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698