OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/signin/profile_oauth2_token_service_request.h" | 5 #include "chrome/browser/signin/profile_oauth2_token_service_request.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 ProfileOAuth2TokenServiceRequest* owner); | 26 ProfileOAuth2TokenServiceRequest* owner); |
27 // Starts fetching an OAuth2 access token for |account_id| and |scopes|. It | 27 // Starts fetching an OAuth2 access token for |account_id| and |scopes|. It |
28 // should be called on the owner thread. | 28 // should be called on the owner thread. |
29 void Start( | 29 void Start( |
30 const std::string& account_id, | 30 const std::string& account_id, |
31 const OAuth2TokenService::ScopeSet& scopes); | 31 const OAuth2TokenService::ScopeSet& scopes); |
32 // Stops the OAuth2 access token fetching. It should be called on the owner | 32 // Stops the OAuth2 access token fetching. It should be called on the owner |
33 // thread. | 33 // thread. |
34 void Stop(); | 34 void Stop(); |
35 | 35 |
| 36 OAuth2TokenService::Request* request(); |
| 37 |
36 // OAuth2TokenService::Consumer. It should be called on the UI thread. | 38 // OAuth2TokenService::Consumer. It should be called on the UI thread. |
37 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 39 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
38 const std::string& access_token, | 40 const std::string& access_token, |
39 const base::Time& expiration_time) OVERRIDE; | 41 const base::Time& expiration_time) OVERRIDE; |
40 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 42 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
41 const GoogleServiceAuthError& error) OVERRIDE; | 43 const GoogleServiceAuthError& error) OVERRIDE; |
42 | 44 |
43 private: | 45 private: |
44 friend class | 46 friend class |
45 base::RefCountedThreadSafe<ProfileOAuth2TokenServiceRequest::Core>; | 47 base::RefCountedThreadSafe<ProfileOAuth2TokenServiceRequest::Core>; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 StopOnUIThread(); | 119 StopOnUIThread(); |
118 } else { | 120 } else { |
119 content::BrowserThread::PostTask( | 121 content::BrowserThread::PostTask( |
120 content::BrowserThread::UI, | 122 content::BrowserThread::UI, |
121 FROM_HERE, | 123 FROM_HERE, |
122 base::Bind(&ProfileOAuth2TokenServiceRequest::Core::StopOnUIThread, | 124 base::Bind(&ProfileOAuth2TokenServiceRequest::Core::StopOnUIThread, |
123 this)); | 125 this)); |
124 } | 126 } |
125 } | 127 } |
126 | 128 |
| 129 OAuth2TokenService::Request* ProfileOAuth2TokenServiceRequest::Core::request() { |
| 130 return request_.get(); |
| 131 } |
| 132 |
127 void ProfileOAuth2TokenServiceRequest::Core::StopOnUIThread() { | 133 void ProfileOAuth2TokenServiceRequest::Core::StopOnUIThread() { |
128 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 134 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
129 request_.reset(); | 135 request_.reset(); |
130 } | 136 } |
131 | 137 |
132 void ProfileOAuth2TokenServiceRequest::Core::StartOnUIThread( | 138 void ProfileOAuth2TokenServiceRequest::Core::StartOnUIThread( |
133 const std::string& account_id, | 139 const std::string& account_id, |
134 const OAuth2TokenService::ScopeSet& scopes) { | 140 const OAuth2TokenService::ScopeSet& scopes) { |
135 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 141 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
136 | 142 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 OAuth2TokenService::Consumer* consumer) | 210 OAuth2TokenService::Consumer* consumer) |
205 : consumer_(consumer), | 211 : consumer_(consumer), |
206 core_(new Core(profile, this)) { | 212 core_(new Core(profile, this)) { |
207 core_->Start(account_id, scopes); | 213 core_->Start(account_id, scopes); |
208 } | 214 } |
209 | 215 |
210 ProfileOAuth2TokenServiceRequest::~ProfileOAuth2TokenServiceRequest() { | 216 ProfileOAuth2TokenServiceRequest::~ProfileOAuth2TokenServiceRequest() { |
211 DCHECK(CalledOnValidThread()); | 217 DCHECK(CalledOnValidThread()); |
212 core_->Stop(); | 218 core_->Stop(); |
213 } | 219 } |
| 220 |
| 221 std::string ProfileOAuth2TokenServiceRequest::GetAccountId() const { |
| 222 return core_->request()->GetAccountId(); |
| 223 } |
| 224 |
OLD | NEW |