Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / signin / profile_oauth2_token_service.cc
blob9ca27fb022bbc949bb542c7b34fe1afa33c788b0
1 // Copyright 2013 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 "chrome/browser/signin/profile_oauth2_token_service.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h"
10 #include "base/time/time.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/signin/signin_global_error.h"
14 #include "chrome/browser/signin/signin_manager.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/ui/global_error/global_error_service.h"
17 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h"
21 #include "net/url_request/url_request_context_getter.h"
23 ProfileOAuth2TokenService::ProfileOAuth2TokenService()
24 : profile_(NULL) {
27 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {
28 DCHECK(!signin_global_error_.get()) <<
29 "ProfileOAuth2TokenService::Initialize called but not "
30 "ProfileOAuth2TokenService::Shutdown";
33 void ProfileOAuth2TokenService::Initialize(Profile* profile) {
34 DCHECK(profile);
35 DCHECK(!profile_);
36 profile_ = profile;
38 signin_global_error_.reset(new SigninGlobalError(profile));
39 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
40 signin_global_error_.get());
43 void ProfileOAuth2TokenService::Shutdown() {
44 DCHECK(profile_) << "Shutdown() called without matching call to Initialize()";
45 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
46 signin_global_error_.get());
47 signin_global_error_.reset();
50 std::string ProfileOAuth2TokenService::GetRefreshToken(
51 const std::string& account_id) {
52 NOTREACHED() << "GetRefreshToken should not be called on the base PO2TS";
53 return "";
56 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() {
57 return NULL;
60 void ProfileOAuth2TokenService::UpdateAuthError(
61 const std::string& account_id,
62 const GoogleServiceAuthError& error) {
63 NOTREACHED();
66 std::string ProfileOAuth2TokenService::GetPrimaryAccountId() {
67 SigninManagerBase* signin_manager =
68 SigninManagerFactory::GetForProfileIfExists(profile_);
69 // TODO(fgorski): DCHECK(signin_manager) here - it may require update to test
70 // code and the line above (SigninManager might not exist yet).
71 return signin_manager ? signin_manager->GetAuthenticatedUsername()
72 : std::string();
75 std::vector<std::string> ProfileOAuth2TokenService::GetAccounts() {
76 NOTREACHED();
77 return std::vector<std::string>();
80 void ProfileOAuth2TokenService::LoadCredentials() {
81 // Empty implementation by default.
84 void ProfileOAuth2TokenService::UpdateCredentials(
85 const std::string& account_id,
86 const std::string& refresh_token) {
87 NOTREACHED();
90 void ProfileOAuth2TokenService::RevokeAllCredentials() {
91 // Empty implementation by default.