OLD | NEW |
---|---|
(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 } | |
38 | |
39 void FakeProfileOAuth2TokenService::IssueTokenForScope( | |
40 const ScopeSet& scope, | |
41 const std::string& access_token, | |
42 const base::Time& expiration) { | |
43 CompleteRequests(false, | |
44 scope, | |
45 GoogleServiceAuthError::AuthErrorNone(), | |
46 access_token, | |
47 expiration); | |
48 } | |
49 | |
50 void FakeProfileOAuth2TokenService::IssueErrorForScope( | |
51 const ScopeSet& scope, | |
52 const GoogleServiceAuthError& error) { | |
53 CompleteRequests(false, scope, error, std::string(), base::Time()); | |
54 } | |
55 | |
56 void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequests( | |
57 const GoogleServiceAuthError& error) { | |
58 CompleteRequests(true, ScopeSet(), error, std::string(), base::Time()); | |
59 } | |
60 | |
61 void FakeProfileOAuth2TokenService::IssueTokenForAllPendingRequests( | |
62 const std::string& access_token, | |
63 const base::Time& expiration) { | |
64 CompleteRequests(true, | |
65 ScopeSet(), | |
66 GoogleServiceAuthError::AuthErrorNone(), | |
67 access_token, | |
68 expiration); | |
69 } | |
70 | |
71 void FakeProfileOAuth2TokenService::CompleteRequests( | |
72 bool all_scopes, | |
73 const ScopeSet& scope, | |
74 const GoogleServiceAuthError& error, | |
75 const std::string& access_token, | |
76 const base::Time& expiration) { | |
77 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests = | |
78 GetPendingRequests(); | |
79 // Walk the requests and notify the callbacks. | |
80 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | |
81 it != pending_requests_.end(); ++it) { | |
82 if (it->request && (all_scopes || it->scopes == scope)) | |
83 it->request->InformConsumer(error, access_token, expiration); | |
84 } | |
85 } | |
86 | |
87 std::string FakeProfileOAuth2TokenService::GetRefreshToken() { | |
88 return refresh_token_; | |
89 } | |
90 | |
91 net::URLRequestContextGetter* | |
92 FakeProfileOAuth2TokenService::GetRequestContext() { | |
93 return NULL; | |
94 } | |
95 | |
96 std::vector<FakeProfileOAuth2TokenService::PendingRequest> | |
97 FakeProfileOAuth2TokenService::GetPendingRequests() { | |
98 std::vector<PendingRequest> valid_requests; | |
99 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | |
100 it != pending_requests_.end(); ++it) { | |
101 if (it->request) | |
102 valid_requests.push_back(*it); | |
103 } | |
104 return valid_requests; | |
105 } | |
106 | |
107 void FakeProfileOAuth2TokenService::FetchOAuth2Token( | |
108 RequestImpl* request, | |
109 net::URLRequestContextGetter* getter, | |
110 const std::string& client_id, | |
111 const std::string& client_secret, | |
112 const ScopeSet& scopes) { | |
113 PendingRequest pending_request; | |
114 pending_request.client_id = client_id; | |
115 pending_request.client_secret = client_secret; | |
116 pending_request.scopes = scopes; | |
117 pending_request.request = request->AsWeakPtr(); | |
118 pending_requests_.push_back(pending_request); | |
Mattias Nissler (ping if slow)
2013/08/19 14:03:22
I don't see any place in the code where elements g
Andrew T Wilson (Slow)
2013/08/20 09:28:35
It's intentional - what we have is good enough for
| |
119 } | |
OLD | NEW |