Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "google_apis/gaia/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" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | |
| 16 #include "components/signin/core/browser/signin_manager.h" | |
| 17 #include "content/public/browser/browser_thread.h" | |
| 18 #include "google_apis/gaia/google_service_auth_error.h" | 12 #include "google_apis/gaia/google_service_auth_error.h" |
| 19 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 13 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
| 20 | 14 |
| 21 class ProfileOAuth2TokenServiceRequest::Core | 15 OAuth2TokenServiceRequest::TokenServiceProvider::TokenServiceProvider() { |
| 22 : public base::RefCountedThreadSafe<ProfileOAuth2TokenServiceRequest::Core>, | 16 } |
| 23 public OAuth2TokenService::Consumer { | 17 |
| 18 OAuth2TokenServiceRequest::TokenServiceProvider::~TokenServiceProvider() { | |
| 19 } | |
| 20 | |
| 21 // Core serves as the base class for OAuth2TokenService operations. Each | |
| 22 // operation should be modeled as a derived type. | |
| 23 // | |
| 24 // Core is used like this: | |
| 25 // | |
| 26 // 1. Constructed on owner thread. | |
| 27 // | |
| 28 // 2. Start() is called on owner thread, which calls StartOnTokenServiceThread() | |
| 29 // on token service thread. | |
| 30 // | |
| 31 // 3. ... | |
|
msarda
2014/05/30 14:37:31
Maybe:
s/.../Request is executed.
maniscalco
2014/05/30 17:48:08
Done.
| |
| 32 // | |
| 33 // 4. Stop() is called on owner thread, which calls StopOnTokenServiceThread() | |
| 34 // on token service thread. | |
| 35 // | |
| 36 // 5. Core is destroyed on owner thread. | |
| 37 class OAuth2TokenServiceRequest::Core | |
| 38 : public base::RefCountedThreadSafe<OAuth2TokenServiceRequest::Core> { | |
| 24 public: | 39 public: |
| 25 // Note the thread where an instance of Core is constructed is referred to as | 40 // Note the thread where an instance of Core is constructed is referred to as |
| 26 // the "owner thread" here. This will be the thread of |owner_task_runner_|. | 41 // the "owner thread" here. This will be the thread of |owner_task_runner_|. |
| 27 Core(Profile* profile, | 42 Core(const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, |
| 28 ProfileOAuth2TokenServiceRequest* owner); | 43 OAuth2TokenServiceRequest* owner, |
| 29 // Starts fetching an OAuth2 access token for |account_id| and |scopes|. It | 44 TokenServiceProvider* provider); |
| 30 // should be called on the owner thread. | 45 |
| 31 void Start( | 46 // Starts the core. Must be called on the owner thread. |
| 47 void Start(); | |
| 48 | |
| 49 // Stops the core. Must be called on the owner thread. | |
| 50 void Stop(); | |
| 51 | |
| 52 protected: | |
| 53 // Core must be destroyed on the owner thread. If data members must be | |
| 54 // cleaned up or destroyed on the token service thread, do so in the | |
| 55 // StopOnTokenServiceThread method. | |
| 56 virtual ~Core(); | |
| 57 | |
| 58 // Called on the token service thread. | |
| 59 virtual void StartOnTokenServiceThread() = 0; | |
| 60 | |
| 61 // Called on the token service thread. | |
| 62 virtual void StopOnTokenServiceThread() = 0; | |
| 63 | |
| 64 base::SingleThreadTaskRunner* owner_task_runner(); | |
|
msarda
2014/05/30 14:37:31
It seems that owner_task_runner() is just used to
maniscalco
2014/05/30 17:48:08
Good idea. Done. Core now inherits from NonThrea
| |
| 65 base::SingleThreadTaskRunner* token_service_task_runner(); | |
| 66 OAuth2TokenService* token_service(); | |
| 67 OAuth2TokenServiceRequest* owner(); | |
| 68 | |
| 69 private: | |
| 70 friend class base::RefCountedThreadSafe<OAuth2TokenServiceRequest::Core>; | |
| 71 | |
| 72 scoped_refptr<base::SingleThreadTaskRunner> owner_task_runner_; | |
| 73 scoped_refptr<base::SingleThreadTaskRunner> token_service_task_runner_; | |
| 74 OAuth2TokenServiceRequest* owner_; | |
| 75 TokenServiceProvider* provider_; | |
| 76 DISALLOW_COPY_AND_ASSIGN(Core); | |
| 77 }; | |
| 78 | |
| 79 OAuth2TokenServiceRequest::Core::Core( | |
| 80 const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, | |
|
Roger Tawa OOO till Jul 10th
2014/05/30 15:39:00
|owner_task_runner| does not seem to be used. I t
maniscalco
2014/05/30 17:48:08
Good catch. Parameter removed.
| |
| 81 OAuth2TokenServiceRequest* owner, | |
| 82 TokenServiceProvider* provider) | |
| 83 : owner_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
| 84 owner_(owner), | |
| 85 provider_(provider) { | |
| 86 DCHECK(owner_); | |
| 87 DCHECK(provider_); | |
| 88 token_service_task_runner_ = provider_->GetTokenServiceTaskRunner(); | |
| 89 DCHECK(token_service_task_runner_); | |
| 90 } | |
| 91 | |
| 92 OAuth2TokenServiceRequest::Core::~Core() { | |
| 93 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | |
| 94 } | |
| 95 | |
| 96 void OAuth2TokenServiceRequest::Core::Start() { | |
| 97 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | |
| 98 token_service_task_runner_->PostTask( | |
| 99 FROM_HERE, | |
| 100 base::Bind(&OAuth2TokenServiceRequest::Core::StartOnTokenServiceThread, | |
| 101 this)); | |
| 102 } | |
| 103 | |
| 104 void OAuth2TokenServiceRequest::Core::Stop() { | |
| 105 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | |
| 106 // Detaches |owner_| from this instance so |owner_| will be called back only | |
| 107 // if |Stop()| has never been called. | |
| 108 owner_ = NULL; | |
| 109 token_service_task_runner_->PostTask( | |
| 110 FROM_HERE, | |
| 111 base::Bind(&OAuth2TokenServiceRequest::Core::StopOnTokenServiceThread, | |
| 112 this)); | |
| 113 } | |
| 114 | |
| 115 base::SingleThreadTaskRunner* | |
| 116 OAuth2TokenServiceRequest::Core::owner_task_runner() { | |
| 117 return owner_task_runner_; | |
| 118 } | |
| 119 | |
| 120 base::SingleThreadTaskRunner* | |
| 121 OAuth2TokenServiceRequest::Core::token_service_task_runner() { | |
| 122 return token_service_task_runner_; | |
| 123 } | |
| 124 | |
| 125 OAuth2TokenService* OAuth2TokenServiceRequest::Core::token_service() { | |
| 126 DCHECK(token_service_task_runner_->BelongsToCurrentThread()); | |
| 127 return provider_->GetTokenService(); | |
| 128 } | |
| 129 | |
| 130 OAuth2TokenServiceRequest* OAuth2TokenServiceRequest::Core::owner() { | |
| 131 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | |
| 132 return owner_; | |
| 133 } | |
|
msarda
2014/05/30 14:37:31
I would add a method IsStopped() here and use it b
maniscalco
2014/05/30 17:48:08
Done.
| |
| 134 | |
| 135 namespace { | |
| 136 | |
| 137 // An implementation of Core for getting an access token. | |
| 138 class RequestCore : public OAuth2TokenServiceRequest::Core, | |
| 139 public OAuth2TokenService::Consumer { | |
| 140 public: | |
| 141 RequestCore( | |
| 142 const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, | |
| 143 OAuth2TokenServiceRequest* owner, | |
| 144 OAuth2TokenServiceRequest::TokenServiceProvider* provider, | |
| 145 OAuth2TokenService::Consumer* consumer, | |
| 32 const std::string& account_id, | 146 const std::string& account_id, |
| 33 const OAuth2TokenService::ScopeSet& scopes); | 147 const OAuth2TokenService::ScopeSet& scopes); |
| 34 // Stops the OAuth2 access token fetching. It should be called on the owner | |
| 35 // thread. | |
| 36 void Stop(); | |
| 37 | 148 |
| 38 OAuth2TokenService::Request* request(); | 149 // OAuth2TokenService::Consumer. Must be called on the token service thread. |
| 39 | |
| 40 // OAuth2TokenService::Consumer. It should be called on the UI thread. | |
| 41 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 150 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 42 const std::string& access_token, | 151 const std::string& access_token, |
| 43 const base::Time& expiration_time) OVERRIDE; | 152 const base::Time& expiration_time) OVERRIDE; |
| 44 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 153 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 45 const GoogleServiceAuthError& error) OVERRIDE; | 154 const GoogleServiceAuthError& error) OVERRIDE; |
| 46 | 155 |
| 47 private: | 156 private: |
| 48 friend class | 157 friend class base::RefCountedThreadSafe<RequestCore>; |
| 49 base::RefCountedThreadSafe<ProfileOAuth2TokenServiceRequest::Core>; | 158 |
| 50 | 159 // Must be destroyed on the owner thread. |
| 51 // Note this can be destructed on the owner thread or on the UI thread, | 160 virtual ~RequestCore(); |
| 52 // depending on the reference count. | 161 |
| 53 virtual ~Core(); | 162 // Core implementation. |
| 54 | 163 virtual void StartOnTokenServiceThread() OVERRIDE; |
| 55 // Starts an OAuth2TokenService::Request on the UI thread. | 164 virtual void StopOnTokenServiceThread() OVERRIDE; |
| 56 void StartOnUIThread( | 165 |
| 57 const std::string& account_id, | |
| 58 const OAuth2TokenService::ScopeSet& scopes); | |
| 59 // Stops the OAuth2TokenService::Request on the UI thread. | |
| 60 void StopOnUIThread(); | |
| 61 | |
| 62 // Method posted to the owner thread to call back |owner_|. Note when this | |
| 63 // posted task is actually running on the owner thread, it is possible that | |
| 64 // |owner_| has been reset NULL. | |
| 65 void InformOwnerOnGetTokenSuccess(std::string access_token, | 166 void InformOwnerOnGetTokenSuccess(std::string access_token, |
| 66 base::Time expiration_time); | 167 base::Time expiration_time); |
| 67 void InformOwnerOnGetTokenFailure(GoogleServiceAuthError error); | 168 void InformOwnerOnGetTokenFailure(GoogleServiceAuthError error); |
| 68 | 169 |
| 69 // The profile with which this instance was initialized. | 170 OAuth2TokenService::Consumer* const consumer_; |
|
msarda
2014/05/30 14:37:31
I think we prefer: const OAuth2TokenService::Consu
maniscalco
2014/05/30 17:48:08
In this case, the consumer object itself must be n
| |
| 70 Profile* const profile_; | 171 std::string account_id_; |
| 71 | 172 OAuth2TokenService::ScopeSet scopes_; |
| 72 // The object to call back when fetching completes. |owner_| should be | |
| 73 // called back only on the owner thread. | |
| 74 ProfileOAuth2TokenServiceRequest* owner_; | |
| 75 // Task runner on which |owner_| should be called back. | |
| 76 scoped_refptr<base::SingleThreadTaskRunner> owner_task_runner_; | |
| 77 | 173 |
| 78 // OAuth2TokenService request for fetching OAuth2 access token; it should be | 174 // OAuth2TokenService request for fetching OAuth2 access token; it should be |
| 79 // created, reset and accessed only on the UI thread. | 175 // created, reset and accessed only on the token service thread. |
| 80 scoped_ptr<OAuth2TokenService::Request> request_; | 176 scoped_ptr<OAuth2TokenService::Request> request_; |
| 81 | 177 |
| 82 DISALLOW_COPY_AND_ASSIGN(Core); | 178 DISALLOW_COPY_AND_ASSIGN(RequestCore); |
| 83 }; | 179 }; |
| 84 | 180 |
| 85 ProfileOAuth2TokenServiceRequest::Core::Core( | 181 RequestCore::RequestCore( |
| 86 Profile* profile, | 182 const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, |
| 87 ProfileOAuth2TokenServiceRequest* owner) | 183 OAuth2TokenServiceRequest* owner, |
| 88 : OAuth2TokenService::Consumer("oauth2_token_service"), | 184 OAuth2TokenServiceRequest::TokenServiceProvider* provider, |
| 89 profile_(profile), | 185 OAuth2TokenService::Consumer* consumer, |
| 90 owner_(owner), | 186 const std::string& account_id, |
| 91 owner_task_runner_(base::ThreadTaskRunnerHandle::Get()) { | 187 const OAuth2TokenService::ScopeSet& scopes) |
| 92 DCHECK(profile); | 188 : OAuth2TokenServiceRequest::Core(owner_task_runner, owner, provider), |
| 93 DCHECK(owner); | 189 OAuth2TokenService::Consumer("oauth2_token_service"), |
| 94 } | 190 consumer_(consumer), |
| 95 | 191 account_id_(account_id), |
| 96 ProfileOAuth2TokenServiceRequest::Core::~Core() { | 192 scopes_(scopes) { |
|
msarda
2014/05/30 14:37:31
Roger: I remember there were some problems on Andr
Roger Tawa OOO till Jul 10th
2014/05/30 15:39:00
Adding a DCHECK for empty scopes is a good idea.
maniscalco
2014/05/30 17:48:08
Done. I've added DCHECKs for empty scopes and mad
maniscalco
2014/05/30 17:48:08
Done.
| |
| 97 } | 193 DCHECK(consumer_); |
| 98 | 194 } |
| 99 void ProfileOAuth2TokenServiceRequest::Core::Start( | 195 |
| 100 const std::string& account_id, | 196 RequestCore::~RequestCore() { |
| 101 const OAuth2TokenService::ScopeSet& scopes) { | 197 DCHECK(owner_task_runner()->BelongsToCurrentThread()); |
|
Roger Tawa OOO till Jul 10th
2014/05/30 15:39:00
Already done in base class dtor.
maniscalco
2014/05/30 17:48:08
Removed here and elsewhere.
| |
| 102 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | 198 } |
| 103 | 199 |
| 104 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 200 void RequestCore::StartOnTokenServiceThread() { |
| 105 StartOnUIThread(account_id, scopes); | 201 DCHECK(token_service_task_runner()->BelongsToCurrentThread()); |
| 106 } else { | 202 request_ = token_service()->StartRequest(account_id_, scopes_, this).Pass(); |
| 107 content::BrowserThread::PostTask( | 203 } |
| 108 content::BrowserThread::UI, | 204 |
| 109 FROM_HERE, | 205 void RequestCore::StopOnTokenServiceThread() { |
| 110 base::Bind(&ProfileOAuth2TokenServiceRequest::Core::StartOnUIThread, | 206 DCHECK(token_service_task_runner()->BelongsToCurrentThread()); |
| 111 this, account_id, scopes)); | 207 request_.reset(); |
| 208 } | |
| 209 | |
| 210 void RequestCore::OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
| 211 const std::string& access_token, | |
| 212 const base::Time& expiration_time) { | |
| 213 DCHECK(token_service_task_runner()->BelongsToCurrentThread()); | |
| 214 DCHECK_EQ(request_.get(), request); | |
| 215 owner_task_runner()->PostTask( | |
|
msarda
2014/05/30 14:37:31
There is slight difference with the previous imple
maniscalco
2014/05/30 17:48:08
Yes, I should have pointed that out. I removed th
| |
| 216 FROM_HERE, | |
| 217 base::Bind(&RequestCore::InformOwnerOnGetTokenSuccess, | |
| 218 this, | |
| 219 access_token, | |
| 220 expiration_time)); | |
| 221 request_.reset(); | |
| 222 } | |
| 223 | |
| 224 void RequestCore::OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 225 const GoogleServiceAuthError& error) { | |
| 226 DCHECK(token_service_task_runner()->BelongsToCurrentThread()); | |
| 227 DCHECK_EQ(request_.get(), request); | |
| 228 owner_task_runner()->PostTask( | |
| 229 FROM_HERE, | |
| 230 base::Bind(&RequestCore::InformOwnerOnGetTokenFailure, this, error)); | |
| 231 request_.reset(); | |
| 232 } | |
| 233 | |
| 234 void RequestCore::InformOwnerOnGetTokenSuccess(std::string access_token, | |
| 235 base::Time expiration_time) { | |
| 236 DCHECK(owner_task_runner()->BelongsToCurrentThread()); | |
| 237 if (owner()) { | |
|
msarda
2014/05/30 14:37:31
If you add IsStopped() to Core, then you could use
maniscalco
2014/05/30 17:48:08
Done.
| |
| 238 consumer_->OnGetTokenSuccess(owner(), access_token, expiration_time); | |
| 112 } | 239 } |
| 113 } | 240 } |
| 114 | 241 |
| 115 void ProfileOAuth2TokenServiceRequest::Core::Stop() { | 242 void RequestCore::InformOwnerOnGetTokenFailure(GoogleServiceAuthError error) { |
| 116 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | 243 DCHECK(owner_task_runner()->BelongsToCurrentThread()); |
| 117 | 244 if (owner()) { |
| 118 // Detaches |owner_| from this instance so |owner_| will be called back only | 245 consumer_->OnGetTokenFailure(owner(), error); |
| 119 // if |Stop()| has never been called. | |
| 120 owner_ = NULL; | |
| 121 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
| 122 StopOnUIThread(); | |
| 123 } else { | |
| 124 content::BrowserThread::PostTask( | |
| 125 content::BrowserThread::UI, | |
| 126 FROM_HERE, | |
| 127 base::Bind(&ProfileOAuth2TokenServiceRequest::Core::StopOnUIThread, | |
| 128 this)); | |
| 129 } | 246 } |
| 130 } | 247 } |
| 131 | 248 |
| 132 OAuth2TokenService::Request* ProfileOAuth2TokenServiceRequest::Core::request() { | 249 // An implementation of Core for invalidating an access token. |
| 133 return request_.get(); | 250 class InvalidateCore : public OAuth2TokenServiceRequest::Core { |
| 134 } | 251 public: |
| 135 | 252 InvalidateCore( |
| 136 void ProfileOAuth2TokenServiceRequest::Core::StopOnUIThread() { | 253 const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, |
| 137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 254 OAuth2TokenServiceRequest* owner, |
| 138 request_.reset(); | 255 OAuth2TokenServiceRequest::TokenServiceProvider* provider, |
| 139 } | 256 const std::string& access_token, |
| 140 | 257 const std::string& account_id, |
| 141 void ProfileOAuth2TokenServiceRequest::Core::StartOnUIThread( | 258 const OAuth2TokenService::ScopeSet& scopes); |
| 142 const std::string& account_id, | 259 |
| 143 const OAuth2TokenService::ScopeSet& scopes) { | 260 private: |
| 144 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 261 friend class base::RefCountedThreadSafe<InvalidateCore>; |
| 145 | 262 |
| 146 ProfileOAuth2TokenService* service = | 263 // Must be destroyed on the owner thread. |
| 147 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 264 virtual ~InvalidateCore(); |
| 148 DCHECK(service); | 265 |
| 149 SigninManagerBase* signin_manager = | 266 // Core implementation. |
| 150 SigninManagerFactory::GetForProfile(profile_); | 267 virtual void StartOnTokenServiceThread() OVERRIDE; |
| 151 DCHECK(signin_manager); | 268 virtual void StopOnTokenServiceThread() OVERRIDE; |
| 152 std::string account_id_to_use = | 269 |
| 153 account_id.empty() ? signin_manager->GetAuthenticatedAccountId() | 270 std::string access_token_; |
| 154 : account_id; | 271 std::string account_id_; |
| 155 request_.reset( | 272 OAuth2TokenService::ScopeSet scopes_; |
| 156 service->StartRequest(account_id_to_use, scopes, this).release()); | 273 |
| 157 } | 274 DISALLOW_COPY_AND_ASSIGN(InvalidateCore); |
| 158 | 275 }; |
| 159 void ProfileOAuth2TokenServiceRequest::Core::OnGetTokenSuccess( | 276 |
| 160 const OAuth2TokenService::Request* request, | 277 InvalidateCore::InvalidateCore( |
| 278 const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, | |
| 279 OAuth2TokenServiceRequest* owner, | |
| 280 OAuth2TokenServiceRequest::TokenServiceProvider* provider, | |
| 161 const std::string& access_token, | 281 const std::string& access_token, |
| 162 const base::Time& expiration_time) { | 282 const std::string& account_id, |
| 163 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 283 const OAuth2TokenService::ScopeSet& scopes) |
| 164 DCHECK_EQ(request_.get(), request); | 284 : OAuth2TokenServiceRequest::Core(owner_task_runner, owner, provider), |
| 165 owner_task_runner_->PostTask(FROM_HERE, base::Bind( | 285 access_token_(access_token), |
| 166 &ProfileOAuth2TokenServiceRequest::Core::InformOwnerOnGetTokenSuccess, | 286 account_id_(account_id), |
| 167 this, | 287 scopes_(scopes) { |
| 168 access_token, | 288 DCHECK(!access_token.empty()); |
| 169 expiration_time)); | 289 DCHECK(!account_id.empty()); |
| 170 request_.reset(); | 290 } |
| 171 } | 291 |
| 172 | 292 InvalidateCore::~InvalidateCore() { |
| 173 void ProfileOAuth2TokenServiceRequest::Core::OnGetTokenFailure( | 293 DCHECK(owner_task_runner()->BelongsToCurrentThread()); |
|
Roger Tawa OOO till Jul 10th
2014/05/30 15:39:00
Already done in base class dtor.
maniscalco
2014/05/30 17:48:08
Removed.
| |
| 174 const OAuth2TokenService::Request* request, | 294 } |
| 175 const GoogleServiceAuthError& error) { | 295 |
| 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 296 void InvalidateCore::StartOnTokenServiceThread() { |
| 177 DCHECK_EQ(request_.get(), request); | 297 DCHECK(token_service_task_runner()->BelongsToCurrentThread()); |
| 178 owner_task_runner_->PostTask(FROM_HERE, base::Bind( | 298 token_service()->InvalidateToken(account_id_, scopes_, access_token_); |
| 179 &ProfileOAuth2TokenServiceRequest::Core::InformOwnerOnGetTokenFailure, | 299 } |
| 180 this, | 300 |
| 181 error)); | 301 void InvalidateCore::StopOnTokenServiceThread() { |
| 182 request_.reset(); | 302 DCHECK(token_service_task_runner()->BelongsToCurrentThread()); |
| 183 } | 303 // Nothing to do. |
| 184 | 304 } |
| 185 void ProfileOAuth2TokenServiceRequest::Core::InformOwnerOnGetTokenSuccess( | 305 |
| 186 std::string access_token, | 306 } // namespace |
| 187 base::Time expiration_time) { | |
| 188 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | |
| 189 | |
| 190 if (owner_) | |
| 191 owner_->consumer_->OnGetTokenSuccess(owner_, access_token, expiration_time); | |
| 192 } | |
| 193 | |
| 194 void ProfileOAuth2TokenServiceRequest::Core::InformOwnerOnGetTokenFailure( | |
| 195 GoogleServiceAuthError error) { | |
| 196 DCHECK(owner_task_runner_->BelongsToCurrentThread()); | |
| 197 | |
| 198 if (owner_) | |
| 199 owner_->consumer_->OnGetTokenFailure(owner_, error); | |
| 200 } | |
| 201 | 307 |
| 202 // static | 308 // static |
| 203 ProfileOAuth2TokenServiceRequest* | 309 OAuth2TokenServiceRequest* OAuth2TokenServiceRequest::CreateAndStart( |
| 204 ProfileOAuth2TokenServiceRequest::CreateAndStart( | 310 TokenServiceProvider* provider, |
| 205 Profile* profile, | |
| 206 const std::string& account_id, | |
| 207 const OAuth2TokenService::ScopeSet& scopes, | |
| 208 OAuth2TokenService::Consumer* consumer) { | |
| 209 return new ProfileOAuth2TokenServiceRequest(profile, account_id, scopes, | |
| 210 consumer); | |
| 211 } | |
| 212 | |
| 213 ProfileOAuth2TokenServiceRequest::ProfileOAuth2TokenServiceRequest( | |
| 214 Profile* profile, | |
| 215 const std::string& account_id, | 311 const std::string& account_id, |
| 216 const OAuth2TokenService::ScopeSet& scopes, | 312 const OAuth2TokenService::ScopeSet& scopes, |
| 217 OAuth2TokenService::Consumer* consumer) | 313 OAuth2TokenService::Consumer* consumer) { |
| 218 : consumer_(consumer), | 314 DCHECK(provider); |
| 219 core_(new Core(profile, this)) { | 315 DCHECK(!account_id.empty()); |
| 220 core_->Start(account_id, scopes); | 316 DCHECK(consumer); |
| 221 } | 317 return new OAuth2TokenServiceRequest(base::ThreadTaskRunnerHandle::Get(), |
| 222 | 318 provider, |
| 223 ProfileOAuth2TokenServiceRequest::~ProfileOAuth2TokenServiceRequest() { | 319 consumer, |
| 320 account_id, | |
| 321 scopes); | |
| 322 } | |
| 323 | |
| 324 OAuth2TokenServiceRequest::OAuth2TokenServiceRequest( | |
|
msarda
2014/05/30 14:37:31
Constructors / destructor are at the top of the cl
maniscalco
2014/05/30 17:48:08
Done. I've reordered the method definitions to ma
| |
| 325 const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, | |
| 326 OAuth2TokenServiceRequest::TokenServiceProvider* provider, | |
| 327 OAuth2TokenService::Consumer* consumer, | |
| 328 const std::string& account_id, | |
| 329 const OAuth2TokenService::ScopeSet& scopes) | |
| 330 : account_id_(account_id), | |
| 331 core_(new RequestCore(owner_task_runner, | |
|
msarda
2014/05/30 14:37:31
The two constructors take very similar arguments,
maniscalco
2014/05/30 17:48:08
Done. OA2TSR now has just one ctor that takes a C
| |
| 332 this, | |
| 333 provider, | |
| 334 consumer, | |
| 335 account_id, | |
| 336 scopes)) { | |
| 337 DCHECK(!account_id.empty()); | |
| 338 core_->Start(); | |
| 339 } | |
| 340 | |
| 341 // static | |
| 342 OAuth2TokenServiceRequest* OAuth2TokenServiceRequest::CreateAndStartInvalidate( | |
| 343 OAuth2TokenServiceRequest::TokenServiceProvider* provider, | |
| 344 const std::string& account_id, | |
| 345 const OAuth2TokenService::ScopeSet& scopes, | |
| 346 const std::string& access_token) { | |
| 347 DCHECK(provider); | |
| 348 DCHECK(!account_id.empty()); | |
| 349 DCHECK(!access_token.empty()); | |
| 350 return new OAuth2TokenServiceRequest(base::ThreadTaskRunnerHandle::Get(), | |
| 351 provider, | |
| 352 access_token, | |
| 353 account_id, | |
| 354 scopes); | |
| 355 } | |
| 356 | |
| 357 OAuth2TokenServiceRequest::OAuth2TokenServiceRequest( | |
| 358 const scoped_refptr<base::SingleThreadTaskRunner>& owner_task_runner, | |
| 359 OAuth2TokenServiceRequest::TokenServiceProvider* provider, | |
| 360 const std::string& access_token, | |
| 361 const std::string& account_id, | |
| 362 const OAuth2TokenService::ScopeSet& scopes) | |
| 363 : account_id_(account_id), | |
| 364 core_(new InvalidateCore(owner_task_runner, | |
| 365 this, | |
| 366 provider, | |
| 367 access_token, | |
| 368 account_id, | |
| 369 scopes)) { | |
| 370 DCHECK(!account_id.empty()); | |
| 371 core_->Start(); | |
| 372 } | |
| 373 | |
| 374 OAuth2TokenServiceRequest::~OAuth2TokenServiceRequest() { | |
| 224 DCHECK(CalledOnValidThread()); | 375 DCHECK(CalledOnValidThread()); |
| 225 core_->Stop(); | 376 core_->Stop(); |
| 226 } | 377 } |
| 227 | 378 |
| 228 std::string ProfileOAuth2TokenServiceRequest::GetAccountId() const { | 379 std::string OAuth2TokenServiceRequest::GetAccountId() const { |
| 229 return core_->request()->GetAccountId(); | 380 return account_id_; |
| 230 } | 381 } |
| 231 | |
| OLD | NEW |