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

Side by Side Diff: chrome/browser/signin/profile_oauth2_token_service_request.h

Issue 299943003: Refactor ProfileOAuth2TokenServiceRequest into OAuth2TokenServiceRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow ProfileOAuth2TokenServiceRequestTest to free UI thread resources. Created 6 years, 7 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
OLDNEW
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 #ifndef CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ 5 #ifndef CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_
6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ 6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/threading/non_thread_safe.h" 11 #include "base/threading/non_thread_safe.h"
12 #include "google_apis/gaia/oauth2_token_service.h" 12 #include "google_apis/gaia/oauth2_token_service.h"
13 #include "google_apis/gaia/oauth2_token_service_proxy.h"
13 14
14 class Profile; 15 class Profile;
15 16
16 // ProfileOAuth2TokenServiceRequest represents a request to fetch an 17 // ProfileOAuth2TokenServiceRequest represents a request to fetch an
17 // OAuth2 access token for a given set of |scopes| by calling |profile|'s 18 // OAuth2 access token for a given set of |scopes| by calling |profile|'s
18 // ProfileOAuth2TokenService. A request can be created and started from 19 // ProfileOAuth2TokenService. A request can be created and started from
19 // any thread with an object |consumer| that will be called back on the 20 // 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 // same thread when fetching completes. If the request is destructed
21 // before |consumer| is called, |consumer| will never be called back. (Note 22 // before |consumer| is called, |consumer| will never be called back. (Note
22 // the actual network activities are not canceled and the cache in 23 // the actual network activities are not canceled and the cache in
23 // ProfileOAuth2TokenService will be populated with the fetched results.) 24 // ProfileOAuth2TokenService will be populated with the fetched results.)
24 class ProfileOAuth2TokenServiceRequest : public OAuth2TokenService::Request, 25 class ProfileOAuth2TokenServiceRequest : public OAuth2TokenService::Request,
25 public base::NonThreadSafe { 26 public base::NonThreadSafe {
26 public: 27 public:
27 // Creates and starts a request for |account_id| and |scopes|. 28 // 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( 29 static ProfileOAuth2TokenServiceRequest* CreateAndStart(
30 Profile* profile, 30 Profile* profile,
31 const std::string& account_id, 31 const std::string& account_id,
32 const OAuth2TokenService::ScopeSet& scopes, 32 const OAuth2TokenService::ScopeSet& scopes,
33 OAuth2TokenService::Consumer* consumer); 33 OAuth2TokenService::Consumer* consumer);
34 34
35 virtual ~ProfileOAuth2TokenServiceRequest(); 35 virtual ~ProfileOAuth2TokenServiceRequest();
36 36
37 // Overridden from Request: 37 // Overridden from Request:
38 virtual std::string GetAccountId() const OVERRIDE; 38 virtual std::string GetAccountId() const OVERRIDE;
39 39
40 private: 40 private:
41 class Core; 41 typedef base::Callback<void(OAuth2TokenService*)> GetTokenServiceCallback;
42 friend class Core;
43 42
44 ProfileOAuth2TokenServiceRequest(Profile* profile, 43 ProfileOAuth2TokenServiceRequest(Profile* profile,
45 const std::string& account_id, 44 const std::string& account_id,
46 const OAuth2TokenService::ScopeSet& scopes, 45 const OAuth2TokenService::ScopeSet& scopes,
47 OAuth2TokenService::Consumer* consumer); 46 OAuth2TokenService::Consumer* consumer);
48 47
48 // Retrieve |profile|'s OAuth2TokenService and task runner. Pass them to
49 // |callback| in the |callers_task_runner| thread.
50 static void GetTokenService(
51 Profile* profile,
52 const scoped_refptr<base::SequencedTaskRunner>& callers_task_runner,
53 const GetTokenServiceCallback& callback);
54
55 void ContinueWithTokenService(OAuth2TokenService* token_service);
56
57 // Invoked when the request has completed.
58 void RequestTokenDone(const GoogleServiceAuthError& error,
59 const std::string& access_token,
60 const base::Time& expiration_time);
61
62 std::string account_id_;
63 OAuth2TokenService::ScopeSet scopes_;
49 OAuth2TokenService::Consumer* const consumer_; 64 OAuth2TokenService::Consumer* const consumer_;
50 scoped_refptr<Core> core_; 65 scoped_ptr<OAuth2TokenServiceProxy> proxy_;
66
67 // Must be last data member.
68 base::WeakPtrFactory<ProfileOAuth2TokenServiceRequest> weak_ptr_factory_;
51 69
52 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceRequest); 70 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceRequest);
53 }; 71 };
54 72
55 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ 73 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698