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

Side by Side Diff: google_apis/gaia/oauth2_token_service_delegate.cc

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address final comments Created 5 years, 5 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
OLDNEW
(Empty)
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.
4
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"
8
9 OAuth2TokenServiceDelegate::ScopedBatchChange::ScopedBatchChange(
10 OAuth2TokenServiceDelegate* delegate)
11 : delegate_(delegate) {
12 DCHECK(delegate_);
13 delegate_->StartBatchChanges();
14 }
15
16 OAuth2TokenServiceDelegate::ScopedBatchChange::~ScopedBatchChange() {
17 delegate_->EndBatchChanges();
18 }
19
20 OAuth2TokenServiceDelegate::OAuth2TokenServiceDelegate()
21 : batch_change_depth_(0) {
22 }
23
24 OAuth2TokenServiceDelegate::~OAuth2TokenServiceDelegate() {
25 }
26
27 void OAuth2TokenServiceDelegate::ValidateAccountId(
28 const std::string& account_id) const {
29 DCHECK(!account_id.empty());
30
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);
37 }
38
39 void OAuth2TokenServiceDelegate::AddObserver(
40 OAuth2TokenService::Observer* observer) {
41 observer_list_.AddObserver(observer);
42 }
43
44 void OAuth2TokenServiceDelegate::RemoveObserver(
45 OAuth2TokenService::Observer* observer) {
46 observer_list_.RemoveObserver(observer);
47 }
48
49 void OAuth2TokenServiceDelegate::StartBatchChanges() {
50 ++batch_change_depth_;
51 if (batch_change_depth_ == 1)
52 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
53 OnStartBatchChanges());
54 }
55
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_,
61 OnEndBatchChanges());
62 }
63
64 void OAuth2TokenServiceDelegate::FireRefreshTokenAvailable(
65 const std::string& account_id) {
66 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
67 // fixed.
68 tracked_objects::ScopedTracker tracking_profile(
69 FROM_HERE_WITH_EXPLICIT_FUNCTION(
70 "422460 OAuth2TokenService::FireRefreshTokenAvailable"));
71
72 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
73 OnRefreshTokenAvailable(account_id));
74 }
75
76 void OAuth2TokenServiceDelegate::FireRefreshTokenRevoked(
77 const std::string& account_id) {
78 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
79 OnRefreshTokenRevoked(account_id));
80 }
81
82 void OAuth2TokenServiceDelegate::FireRefreshTokensLoaded() {
83 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
84 // fixed.
85 tracked_objects::ScopedTracker tracking_profile(
86 FROM_HERE_WITH_EXPLICIT_FUNCTION(
87 "422460 OAuth2TokenService::FireRefreshTokensLoaded"));
88
89 FOR_EACH_OBSERVER(OAuth2TokenService::Observer, observer_list_,
90 OnRefreshTokensLoaded());
91 }
92
93 net::URLRequestContextGetter* OAuth2TokenServiceDelegate::GetRequestContext()
94 const {
95 return nullptr;
96 }
97
98 std::vector<std::string> OAuth2TokenServiceDelegate::GetAccounts() {
99 return std::vector<std::string>();
100 }
OLDNEW
« no previous file with comments | « google_apis/gaia/oauth2_token_service_delegate.h ('k') | google_apis/gaia/oauth2_token_service_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698