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

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

Issue 33173005: Correctly deal with tokens for supervised users in ProfileOAuth2TokenService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 7 years, 1 month 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 | Annotate | Revision Log
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "sync/internal_api/public/sync_encryption_handler.h" 71 #include "sync/internal_api/public/sync_encryption_handler.h"
72 #include "sync/internal_api/public/util/experiments.h" 72 #include "sync/internal_api/public/util/experiments.h"
73 #include "sync/internal_api/public/util/sync_string_conversions.h" 73 #include "sync/internal_api/public/util/sync_string_conversions.h"
74 #include "sync/js/js_arg_list.h" 74 #include "sync/js/js_arg_list.h"
75 #include "sync/js/js_event_details.h" 75 #include "sync/js/js_event_details.h"
76 #include "sync/util/cryptographer.h" 76 #include "sync/util/cryptographer.h"
77 #include "ui/base/l10n/l10n_util.h" 77 #include "ui/base/l10n/l10n_util.h"
78 #include "ui/base/l10n/time_format.h" 78 #include "ui/base/l10n/time_format.h"
79 79
80 #if defined(ENABLE_MANAGED_USERS) 80 #if defined(ENABLE_MANAGED_USERS)
81 #include "chrome/browser/managed_mode/managed_user_service.h" 81 #include "chrome/browser/managed_mode/managed_user_constants.h"
82 #endif 82 #endif
83 83
84 #if defined(OS_ANDROID) 84 #if defined(OS_ANDROID)
85 #include "sync/internal_api/public/read_transaction.h" 85 #include "sync/internal_api/public/read_transaction.h"
86 #endif 86 #endif
87 87
88 using browser_sync::ChangeProcessor; 88 using browser_sync::ChangeProcessor;
89 using browser_sync::DataTypeController; 89 using browser_sync::DataTypeController;
90 using browser_sync::DataTypeManager; 90 using browser_sync::DataTypeManager;
91 using browser_sync::FailedDataTypesHandler; 91 using browser_sync::FailedDataTypesHandler;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (IsManaged() || sync_prefs_.IsStartSuppressed()) 202 if (IsManaged() || sync_prefs_.IsStartSuppressed())
203 return false; 203 return false;
204 204
205 // Sync is logged in if there is a non-empty effective username. 205 // Sync is logged in if there is a non-empty effective username.
206 return !GetEffectiveUsername().empty(); 206 return !GetEffectiveUsername().empty();
207 } 207 }
208 208
209 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { 209 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() {
210 if (!oauth2_token_service_) 210 if (!oauth2_token_service_)
211 return false; 211 return false;
212 return oauth2_token_service_->RefreshTokenIsAvailable( 212
213 oauth2_token_service_->GetPrimaryAccountId()); 213 return oauth2_token_service_->RefreshTokenIsAvailable(GetAccountIdToUse());
214 } 214 }
215 215
216 void ProfileSyncService::Initialize() { 216 void ProfileSyncService::Initialize() {
217 if (profile_) 217 if (profile_)
218 SigninGlobalError::GetForProfile(profile_)->AddProvider(this); 218 SigninGlobalError::GetForProfile(profile_)->AddProvider(this);
219 219
220 InitSettings(); 220 InitSettings();
221 221
222 // We clear this here (vs Shutdown) because we want to remember that an error 222 // We clear this here (vs Shutdown) because we want to remember that an error
223 // happened on shutdown so we can display details (message, location) about it 223 // happened on shutdown so we can display details (message, location) about it
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 691 }
692 default: { 692 default: {
693 // Show error to user. 693 // Show error to user.
694 UpdateAuthErrorState(error); 694 UpdateAuthErrorState(error);
695 } 695 }
696 } 696 }
697 } 697 }
698 698
699 void ProfileSyncService::OnRefreshTokenAvailable( 699 void ProfileSyncService::OnRefreshTokenAvailable(
700 const std::string& account_id) { 700 const std::string& account_id) {
701 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) 701 if (account_id == GetAccountIdToUse())
702 OnRefreshTokensLoaded(); 702 OnRefreshTokensLoaded();
703 } 703 }
704 704
705 void ProfileSyncService::OnRefreshTokenRevoked( 705 void ProfileSyncService::OnRefreshTokenRevoked(
706 const std::string& account_id) { 706 const std::string& account_id) {
707 if (!IsOAuthRefreshTokenAvailable()) { 707 if (!IsOAuthRefreshTokenAvailable()) {
708 access_token_.clear(); 708 access_token_.clear();
709 // The additional check around IsOAuthRefreshTokenAvailable() above 709 // The additional check around IsOAuthRefreshTokenAvailable() above
710 // prevents us sounding the alarm if we actually have a valid token but 710 // prevents us sounding the alarm if we actually have a valid token but
711 // a refresh attempt by TokenService failed for any variety of reasons 711 // a refresh attempt by TokenService failed for any variety of reasons
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 request_access_token_retry_timer_.Stop(); 1880 request_access_token_retry_timer_.Stop();
1881 OAuth2TokenService::ScopeSet oauth2_scopes; 1881 OAuth2TokenService::ScopeSet oauth2_scopes;
1882 if (profile_->IsManaged()) { 1882 if (profile_->IsManaged()) {
1883 oauth2_scopes.insert(GaiaConstants::kChromeSyncManagedOAuth2Scope); 1883 oauth2_scopes.insert(GaiaConstants::kChromeSyncManagedOAuth2Scope);
1884 } else { 1884 } else {
1885 oauth2_scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); 1885 oauth2_scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
1886 } 1886 }
1887 1887
1888 // Invalidate previous token, otherwise token service will return the same 1888 // Invalidate previous token, otherwise token service will return the same
1889 // token again. 1889 // token again.
1890 const std::string& account_id = oauth2_token_service_->GetPrimaryAccountId(); 1890 const std::string& account_id = GetAccountIdToUse();
1891 if (!access_token_.empty()) { 1891 if (!access_token_.empty()) {
1892 oauth2_token_service_->InvalidateToken( 1892 oauth2_token_service_->InvalidateToken(
1893 account_id, oauth2_scopes, access_token_); 1893 account_id, oauth2_scopes, access_token_);
1894 } 1894 }
1895 1895
1896 access_token_.clear(); 1896 access_token_.clear();
1897 access_token_request_ = 1897 access_token_request_ =
1898 oauth2_token_service_->StartRequest(account_id, oauth2_scopes, this); 1898 oauth2_token_service_->StartRequest(account_id, oauth2_scopes, this);
1899 } 1899 }
1900 1900
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 UnrecoverableErrorReason reason) { 2122 UnrecoverableErrorReason reason) {
2123 DCHECK(!HasUnrecoverableError()); 2123 DCHECK(!HasUnrecoverableError());
2124 unrecoverable_error_reason_ = reason; 2124 unrecoverable_error_reason_ = reason;
2125 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); 2125 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database);
2126 } 2126 }
2127 2127
2128 std::string ProfileSyncService::GetEffectiveUsername() { 2128 std::string ProfileSyncService::GetEffectiveUsername() {
2129 if (profile_->IsManaged()) { 2129 if (profile_->IsManaged()) {
2130 #if defined(ENABLE_MANAGED_USERS) 2130 #if defined(ENABLE_MANAGED_USERS)
2131 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); 2131 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername());
2132 return ManagedUserService::GetManagedUserPseudoEmail(); 2132 return managed_users::kManagedUserPseudoEmail;
2133 #else 2133 #else
2134 NOTREACHED(); 2134 NOTREACHED();
2135 #endif 2135 #endif
2136 } 2136 }
2137 2137
2138 return signin_->GetAuthenticatedUsername(); 2138 return signin_->GetAuthenticatedUsername();
2139 } 2139 }
2140 2140
2141 std::string ProfileSyncService::GetAccountIdToUse() {
2142 if (profile_->IsManaged()) {
2143 #if defined(ENABLE_MANAGED_USERS)
2144 return managed_users::kManagedUserPseudoEmail;
2145 #else
2146 NOTREACHED();
2147 #endif
2148 }
2149
2150 // TODO(fgorski): Use GetPrimaryAccountId() when it's available.
2151 return signin_->GetAuthenticatedUsername();
2152 }
2153
2141 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { 2154 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() {
2142 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); 2155 return MakeWeakHandle(sync_js_controller_.AsWeakPtr());
2143 } 2156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698