Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / profile_oauth2_token_service.cc
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.
4
5 #include "chrome/browser/signin/profile_oauth2_token_service.h"
6
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/notification_details.h"
19 #include "content/public/browser/notification_source.h"
20 #include "net/url_request/url_request_context_getter.h"
21
22 ProfileOAuth2TokenService::ProfileOAuth2TokenService()
23     : profile_(NULL) {
24 }
25
26 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {
27   DCHECK(!signin_global_error_.get()) <<
28       "ProfileOAuth2TokenService::Initialize called but not "
29       "ProfileOAuth2TokenService::Shutdown";
30 }
31
32 void ProfileOAuth2TokenService::Initialize(Profile* profile) {
33   DCHECK(profile);
34   DCHECK(!profile_);
35   profile_ = profile;
36
37   signin_global_error_.reset(new SigninGlobalError(profile));
38   GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
39       signin_global_error_.get());
40 }
41
42 void ProfileOAuth2TokenService::Shutdown() {
43   DCHECK(profile_) << "Shutdown() called without matching call to Initialize()";
44   GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
45       signin_global_error_.get());
46   signin_global_error_.reset();
47 }
48
49 std::string ProfileOAuth2TokenService::GetRefreshToken(
50     const std::string& account_id) {
51   NOTREACHED() << "GetRefreshToken should not be called on the base PO2TS";
52   return "";
53 }
54
55 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() {
56   return NULL;
57 }
58
59 void ProfileOAuth2TokenService::UpdateAuthError(
60     const std::string& account_id,
61     const GoogleServiceAuthError& error) {
62   NOTREACHED();
63 }
64
65 std::string ProfileOAuth2TokenService::GetPrimaryAccountId() {
66   SigninManagerBase* signin_manager =
67       SigninManagerFactory::GetForProfileIfExists(profile_);
68   // TODO(fgorski): DCHECK(signin_manager) here - it may require update to test
69   // code and the line above (SigninManager might not exist yet).
70   return signin_manager ? signin_manager->GetAuthenticatedUsername()
71       : std::string();
72 }
73
74 std::vector<std::string> ProfileOAuth2TokenService::GetAccounts() {
75   NOTREACHED();
76   return std::vector<std::string>();
77 }
78
79 void ProfileOAuth2TokenService::LoadCredentials(
80     const std::string& primary_account_id) {
81   // Empty implementation by default.
82 }
83
84 void ProfileOAuth2TokenService::UpdateCredentials(
85     const std::string& account_id,
86     const std::string& refresh_token) {
87   NOTREACHED();
88 }
89
90 void ProfileOAuth2TokenService::RevokeAllCredentials() {
91   // Empty implementation by default.
92 }
93