Infobar material design refresh: bg color
[chromium-blink-merge.git] / google_apis / gaia / oauth2_token_service_delegate.cc
blobaed5db8bc2321f585a59f8e47d5bc9d1c93c44ea
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 return error.IsPersistentError();
54 void OAuth2TokenServiceDelegate::StartBatchChanges() {
55 ++batch_change_depth_;
56 if (batch_change_depth_ == 1)
57 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
58 OnStartBatchChanges());
61 void OAuth2TokenServiceDelegate::EndBatchChanges() {
62 --batch_change_depth_;
63 DCHECK_LE(0, batch_change_depth_);
64 if (batch_change_depth_ == 0)
65 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
66 OnEndBatchChanges());
69 void OAuth2TokenServiceDelegate::FireRefreshTokenAvailable(
70 const std::string& account_id) {
71 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
72 // fixed.
73 tracked_objects::ScopedTracker tracking_profile(
74 FROM_HERE_WITH_EXPLICIT_FUNCTION(
75 "422460 OAuth2TokenService::FireRefreshTokenAvailable"));
77 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
78 OnRefreshTokenAvailable(account_id));
81 void OAuth2TokenServiceDelegate::FireRefreshTokenRevoked(
82 const std::string& account_id) {
83 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
84 OnRefreshTokenRevoked(account_id));
87 void OAuth2TokenServiceDelegate::FireRefreshTokensLoaded() {
88 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
89 // fixed.
90 tracked_objects::ScopedTracker tracking_profile(
91 FROM_HERE_WITH_EXPLICIT_FUNCTION(
92 "422460 OAuth2TokenService::FireRefreshTokensLoaded"));
94 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
95 OnRefreshTokensLoaded());
98 net::URLRequestContextGetter* OAuth2TokenServiceDelegate::GetRequestContext()
99 const {
100 return nullptr;
103 bool OAuth2TokenServiceDelegate::RefreshTokenHasError(
104 const std::string& account_id) const {
105 return false;
108 std::vector<std::string> OAuth2TokenServiceDelegate::GetAccounts() {
109 return std::vector<std::string>();