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

Side by Side Diff: chrome/browser/chromeos/login/oauth2_policy_fetcher.cc

Issue 11969010: Fixed OAuth2 policy fetching retry logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/login/oauth2_policy_fetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromeos/login/oauth2_policy_fetcher.h" 5 #include "chrome/browser/chromeos/login/oauth2_policy_fetcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 20 matching lines...) Expand all
31 const int kRequestRestartDelay = 3000; 31 const int kRequestRestartDelay = 3000;
32 32
33 const char kServiceScopeChromeOSDeviceManagement[] = 33 const char kServiceScopeChromeOSDeviceManagement[] =
34 "https://www.googleapis.com/auth/chromeosdevicemanagement"; 34 "https://www.googleapis.com/auth/chromeosdevicemanagement";
35 35
36 } // namespace 36 } // namespace
37 37
38 OAuth2PolicyFetcher::OAuth2PolicyFetcher( 38 OAuth2PolicyFetcher::OAuth2PolicyFetcher(
39 net::URLRequestContextGetter* auth_context_getter, 39 net::URLRequestContextGetter* auth_context_getter,
40 net::URLRequestContextGetter* system_context_getter) 40 net::URLRequestContextGetter* system_context_getter)
41 : refresh_token_fetcher_( 41 : auth_context_getter_(auth_context_getter),
42 new GaiaAuthFetcher(this, 42 system_context_getter_(system_context_getter),
43 GaiaConstants::kChromeSource,
44 auth_context_getter)),
45 access_token_fetcher_(
46 new OAuth2AccessTokenFetcher(this, system_context_getter)),
47 retry_count_(0), 43 retry_count_(0),
48 failed_(false) { 44 failed_(false) {
49 } 45 }
50 46
51 OAuth2PolicyFetcher::OAuth2PolicyFetcher( 47 OAuth2PolicyFetcher::OAuth2PolicyFetcher(
52 net::URLRequestContextGetter* system_context_getter, 48 net::URLRequestContextGetter* system_context_getter,
53 const std::string& oauth2_refresh_token) 49 const std::string& oauth2_refresh_token)
54 : access_token_fetcher_( 50 : system_context_getter_(system_context_getter),
55 new OAuth2AccessTokenFetcher(this, system_context_getter)),
56 oauth2_refresh_token_(oauth2_refresh_token), 51 oauth2_refresh_token_(oauth2_refresh_token),
57 retry_count_(0), 52 retry_count_(0),
58 failed_(false) { 53 failed_(false) {
59 } 54 }
60 55
61 OAuth2PolicyFetcher::~OAuth2PolicyFetcher() { 56 OAuth2PolicyFetcher::~OAuth2PolicyFetcher() {
62 } 57 }
63 58
64 void OAuth2PolicyFetcher::Start() { 59 void OAuth2PolicyFetcher::Start() {
65 retry_count_ = 0; 60 retry_count_ = 0;
66 if (oauth2_refresh_token_.empty()) { 61 if (oauth2_refresh_token_.empty()) {
67 StartFetchingRefreshToken(); 62 StartFetchingRefreshToken();
68 } else { 63 } else {
69 StartFetchingAccessToken(); 64 StartFetchingAccessToken();
70 } 65 }
71 } 66 }
72 67
73 void OAuth2PolicyFetcher::StartFetchingRefreshToken() { 68 void OAuth2PolicyFetcher::StartFetchingRefreshToken() {
74 DCHECK(refresh_token_fetcher_.get()); 69 DCHECK(refresh_token_fetcher_.get());
70 refresh_token_fetcher_.reset(
71 new GaiaAuthFetcher(this,
72 GaiaConstants::kChromeSource,
73 auth_context_getter_));
75 refresh_token_fetcher_->StartCookieForOAuthLoginTokenExchange(EmptyString()); 74 refresh_token_fetcher_->StartCookieForOAuthLoginTokenExchange(EmptyString());
76 } 75 }
77 76
78 void OAuth2PolicyFetcher::StartFetchingAccessToken() { 77 void OAuth2PolicyFetcher::StartFetchingAccessToken() {
79 std::vector<std::string> scopes; 78 std::vector<std::string> scopes;
80 scopes.push_back(kServiceScopeChromeOSDeviceManagement); 79 scopes.push_back(kServiceScopeChromeOSDeviceManagement);
80 access_token_fetcher_.reset(
81 new OAuth2AccessTokenFetcher(this, system_context_getter_));
81 access_token_fetcher_->Start( 82 access_token_fetcher_->Start(
82 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), 83 GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
83 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), 84 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
84 oauth2_refresh_token_, 85 oauth2_refresh_token_,
85 scopes); 86 scopes);
86 } 87 }
87 88
88 void OAuth2PolicyFetcher::OnClientOAuthSuccess( 89 void OAuth2PolicyFetcher::OnClientOAuthSuccess(
89 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { 90 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) {
90 LOG(INFO) << "OAuth2 tokens for policy fetching succeeded."; 91 LOG(INFO) << "OAuth2 tokens for policy fetching succeeded.";
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 browser_policy_connector->GetUserCloudPolicyManager(); 147 browser_policy_connector->GetUserCloudPolicyManager();
147 if (cloud_policy_manager) { 148 if (cloud_policy_manager) {
148 if (token.empty()) 149 if (token.empty())
149 cloud_policy_manager->CancelWaitForPolicyFetch(); 150 cloud_policy_manager->CancelWaitForPolicyFetch();
150 else 151 else
151 cloud_policy_manager->RegisterClient(token); 152 cloud_policy_manager->RegisterClient(token);
152 } 153 }
153 } 154 }
154 155
155 } // namespace chromeos 156 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/oauth2_policy_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698