OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/signin/core/browser/child_account_info_fetcher_impl.h" | 5 #include "components/signin/core/browser/child_account_info_fetcher_impl.h" |
6 | 6 |
7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "components/invalidation/public/invalidation_service.h" | 10 #include "components/invalidation/public/invalidation_service.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 bool insert_success = | 67 bool insert_success = |
68 invalidation_service_->UpdateRegisteredInvalidationIds(this, ids); | 68 invalidation_service_->UpdateRegisteredInvalidationIds(this, ids); |
69 DCHECK(insert_success); | 69 DCHECK(insert_success); |
70 } | 70 } |
71 FetchIfNotInProgress(); | 71 FetchIfNotInProgress(); |
72 } | 72 } |
73 | 73 |
74 ChildAccountInfoFetcherImpl::~ChildAccountInfoFetcherImpl() { | 74 ChildAccountInfoFetcherImpl::~ChildAccountInfoFetcherImpl() { |
75 TRACE_EVENT_ASYNC_END0("AccountFetcherService", kFetcherId, this); | 75 TRACE_EVENT_ASYNC_END0("AccountFetcherService", kFetcherId, this); |
76 if (invalidation_service_) | 76 if (invalidation_service_) |
77 invalidation_service_->UnregisterInvalidationHandler(this); | 77 UnregisterInvalidationHandler(); |
78 } | 78 } |
79 | 79 |
80 void ChildAccountInfoFetcherImpl::FetchIfNotInProgress() { | 80 void ChildAccountInfoFetcherImpl::FetchIfNotInProgress() { |
81 DCHECK(thread_checker_.CalledOnValidThread()); | 81 DCHECK(thread_checker_.CalledOnValidThread()); |
82 if (fetch_in_progress_) | 82 if (fetch_in_progress_) |
83 return; | 83 return; |
84 fetch_in_progress_ = true; | 84 fetch_in_progress_ = true; |
85 OAuth2TokenService::ScopeSet scopes; | 85 OAuth2TokenService::ScopeSet scopes; |
86 scopes.insert(GaiaConstants::kOAuth1LoginScope); | 86 scopes.insert(GaiaConstants::kOAuth1LoginScope); |
87 login_token_request_.reset( | 87 login_token_request_.reset( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 std::find(service_flags.begin(), service_flags.end(), | 130 std::find(service_flags.begin(), service_flags.end(), |
131 AccountTrackerService::kChildAccountServiceFlag) != | 131 AccountTrackerService::kChildAccountServiceFlag) != |
132 service_flags.end(); | 132 service_flags.end(); |
133 if (!is_child_account && invalidation_service_) { | 133 if (!is_child_account && invalidation_service_) { |
134 // Don't bother listening for invalidations as a non-child account can't | 134 // Don't bother listening for invalidations as a non-child account can't |
135 // become a child account. | 135 // become a child account. |
136 bool insert_success = | 136 bool insert_success = |
137 invalidation_service_->UpdateRegisteredInvalidationIds( | 137 invalidation_service_->UpdateRegisteredInvalidationIds( |
138 this, syncer::ObjectIdSet()); | 138 this, syncer::ObjectIdSet()); |
139 DCHECK(insert_success); | 139 DCHECK(insert_success); |
140 invalidation_service_->UnregisterInvalidationHandler(this); | 140 UnregisterInvalidationHandler(); |
141 invalidation_service_ = nullptr; | |
142 } | 141 } |
143 fetcher_service_->SetIsChildAccount(account_id_, is_child_account); | 142 fetcher_service_->SetIsChildAccount(account_id_, is_child_account); |
144 } else { | 143 } else { |
145 DLOG(ERROR) << "ChildAccountInfoFetcherImpl::OnGetUserInfoSuccess: " | 144 DLOG(ERROR) << "ChildAccountInfoFetcherImpl::OnGetUserInfoSuccess: " |
146 << "GetUserInfo response didn't include allServices field."; | 145 << "GetUserInfo response didn't include allServices field."; |
147 } | 146 } |
148 fetch_in_progress_ = false; | 147 fetch_in_progress_ = false; |
149 } | 148 } |
150 | 149 |
151 void ChildAccountInfoFetcherImpl::OnGetUserInfoFailure( | 150 void ChildAccountInfoFetcherImpl::OnGetUserInfoFailure( |
152 const GoogleServiceAuthError& error) { | 151 const GoogleServiceAuthError& error) { |
153 HandleFailure(); | 152 HandleFailure(); |
154 } | 153 } |
155 | 154 |
156 void ChildAccountInfoFetcherImpl::HandleFailure() { | 155 void ChildAccountInfoFetcherImpl::HandleFailure() { |
157 fetch_in_progress_ = false; | 156 fetch_in_progress_ = false; |
158 backoff_.InformOfRequest(false); | 157 backoff_.InformOfRequest(false); |
159 timer_.Start(FROM_HERE, backoff_.GetTimeUntilRelease(), this, | 158 timer_.Start(FROM_HERE, backoff_.GetTimeUntilRelease(), this, |
160 &ChildAccountInfoFetcherImpl::FetchIfNotInProgress); | 159 &ChildAccountInfoFetcherImpl::FetchIfNotInProgress); |
161 } | 160 } |
162 | 161 |
| 162 void ChildAccountInfoFetcherImpl::UnregisterInvalidationHandler() { |
| 163 invalidation_service_->UnregisterInvalidationHandler(this); |
| 164 invalidation_service_ = nullptr; |
| 165 } |
| 166 |
163 void ChildAccountInfoFetcherImpl::OnInvalidatorStateChange( | 167 void ChildAccountInfoFetcherImpl::OnInvalidatorStateChange( |
164 syncer::InvalidatorState state) { | 168 syncer::InvalidatorState state) { |
| 169 if (state == syncer::INVALIDATOR_SHUTTING_DOWN) |
| 170 UnregisterInvalidationHandler(); |
165 } | 171 } |
166 | 172 |
167 void ChildAccountInfoFetcherImpl::OnIncomingInvalidation( | 173 void ChildAccountInfoFetcherImpl::OnIncomingInvalidation( |
168 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 174 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
169 FetchIfNotInProgress(); | 175 FetchIfNotInProgress(); |
170 invalidation_map.AcknowledgeAll(); | 176 invalidation_map.AcknowledgeAll(); |
171 } | 177 } |
172 | 178 |
173 std::string ChildAccountInfoFetcherImpl::GetOwnerName() const { | 179 std::string ChildAccountInfoFetcherImpl::GetOwnerName() const { |
174 return std::string(kFetcherId); | 180 return std::string(kFetcherId); |
175 } | 181 } |
OLD | NEW |