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

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

Issue 15780020: Setup Sync to use OAuth token for managed users. (Closed) Base URL: http://git.chromium.org/chromium/src.git@issue226464a
Patch Set: fix Created 7 years, 6 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 "https://clients4.google.com/chrome-sync/dev"; 113 "https://clients4.google.com/chrome-sync/dev";
114 114
115 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. 115 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute.
116 116
117 static const char* kOAuth2Scopes[] = { 117 static const char* kOAuth2Scopes[] = {
118 GaiaConstants::kChromeSyncOAuth2Scope, 118 GaiaConstants::kChromeSyncOAuth2Scope,
119 // GoogleTalk scope is needed for notifications. 119 // GoogleTalk scope is needed for notifications.
120 GaiaConstants::kGoogleTalkOAuth2Scope 120 GaiaConstants::kGoogleTalkOAuth2Scope
121 }; 121 };
122 122
123 static const char* kManagedOAuth2Scopes[] = {
124 GaiaConstants::kChromeSyncManagedOAuth2Scope
125 };
123 126
124 static const char* kSyncUnrecoverableErrorHistogram = 127 static const char* kSyncUnrecoverableErrorHistogram =
125 "Sync.UnrecoverableErrors"; 128 "Sync.UnrecoverableErrors";
126 129
127 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { 130 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = {
128 // Number of initial errors (in sequence) to ignore before applying 131 // Number of initial errors (in sequence) to ignore before applying
129 // exponential back-off rules. 132 // exponential back-off rules.
130 0, 133 0,
131 134
132 // Initial delay for exponential back-off in ms. 135 // Initial delay for exponential back-off in ms.
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 if (!IsUsingSecondaryPassphrase()) 1919 if (!IsUsingSecondaryPassphrase())
1917 SetEncryptionPassphrase(passphrase, IMPLICIT); 1920 SetEncryptionPassphrase(passphrase, IMPLICIT);
1918 } 1921 }
1919 1922
1920 void ProfileSyncService::RequestAccessToken() { 1923 void ProfileSyncService::RequestAccessToken() {
1921 // Only one active request at a time. 1924 // Only one active request at a time.
1922 if (access_token_request_ != NULL) 1925 if (access_token_request_ != NULL)
1923 return; 1926 return;
1924 request_access_token_retry_timer_.Stop(); 1927 request_access_token_retry_timer_.Stop();
1925 OAuth2TokenService::ScopeSet oauth2_scopes; 1928 OAuth2TokenService::ScopeSet oauth2_scopes;
1926 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) 1929 bool is_managed = false;
1927 oauth2_scopes.insert(kOAuth2Scopes[i]); 1930 #if defined(ENABLE_MANAGED_USERS)
1931 is_managed = ManagedUserService::ProfileIsManaged(profile_);
1932 #endif
1933 if (is_managed) {
1934 for (size_t i = 0; i < arraysize(kManagedOAuth2Scopes); i++)
1935 oauth2_scopes.insert(kManagedOAuth2Scopes[i]);
1936 } else {
1937 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++)
1938 oauth2_scopes.insert(kOAuth2Scopes[i]);
1939 }
1940
1928 OAuth2TokenService* token_service = 1941 OAuth2TokenService* token_service =
1929 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 1942 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
1930 // Invalidate previous token, otherwise token service will return the same 1943 // Invalidate previous token, otherwise token service will return the same
1931 // token again. 1944 // token again.
1932 token_service->InvalidateToken(oauth2_scopes, access_token_); 1945 token_service->InvalidateToken(oauth2_scopes, access_token_);
1933 access_token_.clear(); 1946 access_token_.clear();
1934 access_token_request_ = token_service->StartRequest(oauth2_scopes, this); 1947 access_token_request_ = token_service->StartRequest(oauth2_scopes, this);
1935 } 1948 }
1936 1949
1937 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, 1950 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 std::string ProfileSyncService::GetEffectiveUsername() { 2228 std::string ProfileSyncService::GetEffectiveUsername() {
2216 #if defined(ENABLE_MANAGED_USERS) 2229 #if defined(ENABLE_MANAGED_USERS)
2217 if (ManagedUserService::ProfileIsManaged(profile_)) { 2230 if (ManagedUserService::ProfileIsManaged(profile_)) {
2218 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); 2231 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername());
2219 return ManagedUserService::GetManagedUserPseudoEmail(); 2232 return ManagedUserService::GetManagedUserPseudoEmail();
2220 } 2233 }
2221 #endif 2234 #endif
2222 2235
2223 return signin_->GetAuthenticatedUsername(); 2236 return signin_->GetAuthenticatedUsername();
2224 } 2237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698