Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / google_apis / gaia / oauth2_token_service_delegate.cc
blob2f976145ea1ee0d03451ac5dc580b780ea3df3af
1 // Copyright 2015 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.
5 #include "base/profiler/scoped_tracker.h"
6 #include "google_apis/gaia/oauth2_token_service.h"
7 #include "google_apis/gaia/oauth2_token_service_delegate.h"
9 OAuth2TokenServiceDelegate::ScopedBatchChange::ScopedBatchChange(
10 OAuth2TokenServiceDelegate* delegate)
11 : delegate_(delegate) {
12 DCHECK(delegate_);
13 delegate_->StartBatchChanges();
16 OAuth2TokenServiceDelegate::ScopedBatchChange::~ScopedBatchChange() {
17 delegate_->EndBatchChanges();
20 OAuth2TokenServiceDelegate::OAuth2TokenServiceDelegate()
21 : batch_change_depth_(0) {
24 OAuth2TokenServiceDelegate::~OAuth2TokenServiceDelegate() {
27 void OAuth2TokenServiceDelegate::ValidateAccountId(
28 const std::string& account_id) const {
29 DCHECK(!account_id.empty());
31 // If the account is given as an email, make sure its a canonical email.
32 // Note that some tests don't use email strings as account id, and after
33 // the gaia id migration it won't be an email. So only check for
34 // canonicalization if the account_id is suspected to be an email.
35 if (account_id.find('@') != std::string::npos)
36 DCHECK_EQ(gaia::CanonicalizeEmail(account_id), account_id);
39 void OAuth2TokenServiceDelegate::AddObserver(
40 OAuth2TokenService::Observer* observer) {
41 observer_list_.AddObserver(observer);
44 void OAuth2TokenServiceDelegate::RemoveObserver(
45 OAuth2TokenService::Observer* observer) {
46 observer_list_.RemoveObserver(observer);
49 // static
50 bool OAuth2TokenServiceDelegate::IsError(const GoogleServiceAuthError& error) {
51 // TODO(rogerta): should we distinguish between transient and persistent?
52 return error.state() != GoogleServiceAuthError::NONE;
55 void OAuth2TokenServiceDelegate::StartBatchChanges() {
56 ++batch_change_depth_;
57 if (batch_change_depth_ == 1)
58 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
59 OnStartBatchChanges());
62 void OAuth2TokenServiceDelegate::EndBatchChanges() {
63 --batch_change_depth_;
64 DCHECK_LE(0, batch_change_depth_);
65 if (batch_change_depth_ == 0)
66 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
67 OnEndBatchChanges());
70 void OAuth2TokenServiceDelegate::FireRefreshTokenAvailable(
71 const std::string& account_id) {
72 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
73 // fixed.
74 tracked_objects::ScopedTracker tracking_profile(
75 FROM_HERE_WITH_EXPLICIT_FUNCTION(
76 "422460 OAuth2TokenService::FireRefreshTokenAvailable"));
78 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
79 OnRefreshTokenAvailable(account_id));
82 void OAuth2TokenServiceDelegate::FireRefreshTokenRevoked(
83 const std::string& account_id) {
84 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
85 OnRefreshTokenRevoked(account_id));
88 void OAuth2TokenServiceDelegate::FireRefreshTokensLoaded() {
89 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
90 // fixed.
91 tracked_objects::ScopedTracker tracking_profile(
92 FROM_HERE_WITH_EXPLICIT_FUNCTION(
93 "422460 OAuth2TokenService::FireRefreshTokensLoaded"));
95 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
96 OnRefreshTokensLoaded());
99 net::URLRequestContextGetter* OAuth2TokenServiceDelegate::GetRequestContext()
100 const {
101 return nullptr;
104 bool OAuth2TokenServiceDelegate::RefreshTokenHasError(
105 const std::string& account_id) const {
106 return false;
109 std::vector<std::string> OAuth2TokenServiceDelegate::GetAccounts() {
110 return std::vector<std::string>();