| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/shell/browser/shell_oauth2_token_service.h" | 5 #include "extensions/shell/browser/shell_oauth2_token_service.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
| 8 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 10 #include "extensions/shell/browser/shell_oauth2_token_service_delegate.h" | 11 #include "extensions/shell/browser/shell_oauth2_token_service_delegate.h" |
| 11 | 12 |
| 12 namespace extensions { | 13 namespace extensions { |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 ShellOAuth2TokenService* g_instance = nullptr; | 16 ShellOAuth2TokenService* g_instance = nullptr; |
| 16 | 17 |
| 17 } // namespace | 18 } // namespace |
| 18 | 19 |
| 19 ShellOAuth2TokenService::ShellOAuth2TokenService( | 20 ShellOAuth2TokenService::ShellOAuth2TokenService( |
| 20 content::BrowserContext* browser_context, | 21 content::BrowserContext* browser_context, |
| 21 std::string account_id, | 22 std::string account_id, |
| 22 std::string refresh_token) | 23 std::string refresh_token) |
| 23 : OAuth2TokenService(new ShellOAuth2TokenServiceDelegate(browser_context, | 24 : OAuth2TokenService( |
| 24 account_id, | 25 base::MakeUnique<ShellOAuth2TokenServiceDelegate>(browser_context, |
| 25 refresh_token)) { | 26 account_id, |
| 27 refresh_token)) { |
| 26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 27 DCHECK(!g_instance); | 29 DCHECK(!g_instance); |
| 28 g_instance = this; | 30 g_instance = this; |
| 29 } | 31 } |
| 30 | 32 |
| 31 ShellOAuth2TokenService::~ShellOAuth2TokenService() { | 33 ShellOAuth2TokenService::~ShellOAuth2TokenService() { |
| 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 33 DCHECK(g_instance); | 35 DCHECK(g_instance); |
| 34 g_instance = nullptr; | 36 g_instance = nullptr; |
| 35 } | 37 } |
| 36 | 38 |
| 37 // static | 39 // static |
| 38 ShellOAuth2TokenService* ShellOAuth2TokenService::GetInstance() { | 40 ShellOAuth2TokenService* ShellOAuth2TokenService::GetInstance() { |
| 39 DCHECK(g_instance); | 41 DCHECK(g_instance); |
| 40 return g_instance; | 42 return g_instance; |
| 41 } | 43 } |
| 42 | 44 |
| 43 void ShellOAuth2TokenService::SetRefreshToken( | 45 void ShellOAuth2TokenService::SetRefreshToken( |
| 44 const std::string& account_id, | 46 const std::string& account_id, |
| 45 const std::string& refresh_token) { | 47 const std::string& refresh_token) { |
| 46 GetDelegate()->UpdateCredentials(account_id, refresh_token); | 48 GetDelegate()->UpdateCredentials(account_id, refresh_token); |
| 47 } | 49 } |
| 48 | 50 |
| 49 std::string ShellOAuth2TokenService::AccountId() const { | 51 std::string ShellOAuth2TokenService::AccountId() const { |
| 50 return GetAccounts()[0]; | 52 return GetAccounts()[0]; |
| 51 } | 53 } |
| 52 | 54 |
| 53 } // namespace extensions | 55 } // namespace extensions |
| OLD | NEW |