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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_
6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_
11 #include "base/threading/non_thread_safe.h"
12 #include "google_apis/gaia/oauth2_token_service.h"
16 // ProfileOAuth2TokenServiceRequest represents a request to fetch an
17 // OAuth2 access token for a given set of |scopes| by calling |profile|'s
18 // ProfileOAuth2TokenService. A request can be created and started from
19 // any thread with an object |consumer| that will be called back on the
20 // same thread when fetching completes. If the request is destructed
21 // before |consumer| is called, |consumer| will never be called back. (Note
22 // the actual network activities are not canceled and the cache in
23 // ProfileOAuth2TokenService will be populated with the fetched results.)
24 class ProfileOAuth2TokenServiceRequest
: public OAuth2TokenService::Request
,
25 public base::NonThreadSafe
{
27 // Creates and starts a request for |account_id| and |scopes|.
28 // Uses the primary account id if |account_id| is the empty string.
29 static ProfileOAuth2TokenServiceRequest
* CreateAndStart(
31 const std::string
& account_id
,
32 const OAuth2TokenService::ScopeSet
& scopes
,
33 OAuth2TokenService::Consumer
* consumer
);
35 virtual ~ProfileOAuth2TokenServiceRequest();
37 // Overridden from Request:
38 virtual std::string
GetAccountId() const OVERRIDE
;
44 ProfileOAuth2TokenServiceRequest(Profile
* profile
,
45 const std::string
& account_id
,
46 const OAuth2TokenService::ScopeSet
& scopes
,
47 OAuth2TokenService::Consumer
* consumer
);
49 OAuth2TokenService::Consumer
* const consumer_
;
50 scoped_refptr
<Core
> core_
;
52 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceRequest
);
55 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_