Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / google_apis / gaia / fake_oauth2_token_service_delegate.cc
blob580025ceeb07fa2b98aacc4c502be42177bae27b
1 // Copyright 2015 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.
5 #include "google_apis/gaia/fake_oauth2_token_service_delegate.h"
6 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
8 FakeOAuth2TokenServiceDelegate::FakeOAuth2TokenServiceDelegate(
9 net::URLRequestContextGetter* request_context)
10 : request_context_(request_context) {
13 FakeOAuth2TokenServiceDelegate::~FakeOAuth2TokenServiceDelegate() {
16 OAuth2AccessTokenFetcher*
17 FakeOAuth2TokenServiceDelegate::CreateAccessTokenFetcher(
18 const std::string& account_id,
19 net::URLRequestContextGetter* getter,
20 OAuth2AccessTokenConsumer* consumer) {
21 std::map<std::string, std::string>::const_iterator it =
22 refresh_tokens_.find(account_id);
23 DCHECK(it != refresh_tokens_.end());
24 std::string refresh_token(it->second);
25 return new OAuth2AccessTokenFetcherImpl(consumer, getter, refresh_token);
28 bool FakeOAuth2TokenServiceDelegate::RefreshTokenIsAvailable(
29 const std::string& account_id) const {
30 return !GetRefreshToken(account_id).empty();
33 std::string FakeOAuth2TokenServiceDelegate::GetRefreshToken(
34 const std::string& account_id) const {
35 std::map<std::string, std::string>::const_iterator it =
36 refresh_tokens_.find(account_id);
37 if (it != refresh_tokens_.end())
38 return it->second;
39 return std::string();
42 std::vector<std::string> FakeOAuth2TokenServiceDelegate::GetAccounts() {
43 std::vector<std::string> account_ids;
44 for (std::map<std::string, std::string>::const_iterator iter =
45 refresh_tokens_.begin();
46 iter != refresh_tokens_.end(); ++iter) {
47 account_ids.push_back(iter->first);
49 return account_ids;
52 void FakeOAuth2TokenServiceDelegate::RevokeAllCredentials() {
53 std::vector<std::string> account_ids = GetAccounts();
54 for (std::vector<std::string>::const_iterator it = account_ids.begin();
55 it != account_ids.end(); it++) {
56 RevokeCredentials(*it);
60 void FakeOAuth2TokenServiceDelegate::LoadCredentials(
61 const std::string& primary_account_id) {
62 FireRefreshTokensLoaded();
65 void FakeOAuth2TokenServiceDelegate::UpdateCredentials(
66 const std::string& account_id,
67 const std::string& refresh_token) {
68 IssueRefreshTokenForUser(account_id, refresh_token);
71 void FakeOAuth2TokenServiceDelegate::IssueRefreshTokenForUser(
72 const std::string& account_id,
73 const std::string& token) {
74 ScopedBatchChange batch(this);
75 if (token.empty()) {
76 refresh_tokens_.erase(account_id);
77 FireRefreshTokenRevoked(account_id);
78 } else {
79 refresh_tokens_[account_id] = token;
80 FireRefreshTokenAvailable(account_id);
81 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
85 void FakeOAuth2TokenServiceDelegate::RevokeCredentials(
86 const std::string& account_id) {
87 IssueRefreshTokenForUser(account_id, std::string());
90 net::URLRequestContextGetter*
91 FakeOAuth2TokenServiceDelegate::GetRequestContext() const {
92 return request_context_.get();