OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "google_apis/gaia/account_tracker.h" | 5 #include "google_apis/gaia/account_tracker.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 tracked_objects::ScopedTracker tracking_profile( | 170 tracked_objects::ScopedTracker tracking_profile( |
171 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 171 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
172 "422460 AccountTracker::NotifySignInChanged")); | 172 "422460 AccountTracker::NotifySignInChanged")); |
173 | 173 |
174 DCHECK(!account.ids.gaia.empty()); | 174 DCHECK(!account.ids.gaia.empty()); |
175 FOR_EACH_OBSERVER(Observer, | 175 FOR_EACH_OBSERVER(Observer, |
176 observer_list_, | 176 observer_list_, |
177 OnAccountSignInChanged(account.ids, account.is_signed_in)); | 177 OnAccountSignInChanged(account.ids, account.is_signed_in)); |
178 } | 178 } |
179 | 179 |
180 void AccountTracker::UpdateSignInState(const std::string account_key, | 180 void AccountTracker::UpdateSignInState(const std::string& account_key, |
181 bool is_signed_in) { | 181 bool is_signed_in) { |
182 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 182 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
183 // fixed. | 183 // fixed. |
184 tracked_objects::ScopedTracker tracking_profile( | 184 tracked_objects::ScopedTracker tracking_profile( |
185 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 185 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
186 "422460 AccountTracker::UpdateSignInState")); | 186 "422460 AccountTracker::UpdateSignInState")); |
187 | 187 |
188 StartTrackingAccount(account_key); | 188 StartTrackingAccount(account_key); |
189 AccountState& account = accounts_[account_key]; | 189 AccountState& account = accounts_[account_key]; |
190 bool needs_gaia_id = account.ids.gaia.empty(); | 190 bool needs_gaia_id = account.ids.gaia.empty(); |
191 bool was_signed_in = account.is_signed_in; | 191 bool was_signed_in = account.is_signed_in; |
192 account.is_signed_in = is_signed_in; | 192 account.is_signed_in = is_signed_in; |
193 | 193 |
194 if (needs_gaia_id && is_signed_in) | 194 if (needs_gaia_id && is_signed_in) |
195 StartFetchingUserInfo(account_key); | 195 StartFetchingUserInfo(account_key); |
196 | 196 |
197 if (!needs_gaia_id && (was_signed_in != is_signed_in)) | 197 if (!needs_gaia_id && (was_signed_in != is_signed_in)) |
198 NotifySignInChanged(account); | 198 NotifySignInChanged(account); |
199 } | 199 } |
200 | 200 |
201 void AccountTracker::StartTrackingAccount(const std::string account_key) { | 201 void AccountTracker::StartTrackingAccount(const std::string& account_key) { |
202 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 202 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
203 // fixed. | 203 // fixed. |
204 tracked_objects::ScopedTracker tracking_profile( | 204 tracked_objects::ScopedTracker tracking_profile( |
205 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 205 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
206 "422460 AccountTracker::StartTrackingAccount")); | 206 "422460 AccountTracker::StartTrackingAccount")); |
207 | 207 |
208 if (!ContainsKey(accounts_, account_key)) { | 208 if (!ContainsKey(accounts_, account_key)) { |
209 DVLOG(1) << "StartTracking " << account_key; | 209 DVLOG(1) << "StartTracking " << account_key; |
210 AccountState account_state; | 210 AccountState account_state; |
211 account_state.ids.account_key = account_key; | 211 account_state.ids.account_key = account_key; |
212 account_state.ids.email = account_key; | 212 account_state.ids.email = account_key; |
213 account_state.is_signed_in = false; | 213 account_state.is_signed_in = false; |
214 accounts_.insert(make_pair(account_key, account_state)); | 214 accounts_.insert(make_pair(account_key, account_state)); |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 void AccountTracker::StopTrackingAccount(const std::string account_key) { | 218 void AccountTracker::StopTrackingAccount(const std::string& account_key) { |
219 DVLOG(1) << "StopTracking " << account_key; | 219 DVLOG(1) << "StopTracking " << account_key; |
220 if (ContainsKey(accounts_, account_key)) { | 220 if (ContainsKey(accounts_, account_key)) { |
221 AccountState& account = accounts_[account_key]; | 221 AccountState& account = accounts_[account_key]; |
222 if (!account.ids.gaia.empty()) { | 222 if (!account.ids.gaia.empty()) { |
223 UpdateSignInState(account_key, false); | 223 UpdateSignInState(account_key, false); |
224 NotifyAccountRemoved(account); | 224 NotifyAccountRemoved(account); |
225 } | 225 } |
226 accounts_.erase(account_key); | 226 accounts_.erase(account_key); |
227 } | 227 } |
228 | 228 |
229 if (ContainsKey(user_info_requests_, account_key)) | 229 if (ContainsKey(user_info_requests_, account_key)) |
230 DeleteFetcher(user_info_requests_[account_key]); | 230 DeleteFetcher(user_info_requests_[account_key]); |
231 } | 231 } |
232 | 232 |
233 void AccountTracker::StopTrackingAllAccounts() { | 233 void AccountTracker::StopTrackingAllAccounts() { |
234 while (!accounts_.empty()) | 234 while (!accounts_.empty()) |
235 StopTrackingAccount(accounts_.begin()->first); | 235 StopTrackingAccount(accounts_.begin()->first); |
236 } | 236 } |
237 | 237 |
238 void AccountTracker::StartFetchingUserInfo(const std::string account_key) { | 238 void AccountTracker::StartFetchingUserInfo(const std::string& account_key) { |
239 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 239 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
240 // fixed. | 240 // fixed. |
241 tracked_objects::ScopedTracker tracking_profile( | 241 tracked_objects::ScopedTracker tracking_profile( |
242 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 242 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
243 "422460 AccountTracker::StartFetchingUserInfo")); | 243 "422460 AccountTracker::StartFetchingUserInfo")); |
244 | 244 |
245 if (ContainsKey(user_info_requests_, account_key)) { | 245 if (ContainsKey(user_info_requests_, account_key)) { |
246 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 | 246 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
247 // is fixed. | 247 // is fixed. |
248 tracked_objects::ScopedTracker tracking_profile1( | 248 tracked_objects::ScopedTracker tracking_profile1( |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 "AccountIdFetcher", | 381 "AccountIdFetcher", |
382 this, | 382 this, |
383 "OnNetworkError", | 383 "OnNetworkError", |
384 "response_code", | 384 "response_code", |
385 response_code); | 385 response_code); |
386 LOG(ERROR) << "OnNetworkError " << response_code; | 386 LOG(ERROR) << "OnNetworkError " << response_code; |
387 tracker_->OnUserInfoFetchFailure(this); | 387 tracker_->OnUserInfoFetchFailure(this); |
388 } | 388 } |
389 | 389 |
390 } // namespace gaia | 390 } // namespace gaia |
OLD | NEW |