OLD | NEW |
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/chromeos/policy/policy_oauth2_token_fetcher.h" | 5 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 const int kRequestRestartDelay = 3000; | 30 const int kRequestRestartDelay = 3000; |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 PolicyOAuth2TokenFetcher::PolicyOAuth2TokenFetcher( | 34 PolicyOAuth2TokenFetcher::PolicyOAuth2TokenFetcher( |
35 net::URLRequestContextGetter* auth_context_getter, | 35 net::URLRequestContextGetter* auth_context_getter, |
36 net::URLRequestContextGetter* system_context_getter, | 36 net::URLRequestContextGetter* system_context_getter, |
37 const TokenCallback& callback) | 37 const TokenCallback& callback) |
38 : auth_context_getter_(auth_context_getter), | 38 : auth_context_getter_(auth_context_getter), |
39 system_context_getter_(system_context_getter), | 39 system_context_getter_(system_context_getter), |
40 retry_count_(0), | |
41 failed_(false), | |
42 callback_(callback) {} | 40 callback_(callback) {} |
43 | 41 |
44 PolicyOAuth2TokenFetcher::PolicyOAuth2TokenFetcher( | 42 PolicyOAuth2TokenFetcher::PolicyOAuth2TokenFetcher( |
45 const std::string& auth_code, | 43 const std::string& auth_code, |
46 net::URLRequestContextGetter* system_context_getter, | 44 net::URLRequestContextGetter* system_context_getter, |
47 const TokenCallback& callback) | 45 const TokenCallback& callback) |
48 : auth_code_(auth_code), | 46 : auth_code_(auth_code), |
49 system_context_getter_(system_context_getter), | 47 system_context_getter_(system_context_getter), |
50 retry_count_(0), | |
51 failed_(false), | |
52 callback_(callback) { | 48 callback_(callback) { |
53 } | 49 } |
54 | 50 |
55 PolicyOAuth2TokenFetcher::~PolicyOAuth2TokenFetcher() {} | 51 PolicyOAuth2TokenFetcher::~PolicyOAuth2TokenFetcher() {} |
56 | 52 |
57 void PolicyOAuth2TokenFetcher::Start() { | 53 void PolicyOAuth2TokenFetcher::Start() { |
58 retry_count_ = 0; | 54 retry_count_ = 0; |
59 StartFetchingRefreshToken(); | 55 StartFetchingRefreshToken(); |
60 } | 56 } |
61 | 57 |
| 58 void PolicyOAuth2TokenFetcher::StartWithRefreshToken( |
| 59 const std::string& oauth2_refresh_token) { |
| 60 retry_count_ = 0; |
| 61 oauth2_refresh_token_ = oauth2_refresh_token; |
| 62 StartFetchingAccessToken(); |
| 63 } |
| 64 |
62 void PolicyOAuth2TokenFetcher::StartFetchingRefreshToken() { | 65 void PolicyOAuth2TokenFetcher::StartFetchingRefreshToken() { |
63 if (auth_code_.empty()) { | 66 if (auth_code_.empty()) { |
64 refresh_token_fetcher_.reset(new GaiaAuthFetcher( | 67 refresh_token_fetcher_.reset(new GaiaAuthFetcher( |
65 this, GaiaConstants::kChromeSource, auth_context_getter_.get())); | 68 this, GaiaConstants::kChromeSource, auth_context_getter_.get())); |
66 refresh_token_fetcher_->StartCookieForOAuthLoginTokenExchange( | 69 refresh_token_fetcher_->StartCookieForOAuthLoginTokenExchange( |
67 std::string()); | 70 std::string()); |
68 } else { | 71 } else { |
69 refresh_token_fetcher_.reset(new GaiaAuthFetcher( | 72 refresh_token_fetcher_.reset(new GaiaAuthFetcher( |
70 this, GaiaConstants::kChromeSource, system_context_getter_.get())); | 73 this, GaiaConstants::kChromeSource, system_context_getter_.get())); |
71 refresh_token_fetcher_->StartAuthCodeForOAuth2TokenExchange(auth_code_); | 74 refresh_token_fetcher_->StartAuthCodeForOAuth2TokenExchange(auth_code_); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 145 } |
143 | 146 |
144 void PolicyOAuth2TokenFetcher::ForwardPolicyToken( | 147 void PolicyOAuth2TokenFetcher::ForwardPolicyToken( |
145 const std::string& token, | 148 const std::string& token, |
146 const GoogleServiceAuthError& error) { | 149 const GoogleServiceAuthError& error) { |
147 if (!callback_.is_null()) | 150 if (!callback_.is_null()) |
148 callback_.Run(token, error); | 151 callback_.Run(token, error); |
149 } | 152 } |
150 | 153 |
151 } // namespace policy | 154 } // namespace policy |
OLD | NEW |