| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "google_apis/gaia/fake_oauth2_token_service.h" | 5 #include "google_apis/gaia/fake_oauth2_token_service.h" |
| 6 | 6 |
| 7 FakeOAuth2TokenService::PendingRequest::PendingRequest() { | 7 FakeOAuth2TokenService::PendingRequest::PendingRequest() { |
| 8 } | 8 } |
| 9 | 9 |
| 10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() { | 10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() { |
| 11 } | 11 } |
| 12 | 12 |
| 13 FakeOAuth2TokenService::FakeOAuth2TokenService() : request_context_(NULL) { | 13 FakeOAuth2TokenService::FakeOAuth2TokenService() |
| 14 : OAuth2TokenService(new FakeOAuth2TokenServiceDelegate(nullptr)) { |
| 14 } | 15 } |
| 15 | 16 |
| 16 FakeOAuth2TokenService::~FakeOAuth2TokenService() { | 17 FakeOAuth2TokenService::~FakeOAuth2TokenService() { |
| 17 } | 18 } |
| 18 | 19 |
| 19 std::vector<std::string> FakeOAuth2TokenService::GetAccounts() { | |
| 20 return std::vector<std::string>(account_ids_.begin(), account_ids_.end()); | |
| 21 } | |
| 22 | |
| 23 void FakeOAuth2TokenService::FetchOAuth2Token( | 20 void FakeOAuth2TokenService::FetchOAuth2Token( |
| 24 RequestImpl* request, | 21 RequestImpl* request, |
| 25 const std::string& account_id, | 22 const std::string& account_id, |
| 26 net::URLRequestContextGetter* getter, | 23 net::URLRequestContextGetter* getter, |
| 27 const std::string& client_id, | 24 const std::string& client_id, |
| 28 const std::string& client_secret, | 25 const std::string& client_secret, |
| 29 const ScopeSet& scopes) { | 26 const ScopeSet& scopes) { |
| 30 PendingRequest pending_request; | 27 PendingRequest pending_request; |
| 31 pending_request.account_id = account_id; | 28 pending_request.account_id = account_id; |
| 32 pending_request.client_id = client_id; | 29 pending_request.client_id = client_id; |
| 33 pending_request.client_secret = client_secret; | 30 pending_request.client_secret = client_secret; |
| 34 pending_request.scopes = scopes; | 31 pending_request.scopes = scopes; |
| 35 pending_request.request = request->AsWeakPtr(); | 32 pending_request.request = request->AsWeakPtr(); |
| 36 pending_requests_.push_back(pending_request); | 33 pending_requests_.push_back(pending_request); |
| 37 } | 34 } |
| 38 | 35 |
| 39 void FakeOAuth2TokenService::InvalidateOAuth2Token( | 36 void FakeOAuth2TokenService::InvalidateAccessTokenImpl( |
| 40 const std::string& account_id, | 37 const std::string& account_id, |
| 41 const std::string& client_id, | 38 const std::string& client_id, |
| 42 const ScopeSet& scopes, | 39 const ScopeSet& scopes, |
| 43 const std::string& access_token) { | 40 const std::string& access_token) { |
| 44 } | 41 } |
| 45 | 42 |
| 46 net::URLRequestContextGetter* FakeOAuth2TokenService::GetRequestContext() { | |
| 47 return request_context_; | |
| 48 } | |
| 49 | |
| 50 bool FakeOAuth2TokenService::RefreshTokenIsAvailable( | |
| 51 const std::string& account_id) const { | |
| 52 return account_ids_.count(account_id) != 0; | |
| 53 }; | |
| 54 | |
| 55 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) { | |
| 56 account_ids_.insert(account_id); | |
| 57 FireRefreshTokenAvailable(account_id); | |
| 58 } | |
| 59 | |
| 60 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) { | |
| 61 account_ids_.erase(account_id); | |
| 62 FireRefreshTokenRevoked(account_id); | |
| 63 } | |
| 64 | |
| 65 void FakeOAuth2TokenService::IssueAllTokensForAccount( | 43 void FakeOAuth2TokenService::IssueAllTokensForAccount( |
| 66 const std::string& account_id, | 44 const std::string& account_id, |
| 67 const std::string& access_token, | 45 const std::string& access_token, |
| 68 const base::Time& expiration) { | 46 const base::Time& expiration) { |
| 69 // Walk the requests and notify the callbacks. | 47 // Walk the requests and notify the callbacks. |
| 70 // Using a copy of pending requests to make sure a new token request triggered | 48 // Using a copy of pending requests to make sure a new token request triggered |
| 71 // from the handling code does not invalidate the iterator. | 49 // from the handling code does not invalidate the iterator. |
| 72 std::vector<PendingRequest> pending_requests_copy = pending_requests_; | 50 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
| 73 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); | 51 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); |
| 74 it != pending_requests_copy.end(); | 52 it != pending_requests_copy.end(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 std::vector<PendingRequest> pending_requests_copy = pending_requests_; | 67 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
| 90 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); | 68 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); |
| 91 it != pending_requests_copy.end(); | 69 it != pending_requests_copy.end(); |
| 92 ++it) { | 70 ++it) { |
| 93 if (it->request && (account_id == it->account_id)) { | 71 if (it->request && (account_id == it->account_id)) { |
| 94 it->request->InformConsumer(auth_error, std::string(), base::Time()); | 72 it->request->InformConsumer(auth_error, std::string(), base::Time()); |
| 95 } | 73 } |
| 96 } | 74 } |
| 97 } | 75 } |
| 98 | 76 |
| 99 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( | 77 FakeOAuth2TokenServiceDelegate* |
| 100 const std::string& account_id, | 78 FakeOAuth2TokenService::GetFakeOAuth2TokenServiceDelegate() { |
| 101 net::URLRequestContextGetter* getter, | 79 return static_cast<FakeOAuth2TokenServiceDelegate*>(GetDelegate()); |
| 102 OAuth2AccessTokenConsumer* consumer) { | |
| 103 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus | |
| 104 // |CreateAccessTokenFetcher| should never be called. | |
| 105 NOTREACHED(); | |
| 106 return NULL; | |
| 107 } | 80 } |
| OLD | NEW |