[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
Colin Blundell | 3e0efae | 2018-06-05 07:11:49 | [diff] [blame] | 5 | #include "components/invalidation/impl/profile_identity_provider.h" |
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 6 | |
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 7 | #include "components/signin/core/browser/profile_oauth2_token_service.h" |
8 | |||||
Colin Blundell | 3e0efae | 2018-06-05 07:11:49 | [diff] [blame] | 9 | namespace invalidation { |
10 | |||||
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 11 | ProfileIdentityProvider::ProfileIdentityProvider( |
12 | SigninManagerBase* signin_manager, | ||||
Colin Blundell | 12b411d2 | 2018-05-23 09:24:26 | [diff] [blame] | 13 | ProfileOAuth2TokenService* token_service) |
14 | : signin_manager_(signin_manager), token_service_(token_service) { | ||||
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 15 | signin_manager_->AddObserver(this); |
16 | } | ||||
17 | |||||
18 | ProfileIdentityProvider::~ProfileIdentityProvider() { | ||||
19 | signin_manager_->RemoveObserver(this); | ||||
20 | } | ||||
21 | |||||
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 22 | std::string ProfileIdentityProvider::GetActiveAccountId() { |
23 | return signin_manager_->GetAuthenticatedAccountId(); | ||||
24 | } | ||||
25 | |||||
Colin Blundell | a212f4f | 2018-06-05 14:13:11 | [diff] [blame^] | 26 | bool ProfileIdentityProvider::IsActiveAccountAvailable() { |
27 | if (GetActiveAccountId().empty() || !token_service_ || | ||||
28 | !token_service_->RefreshTokenIsAvailable(GetActiveAccountId())) | ||||
29 | return false; | ||||
30 | |||||
31 | return true; | ||||
32 | } | ||||
33 | |||||
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 34 | OAuth2TokenService* ProfileIdentityProvider::GetTokenService() { |
35 | return token_service_; | ||||
36 | } | ||||
37 | |||||
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 38 | void ProfileIdentityProvider::GoogleSigninSucceeded( |
rogerta | 22aa58e | 2014-08-29 15:15:57 | [diff] [blame] | 39 | const std::string& account_id, |
Mihai Sardarescu | b4b697e | 2017-07-04 16:41:46 | [diff] [blame] | 40 | const std::string& username) { |
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 41 | FireOnActiveAccountLogin(); |
42 | } | ||||
43 | |||||
rogerta | 22aa58e | 2014-08-29 15:15:57 | [diff] [blame] | 44 | void ProfileIdentityProvider::GoogleSignedOut(const std::string& account_id, |
45 | const std::string& username) { | ||||
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 46 | FireOnActiveAccountLogout(); |
47 | } | ||||
Colin Blundell | 3e0efae | 2018-06-05 07:11:49 | [diff] [blame] | 48 | |
49 | } // namespace invalidation |