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
) {
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 void OAuth2TokenServiceDelegate::StartBatchChanges() {
50 ++batch_change_depth_
;
51 if (batch_change_depth_
== 1)
52 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
, observer_list_
,
53 OnStartBatchChanges());
56 void OAuth2TokenServiceDelegate::EndBatchChanges() {
57 --batch_change_depth_
;
58 DCHECK_LE(0, batch_change_depth_
);
59 if (batch_change_depth_
== 0)
60 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
, observer_list_
,
64 void OAuth2TokenServiceDelegate::FireRefreshTokenAvailable(
65 const std::string
& account_id
) {
66 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
68 tracked_objects::ScopedTracker
tracking_profile(
69 FROM_HERE_WITH_EXPLICIT_FUNCTION(
70 "422460 OAuth2TokenService::FireRefreshTokenAvailable"));
72 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
, observer_list_
,
73 OnRefreshTokenAvailable(account_id
));
76 void OAuth2TokenServiceDelegate::FireRefreshTokenRevoked(
77 const std::string
& account_id
) {
78 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
, observer_list_
,
79 OnRefreshTokenRevoked(account_id
));
82 void OAuth2TokenServiceDelegate::FireRefreshTokensLoaded() {
83 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
85 tracked_objects::ScopedTracker
tracking_profile(
86 FROM_HERE_WITH_EXPLICIT_FUNCTION(
87 "422460 OAuth2TokenService::FireRefreshTokensLoaded"));
89 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
, observer_list_
,
90 OnRefreshTokensLoaded());
93 net::URLRequestContextGetter
* OAuth2TokenServiceDelegate::GetRequestContext()
98 std::vector
<std::string
> OAuth2TokenServiceDelegate::GetAccounts() {
99 return std::vector
<std::string
>();