Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / signin / core / browser / fake_signin_manager.cc
blobee18b8dd95a53e0deebdf3360942ffc7f4c9230b
1 // Copyright (c) 2012 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 "components/signin/core/browser/fake_signin_manager.h"
7 #include "base/callback_helpers.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/signin/core/browser/account_tracker_service.h"
10 #include "components/signin/core/browser/signin_metrics.h"
12 FakeSigninManagerBase::FakeSigninManagerBase(
13 SigninClient* client,
14 AccountTrackerService* account_tracker_service)
15 : SigninManagerBase(client, account_tracker_service) {}
17 FakeSigninManagerBase::~FakeSigninManagerBase() {}
19 #if !defined(OS_CHROMEOS)
21 FakeSigninManager::FakeSigninManager(
22 SigninClient* client,
23 ProfileOAuth2TokenService* token_service,
24 AccountTrackerService* account_tracker_service,
25 GaiaCookieManagerService* cookie_manager_service)
26 : SigninManager(client,
27 token_service,
28 account_tracker_service,
29 cookie_manager_service) {}
31 FakeSigninManager::~FakeSigninManager() {}
33 void FakeSigninManager::StartSignInWithRefreshToken(
34 const std::string& refresh_token,
35 const std::string& gaia_id,
36 const std::string& username,
37 const std::string& password,
38 const OAuthTokenFetchedCallback& oauth_fetched_callback) {
39 set_auth_in_progress(
40 account_tracker_service()->SeedAccountInfo(gaia_id, username));
41 set_password(password);
42 username_ = username;
44 if (!oauth_fetched_callback.is_null())
45 oauth_fetched_callback.Run(refresh_token);
48 void FakeSigninManager::CompletePendingSignin() {
49 SetAuthenticatedAccountId(GetAccountIdForAuthInProgress());
50 set_auth_in_progress(std::string());
51 FOR_EACH_OBSERVER(
52 SigninManagerBase::Observer, observer_list_,
53 GoogleSigninSucceeded(authenticated_account_id_, username_, password_));
56 void FakeSigninManager::SignIn(const std::string& gaia_id,
57 const std::string& username,
58 const std::string& password) {
59 StartSignInWithRefreshToken(std::string(), gaia_id, username, password,
60 OAuthTokenFetchedCallback());
61 CompletePendingSignin();
64 void FakeSigninManager::ForceSignOut() {
65 prohibit_signout_ = false;
66 SignOut(signin_metrics::SIGNOUT_TEST);
69 void FakeSigninManager::FailSignin(const GoogleServiceAuthError& error) {
70 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
71 GoogleSigninFailed(error));
74 void FakeSigninManager::SignOut(
75 signin_metrics::ProfileSignout signout_source_metric) {
76 if (IsSignoutProhibited())
77 return;
78 set_auth_in_progress(std::string());
79 set_password(std::string());
80 const std::string account_id = GetAuthenticatedAccountId();
81 const std::string username = GetAuthenticatedAccountInfo().email;
82 authenticated_account_id_.clear();
84 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
85 GoogleSignedOut(account_id, username));
88 #endif // !defined (OS_CHROMEOS)