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

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: Android fixes. 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 GoogleServiceAuthError::AuthErrorNone());
36 } else {
37 FireRefreshTokenAvailable("account_id");
38 }
39 }
40
41 void FakeProfileOAuth2TokenService::IssueTokenForScope(
42 const ScopeSet& scope,
43 const std::string& access_token,
44 const base::Time& expiration) {
45 CompleteRequests(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(scope, error, std::string(), base::Time());
55 }
56
57 void FakeProfileOAuth2TokenService::CompleteRequests(
58 const ScopeSet& scope,
59 const GoogleServiceAuthError& error,
60 const std::string& access_token,
61 const base::Time& expiration) {
62 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests =
63 GetPendingRequests();
64 // Walk the requests and notify the callbacks.
65 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
66 it != pending_requests_.end(); ++it) {
67 if (it->request && it->scopes == scope)
68 it->request->InformConsumer(error, access_token, expiration);
69 }
70 }
71
72 std::string FakeProfileOAuth2TokenService::GetRefreshToken() {
73 return refresh_token_;
74 }
75
76 net::URLRequestContextGetter*
77 FakeProfileOAuth2TokenService::GetRequestContext() {
78 return NULL;
79 }
80
81 std::vector<FakeProfileOAuth2TokenService::PendingRequest>
82 FakeProfileOAuth2TokenService::GetPendingRequests() {
83 std::vector<PendingRequest> valid_requests;
84 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
85 it != pending_requests_.end(); ++it) {
86 if (it->request)
87 valid_requests.push_back(*it);
88 }
89 return valid_requests;
90 }
91
92 void FakeProfileOAuth2TokenService::FetchOAuth2Token(
93 RequestImpl* request,
94 net::URLRequestContextGetter* getter,
95 const std::string& client_id,
96 const std::string& client_secret,
97 const ScopeSet& scopes) {
98 PendingRequest pending_request;
99 pending_request.client_id = client_id;
100 pending_request.client_secret = client_secret;
101 pending_request.scopes = scopes;
102 pending_request.request = request->AsWeakPtr();
103 pending_requests_.push_back(pending_request);
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698