Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: chrome/browser/extensions/api/identity/account_tracker.cc

Issue 196783002: Export a private webstore API to call into the new inline sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add API tests Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/extensions/api/identity/account_tracker.h" 5 #include "chrome/browser/extensions/api/identity/account_tracker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
13 #include "chrome/browser/signin/signin_manager.h" 13 #include "chrome/browser/signin/signin_manager.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "components/signin/core/browser/profile_oauth2_token_service.h" 14 #include "components/signin/core/browser/profile_oauth2_token_service.h"
16 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
17 #include "extensions/browser/extension_system.h" 16 #include "extensions/browser/extension_system.h"
18 17
19 namespace extensions { 18 namespace extensions {
20 19
21 AccountTracker::AccountTracker(Profile* profile) : profile_(profile) { 20 AccountTracker::AccountTracker(Profile* profile) : profile_(profile) {
22 ProfileOAuth2TokenService* service = 21 ProfileOAuth2TokenService* service =
23 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 22 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
24 service->AddObserver(this); 23 service->AddObserver(this);
25 service->signin_error_controller()->AddProvider(this); 24 service->signin_error_controller()->AddProvider(this);
26 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); 25 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this);
26 SigninManagerFactory::GetInstance()->AddObserver(this);
27 } 27 }
28 28
29 AccountTracker::~AccountTracker() {} 29 AccountTracker::~AccountTracker() {
30 SigninManagerFactory::GetInstance()->RemoveObserver(this);
31 }
30 32
31 void AccountTracker::ReportAuthError(const std::string& account_id, 33 void AccountTracker::ReportAuthError(const std::string& account_id,
32 const GoogleServiceAuthError& error) { 34 const GoogleServiceAuthError& error) {
33 account_errors_.insert(make_pair(account_id, error)); 35 account_errors_.insert(make_pair(account_id, error));
34 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 36 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
35 signin_error_controller()->AuthStatusChanged(); 37 signin_error_controller()->AuthStatusChanged();
36 UpdateSignInState(account_id, false); 38 UpdateSignInState(account_id, false);
37 } 39 }
38 40
39 void AccountTracker::Shutdown() { 41 void AccountTracker::Shutdown() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 84
83 void AccountTracker::GoogleSignedOut(const std::string& username) { 85 void AccountTracker::GoogleSignedOut(const std::string& username) {
84 if (username == signin_manager_account_id() || 86 if (username == signin_manager_account_id() ||
85 signin_manager_account_id().empty()) { 87 signin_manager_account_id().empty()) {
86 StopTrackingAllAccounts(); 88 StopTrackingAllAccounts();
87 } else { 89 } else {
88 StopTrackingAccount(username); 90 StopTrackingAccount(username);
89 } 91 }
90 } 92 }
91 93
94 void AccountTracker::SigninManagerCreated(SigninManagerBase* manager) {
95 manager->AddObserver(this);
96 }
97
98 void AccountTracker::SigninManagerShutdown(SigninManagerBase* manager) {
99 manager->RemoveObserver(this);
100 }
101
92 const std::string AccountTracker::signin_manager_account_id() { 102 const std::string AccountTracker::signin_manager_account_id() {
93 return SigninManagerFactory::GetForProfile(profile_) 103 return SigninManagerFactory::GetForProfile(profile_)
94 ->GetAuthenticatedAccountId(); 104 ->GetAuthenticatedAccountId();
95 } 105 }
96 106
97 void AccountTracker::NotifyAccountAdded(const AccountState& account) { 107 void AccountTracker::NotifyAccountAdded(const AccountState& account) {
98 DCHECK(!account.ids.gaia.empty()); 108 DCHECK(!account.ids.gaia.empty());
99 FOR_EACH_OBSERVER( 109 FOR_EACH_OBSERVER(
100 Observer, observer_list_, OnAccountAdded(account.ids)); 110 Observer, observer_list_, OnAccountAdded(account.ids));
101 } 111 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 LOG(ERROR) << "OnOAuthError"; 277 LOG(ERROR) << "OnOAuthError";
268 tracker_->OnUserInfoFetchFailure(this); 278 tracker_->OnUserInfoFetchFailure(this);
269 } 279 }
270 280
271 void AccountIdFetcher::OnNetworkError(int response_code) { 281 void AccountIdFetcher::OnNetworkError(int response_code) {
272 LOG(ERROR) << "OnNetworkError " << response_code; 282 LOG(ERROR) << "OnNetworkError " << response_code;
273 tracker_->OnUserInfoFetchFailure(this); 283 tracker_->OnUserInfoFetchFailure(this);
274 } 284 }
275 285
276 } // namespace extensions 286 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698