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 "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 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/defaults.h" | 27 #include "chrome/browser/defaults.h" |
28 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 28 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
29 #include "chrome/browser/prefs/pref_service_syncable.h" | 29 #include "chrome/browser/prefs/pref_service_syncable.h" |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/signin/about_signin_internals.h" | 31 #include "chrome/browser/signin/about_signin_internals.h" |
32 #include "chrome/browser/signin/about_signin_internals_factory.h" | 32 #include "chrome/browser/signin/about_signin_internals_factory.h" |
33 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 33 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
34 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 34 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
35 #include "chrome/browser/signin/signin_manager.h" | 35 #include "chrome/browser/signin/signin_manager.h" |
36 #include "chrome/browser/signin/signin_manager_factory.h" | 36 #include "chrome/browser/signin/signin_manager_factory.h" |
37 #include "chrome/browser/signin/token_service.h" | |
38 #include "chrome/browser/signin/token_service_factory.h" | |
39 #include "chrome/browser/sync/backend_migrator.h" | 37 #include "chrome/browser/sync/backend_migrator.h" |
40 #include "chrome/browser/sync/glue/change_processor.h" | 38 #include "chrome/browser/sync/glue/change_processor.h" |
41 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 39 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
42 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 40 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
43 #include "chrome/browser/sync/glue/data_type_controller.h" | 41 #include "chrome/browser/sync/glue/data_type_controller.h" |
44 #include "chrome/browser/sync/glue/device_info.h" | 42 #include "chrome/browser/sync/glue/device_info.h" |
45 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 43 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
46 #include "chrome/browser/sync/glue/session_model_associator.h" | 44 #include "chrome/browser/sync/glue/session_model_associator.h" |
47 #include "chrome/browser/sync/glue/sync_backend_host.h" | 45 #include "chrome/browser/sync/glue/sync_backend_host.h" |
48 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" | 46 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); | 271 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); |
274 sync_prefs_.SetKeepEverythingSynced(true); | 272 sync_prefs_.SetKeepEverythingSynced(true); |
275 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 273 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
276 sync_prefs_.SetPreferredDataTypes(registered_types, | 274 sync_prefs_.SetPreferredDataTypes(registered_types, |
277 registered_types); | 275 registered_types); |
278 } | 276 } |
279 | 277 |
280 void ProfileSyncService::TryStart() { | 278 void ProfileSyncService::TryStart() { |
281 if (!IsSyncEnabledAndLoggedIn()) | 279 if (!IsSyncEnabledAndLoggedIn()) |
282 return; | 280 return; |
283 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 281 |
284 if (!token_service) | 282 // Don't start sync until tokens are loaded, because the user can be |
| 283 // "signed in" long before the tokens get loaded, and we don't want to |
| 284 // generate spurious auth errors. |
| 285 if (!IsOAuthRefreshTokenAvailable()) |
285 return; | 286 return; |
286 // Don't start the backend if the token service hasn't finished loading tokens | |
287 // yet. Note if the backend is started before the sync token has been loaded, | |
288 // GetCredentials() will return bogus credentials. On auto_start platforms | |
289 // (like ChromeOS) we don't start sync until tokens are loaded, because the | |
290 // user can be "signed in" on those platforms long before the tokens get | |
291 // loaded, and we don't want to generate spurious auth errors. | |
292 if (!IsOAuthRefreshTokenAvailable() && | |
293 !(!auto_start_enabled_ && token_service->TokensLoadedFromDB())) { | |
294 return; | |
295 } | |
296 | 287 |
297 // If we got here then tokens are loaded and user logged in and sync is | 288 // If we got here then tokens are loaded and user logged in and sync is |
298 // enabled. If OAuth refresh token is not available then something is wrong. | 289 // enabled. If OAuth refresh token is not available then something is wrong. |
299 // When PSS requests access token, OAuth2TokenService will return error and | 290 // When PSS requests access token, OAuth2TokenService will return error and |
300 // PSS will show error to user asking to reauthenticate. | 291 // PSS will show error to user asking to reauthenticate. |
301 UMA_HISTOGRAM_BOOLEAN("Sync.RefreshTokenAvailable", | 292 UMA_HISTOGRAM_BOOLEAN("Sync.RefreshTokenAvailable", |
302 IsOAuthRefreshTokenAvailable()); | 293 IsOAuthRefreshTokenAvailable()); |
303 | 294 |
304 // If sync setup has completed we always start the backend. If the user is in | 295 // If sync setup has completed we always start the backend. If the user is in |
305 // the process of setting up now, we should start the backend to download | 296 // the process of setting up now, we should start the backend to download |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 if (account_id == GetAccountIdToUse()) | 715 if (account_id == GetAccountIdToUse()) |
725 OnRefreshTokensLoaded(); | 716 OnRefreshTokensLoaded(); |
726 } | 717 } |
727 | 718 |
728 void ProfileSyncService::OnRefreshTokenRevoked( | 719 void ProfileSyncService::OnRefreshTokenRevoked( |
729 const std::string& account_id) { | 720 const std::string& account_id) { |
730 if (!IsOAuthRefreshTokenAvailable()) { | 721 if (!IsOAuthRefreshTokenAvailable()) { |
731 access_token_.clear(); | 722 access_token_.clear(); |
732 // The additional check around IsOAuthRefreshTokenAvailable() above | 723 // The additional check around IsOAuthRefreshTokenAvailable() above |
733 // prevents us sounding the alarm if we actually have a valid token but | 724 // prevents us sounding the alarm if we actually have a valid token but |
734 // a refresh attempt by TokenService failed for any variety of reasons | 725 // a refresh attempt failed for any variety of reasons |
735 // (e.g. flaky network). It's possible the token we do have is also | 726 // (e.g. flaky network). It's possible the token we do have is also |
736 // invalid, but in that case we should already have (or can expect) an | 727 // invalid, but in that case we should already have (or can expect) an |
737 // auth error sent from the sync backend. | 728 // auth error sent from the sync backend. |
738 UpdateAuthErrorState( | 729 UpdateAuthErrorState( |
739 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); | 730 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); |
740 } | 731 } |
741 } | 732 } |
742 | 733 |
743 void ProfileSyncService::OnRefreshTokensLoaded() { | 734 void ProfileSyncService::OnRefreshTokensLoaded() { |
744 // This notification gets fired when TokenService loads the tokens | 735 // This notification gets fired when OAuth2TokenService loads the tokens |
745 // from storage. | 736 // from storage. |
746 // Initialize the backend if sync is enabled. If the sync token was | 737 // Initialize the backend if sync is enabled. If the sync token was |
747 // not loaded, GetCredentials() will generate invalid credentials to | 738 // not loaded, GetCredentials() will generate invalid credentials to |
748 // cause the backend to generate an auth error (crbug.com/121755). | 739 // cause the backend to generate an auth error (crbug.com/121755). |
749 if (backend_) { | 740 if (backend_) { |
750 RequestAccessToken(); | 741 RequestAccessToken(); |
751 } else { | 742 } else { |
752 TryStart(); | 743 TryStart(); |
753 } | 744 } |
754 } | 745 } |
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2216 SyncTokenStatus status; | 2207 SyncTokenStatus status; |
2217 status.connection_status_update_time = connection_status_update_time_; | 2208 status.connection_status_update_time = connection_status_update_time_; |
2218 status.connection_status = connection_status_; | 2209 status.connection_status = connection_status_; |
2219 status.token_request_time = token_request_time_; | 2210 status.token_request_time = token_request_time_; |
2220 status.token_receive_time = token_receive_time_; | 2211 status.token_receive_time = token_receive_time_; |
2221 status.last_get_token_error = last_get_token_error_; | 2212 status.last_get_token_error = last_get_token_error_; |
2222 if (request_access_token_retry_timer_.IsRunning()) | 2213 if (request_access_token_retry_timer_.IsRunning()) |
2223 status.next_token_request_time = next_token_request_time_; | 2214 status.next_token_request_time = next_token_request_time_; |
2224 return status; | 2215 return status; |
2225 } | 2216 } |
OLD | NEW |