| Index: chrome/browser/signin/fake_profile_oauth2_token_service.cc
|
| diff --git a/chrome/browser/signin/fake_profile_oauth2_token_service.cc b/chrome/browser/signin/fake_profile_oauth2_token_service.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1e3af60e4112f473e333b111a3d1749f0e5fa6c2
|
| --- /dev/null
|
| +++ b/chrome/browser/signin/fake_profile_oauth2_token_service.cc
|
| @@ -0,0 +1,104 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
|
| +
|
| +FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() {
|
| +}
|
| +
|
| +FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() {
|
| +}
|
| +
|
| +// static
|
| +BrowserContextKeyedService* FakeProfileOAuth2TokenService::Build(
|
| + content::BrowserContext* profile) {
|
| + return new FakeProfileOAuth2TokenService();
|
| +}
|
| +
|
| +FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() {
|
| +}
|
| +
|
| +FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() {
|
| +}
|
| +
|
| +void FakeProfileOAuth2TokenService::Shutdown() {
|
| + // Do not call the base class handler because it assumes that Initialize()
|
| + // is always called before Shutdown() and that's not the case for this mock.
|
| +}
|
| +
|
| +void FakeProfileOAuth2TokenService::IssueRefreshToken(
|
| + const std::string& token) {
|
| + refresh_token_ = token;
|
| + if (refresh_token_.empty()) {
|
| + FireRefreshTokenRevoked("account_id",
|
| + GoogleServiceAuthError::AuthErrorNone());
|
| + } else {
|
| + FireRefreshTokenAvailable("account_id");
|
| + }
|
| +}
|
| +
|
| +void FakeProfileOAuth2TokenService::IssueTokenForScope(
|
| + const ScopeSet& scope,
|
| + const std::string& access_token,
|
| + const base::Time& expiration) {
|
| + CompleteRequests(scope,
|
| + GoogleServiceAuthError::AuthErrorNone(),
|
| + access_token,
|
| + expiration);
|
| +}
|
| +
|
| +void FakeProfileOAuth2TokenService::IssueErrorForScope(
|
| + const ScopeSet& scope,
|
| + const GoogleServiceAuthError& error) {
|
| + CompleteRequests(scope, error, std::string(), base::Time());
|
| +}
|
| +
|
| +void FakeProfileOAuth2TokenService::CompleteRequests(
|
| + const ScopeSet& scope,
|
| + const GoogleServiceAuthError& error,
|
| + const std::string& access_token,
|
| + const base::Time& expiration) {
|
| + std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests =
|
| + GetPendingRequests();
|
| + // Walk the requests and notify the callbacks.
|
| + for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
|
| + it != pending_requests_.end(); ++it) {
|
| + if (it->request && it->scopes == scope)
|
| + it->request->InformConsumer(error, access_token, expiration);
|
| + }
|
| +}
|
| +
|
| +std::string FakeProfileOAuth2TokenService::GetRefreshToken() {
|
| + return refresh_token_;
|
| +}
|
| +
|
| +net::URLRequestContextGetter*
|
| +FakeProfileOAuth2TokenService::GetRequestContext() {
|
| + return NULL;
|
| +}
|
| +
|
| +std::vector<FakeProfileOAuth2TokenService::PendingRequest>
|
| +FakeProfileOAuth2TokenService::GetPendingRequests() {
|
| + std::vector<PendingRequest> valid_requests;
|
| + for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
|
| + it != pending_requests_.end(); ++it) {
|
| + if (it->request)
|
| + valid_requests.push_back(*it);
|
| + }
|
| + return valid_requests;
|
| +}
|
| +
|
| +void FakeProfileOAuth2TokenService::FetchOAuth2Token(
|
| + RequestImpl* request,
|
| + net::URLRequestContextGetter* getter,
|
| + const std::string& client_id,
|
| + const std::string& client_secret,
|
| + const ScopeSet& scopes) {
|
| + PendingRequest pending_request;
|
| + pending_request.client_id = client_id;
|
| + pending_request.client_secret = client_secret;
|
| + pending_request.scopes = scopes;
|
| + pending_request.request = request->AsWeakPtr();
|
| + pending_requests_.push_back(pending_request);
|
| +}
|
|
|