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 "chrome/browser/services/gcm/gcm_account_tracker.h" | 5 #include "chrome/browser/services/gcm/gcm_account_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" |
12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
13 #include "components/gcm_driver/gcm_driver.h" | 15 #include "components/gcm_driver/gcm_driver.h" |
14 #include "google_apis/gaia/google_service_auth_error.h" | 16 #include "google_apis/gaia/google_service_auth_error.h" |
15 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
16 | 18 |
17 namespace gcm { | 19 namespace gcm { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 // Scopes needed by the OAuth2 access tokens. | 23 // Scopes needed by the OAuth2 access tokens. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void GCMAccountTracker::ScheduleReportTokens() { | 86 void GCMAccountTracker::ScheduleReportTokens() { |
85 // Shortcutting here, in case GCM Driver is not yet connected. In that case | 87 // Shortcutting here, in case GCM Driver is not yet connected. In that case |
86 // reporting will be scheduled/started when the connection is made. | 88 // reporting will be scheduled/started when the connection is made. |
87 if (!driver_->IsConnected()) | 89 if (!driver_->IsConnected()) |
88 return; | 90 return; |
89 | 91 |
90 DVLOG(1) << "Deferring the token reporting for: " | 92 DVLOG(1) << "Deferring the token reporting for: " |
91 << GetTimeToNextTokenReporting().InSeconds() << " seconds."; | 93 << GetTimeToNextTokenReporting().InSeconds() << " seconds."; |
92 | 94 |
93 reporting_weak_ptr_factory_.InvalidateWeakPtrs(); | 95 reporting_weak_ptr_factory_.InvalidateWeakPtrs(); |
94 base::MessageLoop::current()->PostDelayedTask( | 96 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
95 FROM_HERE, | 97 FROM_HERE, base::Bind(&GCMAccountTracker::ReportTokens, |
96 base::Bind(&GCMAccountTracker::ReportTokens, | 98 reporting_weak_ptr_factory_.GetWeakPtr()), |
97 reporting_weak_ptr_factory_.GetWeakPtr()), | |
98 GetTimeToNextTokenReporting()); | 99 GetTimeToNextTokenReporting()); |
99 } | 100 } |
100 | 101 |
101 void GCMAccountTracker::OnAccountAdded(const gaia::AccountIds& ids) { | 102 void GCMAccountTracker::OnAccountAdded(const gaia::AccountIds& ids) { |
102 DVLOG(1) << "Account added: " << ids.email; | 103 DVLOG(1) << "Account added: " << ids.email; |
103 // We listen for the account signing in, which happens after account is added. | 104 // We listen for the account signing in, which happens after account is added. |
104 } | 105 } |
105 | 106 |
106 void GCMAccountTracker::OnAccountRemoved(const gaia::AccountIds& ids) { | 107 void GCMAccountTracker::OnAccountRemoved(const gaia::AccountIds& ids) { |
107 DVLOG(1) << "Account removed: " << ids.email; | 108 DVLOG(1) << "Account removed: " << ids.email; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 iter->second.state = ACCOUNT_REMOVED; | 367 iter->second.state = ACCOUNT_REMOVED; |
367 ReportTokens(); | 368 ReportTokens(); |
368 } | 369 } |
369 | 370 |
370 OAuth2TokenService* GCMAccountTracker::GetTokenService() { | 371 OAuth2TokenService* GCMAccountTracker::GetTokenService() { |
371 DCHECK(account_tracker_->identity_provider()); | 372 DCHECK(account_tracker_->identity_provider()); |
372 return account_tracker_->identity_provider()->GetTokenService(); | 373 return account_tracker_->identity_provider()->GetTokenService(); |
373 } | 374 } |
374 | 375 |
375 } // namespace gcm | 376 } // namespace gcm |
OLD | NEW |