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

Unified 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: Merge with ToT 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 side-by-side diff with in-line comments
Download patch
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..04d4fb9ef36f9162cae32cee2ed186b73c64a525
--- /dev/null
+++ b/chrome/browser/signin/fake_profile_oauth2_token_service.cc
@@ -0,0 +1,120 @@
+// 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");
+ else
+ FireRefreshTokenAvailable("account_id");
+ // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
+}
+
+void FakeProfileOAuth2TokenService::IssueTokenForScope(
+ const ScopeSet& scope,
+ const std::string& access_token,
+ const base::Time& expiration) {
+ CompleteRequests(false,
+ scope,
+ GoogleServiceAuthError::AuthErrorNone(),
+ access_token,
+ expiration);
+}
+
+void FakeProfileOAuth2TokenService::IssueErrorForScope(
+ const ScopeSet& scope,
+ const GoogleServiceAuthError& error) {
+ CompleteRequests(false, scope, error, std::string(), base::Time());
+}
+
+void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequests(
+ const GoogleServiceAuthError& error) {
+ CompleteRequests(true, ScopeSet(), error, std::string(), base::Time());
+}
+
+void FakeProfileOAuth2TokenService::IssueTokenForAllPendingRequests(
+ const std::string& access_token,
+ const base::Time& expiration) {
+ CompleteRequests(true,
+ ScopeSet(),
+ GoogleServiceAuthError::AuthErrorNone(),
+ access_token,
+ expiration);
+}
+
+void FakeProfileOAuth2TokenService::CompleteRequests(
+ bool all_scopes,
+ 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 && (all_scopes || 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);
+}
« no previous file with comments | « chrome/browser/signin/fake_profile_oauth2_token_service.h ('k') | chrome/browser/signin/oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698