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

Side by Side Diff: chrome/browser/signin/fake_profile_oauth2_token_service.cc

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 4 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
(Empty)
1 // Copyright 2013 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.
4
5 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
6
7 FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() {
8 }
9
10 FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() {
11 }
12
13 // static
14 BrowserContextKeyedService* FakeProfileOAuth2TokenService::Build(
15 content::BrowserContext* profile) {
16 return new FakeProfileOAuth2TokenService();
17 }
18
19 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() {
20 }
21
22 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() {
23 }
24
25 void FakeProfileOAuth2TokenService::Shutdown() {
26 // Do not call the base class handler because it assumes that Initialize()
27 // is always called before Shutdown() and that's not the case for this mock.
28 }
29
30 void FakeProfileOAuth2TokenService::IssueRefreshToken(
31 const std::string& token) {
32 refresh_token_ = token;
33 if (refresh_token_.empty())
34 FireRefreshTokenRevoked("account_id");
35 else
36 FireRefreshTokenAvailable("account_id");
37 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
38 }
39
40 void FakeProfileOAuth2TokenService::IssueTokenForScope(
41 const ScopeSet& scope,
42 const std::string& access_token,
43 const base::Time& expiration) {
44 CompleteRequests(false,
45 scope,
46 GoogleServiceAuthError::AuthErrorNone(),
47 access_token,
48 expiration);
49 }
50
51 void FakeProfileOAuth2TokenService::IssueErrorForScope(
52 const ScopeSet& scope,
53 const GoogleServiceAuthError& error) {
54 CompleteRequests(false, scope, error, std::string(), base::Time());
55 }
56
57 void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequests(
58 const GoogleServiceAuthError& error) {
59 CompleteRequests(true, ScopeSet(), error, std::string(), base::Time());
60 }
61
62 void FakeProfileOAuth2TokenService::IssueTokenForAllPendingRequests(
63 const std::string& access_token,
64 const base::Time& expiration) {
65 CompleteRequests(true,
66 ScopeSet(),
67 GoogleServiceAuthError::AuthErrorNone(),
68 access_token,
69 expiration);
70 }
71
72 void FakeProfileOAuth2TokenService::CompleteRequests(
73 bool all_scopes,
74 const ScopeSet& scope,
75 const GoogleServiceAuthError& error,
76 const std::string& access_token,
77 const base::Time& expiration) {
78 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests =
79 GetPendingRequests();
80 // Walk the requests and notify the callbacks.
81 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
82 it != pending_requests_.end(); ++it) {
83 if (it->request && (all_scopes || it->scopes == scope))
84 it->request->InformConsumer(error, access_token, expiration);
85 }
86 }
87
88 std::string FakeProfileOAuth2TokenService::GetRefreshToken() {
89 return refresh_token_;
90 }
91
92 net::URLRequestContextGetter*
93 FakeProfileOAuth2TokenService::GetRequestContext() {
94 return NULL;
95 }
96
97 std::vector<FakeProfileOAuth2TokenService::PendingRequest>
98 FakeProfileOAuth2TokenService::GetPendingRequests() {
99 std::vector<PendingRequest> valid_requests;
100 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
101 it != pending_requests_.end(); ++it) {
102 if (it->request)
103 valid_requests.push_back(*it);
104 }
105 return valid_requests;
106 }
107
108 void FakeProfileOAuth2TokenService::FetchOAuth2Token(
109 RequestImpl* request,
110 net::URLRequestContextGetter* getter,
111 const std::string& client_id,
112 const std::string& client_secret,
113 const ScopeSet& scopes) {
114 PendingRequest pending_request;
115 pending_request.client_id = client_id;
116 pending_request.client_secret = client_secret;
117 pending_request.scopes = scopes;
118 pending_request.request = request->AsWeakPtr();
119 pending_requests_.push_back(pending_request);
120 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/fake_profile_oauth2_token_service.h ('k') | chrome/browser/signin/oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698