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

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

Issue 2657673004: Add shutdown notification and service refs to SyncServiceObserver. (Closed)
Patch Set: Chromeos fix Created 3 years, 10 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/sync_startup_tracker.h" 5 #include "chrome/browser/sync/sync_startup_tracker.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/sync/profile_sync_service_factory.h" 8 #include "chrome/browser/sync/profile_sync_service_factory.h"
9 #include "components/browser_sync/profile_sync_service.h" 9 #include "components/browser_sync/profile_sync_service.h"
10 10
11 SyncStartupTracker::SyncStartupTracker(Profile* profile, Observer* observer) 11 SyncStartupTracker::SyncStartupTracker(Profile* profile, Observer* observer)
12 : profile_(profile), 12 : profile_(profile),
13 observer_(observer) { 13 observer_(observer) {
14 browser_sync::ProfileSyncService* service = 14 browser_sync::ProfileSyncService* service =
15 ProfileSyncServiceFactory::GetForProfile(profile_); 15 ProfileSyncServiceFactory::GetForProfile(profile_);
16 if (service) 16 if (service)
17 service->AddObserver(this); 17 service->AddObserver(this);
18 18
19 CheckServiceState(); 19 CheckServiceState();
20 } 20 }
21 21
22 SyncStartupTracker::~SyncStartupTracker() { 22 SyncStartupTracker::~SyncStartupTracker() {
23 browser_sync::ProfileSyncService* service = 23 browser_sync::ProfileSyncService* service =
24 ProfileSyncServiceFactory::GetForProfile(profile_); 24 ProfileSyncServiceFactory::GetForProfile(profile_);
25 if (service) 25 if (service)
26 service->RemoveObserver(this); 26 service->RemoveObserver(this);
27 } 27 }
28 28
29 void SyncStartupTracker::OnStateChanged() { 29 void SyncStartupTracker::OnStateChanged(syncer::SyncService* sync) {
30 CheckServiceState(); 30 CheckServiceState();
31 } 31 }
32 32
33 void SyncStartupTracker::CheckServiceState() { 33 void SyncStartupTracker::CheckServiceState() {
34 // Note: the observer may free this object so it is not allowed to access 34 // Note: the observer may free this object so it is not allowed to access
35 // this object after invoking the observer callback below. 35 // this object after invoking the observer callback below.
36 switch (GetSyncServiceState(profile_)) { 36 switch (GetSyncServiceState(profile_)) {
37 case SYNC_STARTUP_ERROR: 37 case SYNC_STARTUP_ERROR:
38 observer_->SyncStartupFailed(); 38 observer_->SyncStartupFailed();
39 break; 39 break;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // to be fetched, exit. 73 // to be fetched, exit.
74 if (!service->waiting_for_auth() && 74 if (!service->waiting_for_auth() &&
75 service->GetAuthError().state() != GoogleServiceAuthError::NONE) { 75 service->GetAuthError().state() != GoogleServiceAuthError::NONE) {
76 return SYNC_STARTUP_ERROR; 76 return SYNC_STARTUP_ERROR;
77 } 77 }
78 78
79 // No error detected yet, but the sync engine hasn't started up yet, so 79 // No error detected yet, but the sync engine hasn't started up yet, so
80 // we're in the pending state. 80 // we're in the pending state.
81 return SYNC_STARTUP_PENDING; 81 return SYNC_STARTUP_PENDING;
82 } 82 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_startup_tracker.h ('k') | chrome/browser/sync/sync_startup_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698