1988af0d9a839a44a740597c4a21a31f04e48104
[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/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"
22
23 ProfileOAuth2TokenService::ProfileOAuth2TokenService()
24     : profile_(NULL) {
25 }
26
27 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {
28   DCHECK(!signin_global_error_.get()) <<
29       "ProfileOAuth2TokenService::Initialize called but not "
30       "ProfileOAuth2TokenService::Shutdown";
31 }
32
33 void ProfileOAuth2TokenService::Initialize(Profile* profile) {
34   DCHECK(profile);
35   DCHECK(!profile_);
36   profile_ = profile;
37
38   signin_global_error_.reset(new SigninGlobalError(profile));
39   GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
40       signin_global_error_.get());
41 }
42
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();
48 }
49
50 std::string ProfileOAuth2TokenService::GetRefreshToken(
51     const std::string& account_id) {
52   NOTREACHED() << "GetRefreshToken should not be called on the base PO2TS";
53   return "";
54 }
55
56 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() {
57   return NULL;
58 }
59
60 void ProfileOAuth2TokenService::UpdateAuthError(
61     const std::string& account_id,
62     const GoogleServiceAuthError& error) {
63   NOTREACHED();
64 }
65
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();
73 }
74
75 std::vector<std::string> ProfileOAuth2TokenService::GetAccounts() {
76   NOTREACHED();
77   return std::vector<std::string>();
78 }
79
80 void ProfileOAuth2TokenService::LoadCredentials(
81     const std::string& primary_account_id) {
82   // Empty implementation by default.
83 }
84
85 void ProfileOAuth2TokenService::UpdateCredentials(
86     const std::string& account_id,
87     const std::string& refresh_token) {
88   NOTREACHED();
89 }
90
91 void ProfileOAuth2TokenService::RevokeAllCredentials() {
92   // Empty implementation by default.
93 }
94