Chromium Code Reviews| 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_service.h" | 5 #include "chrome/browser/services/gcm/gcm_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 const std::string& message_id, | 139 const std::string& message_id, |
| 140 GCMClient::Result result) OVERRIDE; | 140 GCMClient::Result result) OVERRIDE; |
| 141 virtual void OnMessageReceived( | 141 virtual void OnMessageReceived( |
| 142 const std::string& app_id, | 142 const std::string& app_id, |
| 143 const GCMClient::IncomingMessage& message) OVERRIDE; | 143 const GCMClient::IncomingMessage& message) OVERRIDE; |
| 144 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | 144 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
| 145 virtual void OnMessageSendError( | 145 virtual void OnMessageSendError( |
| 146 const std::string& app_id, | 146 const std::string& app_id, |
| 147 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; | 147 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; |
| 148 virtual void OnGCMReady() OVERRIDE; | 148 virtual void OnGCMReady() OVERRIDE; |
| 149 virtual void OnActivityRecorded() OVERRIDE; | |
| 149 | 150 |
| 150 // Called on IO thread. | 151 // Called on IO thread. |
| 151 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory, | 152 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 152 const base::FilePath& store_path, | 153 const base::FilePath& store_path, |
| 153 const std::vector<std::string>& account_ids, | 154 const std::vector<std::string>& account_ids, |
| 154 const scoped_refptr<net::URLRequestContextGetter>& | 155 const scoped_refptr<net::URLRequestContextGetter>& |
| 155 url_request_context_getter); | 156 url_request_context_getter); |
| 156 void Load(const base::WeakPtr<GCMService>& service); | 157 void Load(const base::WeakPtr<GCMService>& service); |
| 157 void Stop(); | 158 void Stop(); |
| 158 void CheckOut(); | 159 void CheckOut(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 send_error_details)); | 290 send_error_details)); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void GCMService::IOWorker::OnGCMReady() { | 293 void GCMService::IOWorker::OnGCMReady() { |
| 293 content::BrowserThread::PostTask(content::BrowserThread::UI, | 294 content::BrowserThread::PostTask(content::BrowserThread::UI, |
| 294 FROM_HERE, | 295 FROM_HERE, |
| 295 base::Bind(&GCMService::GCMClientReady, | 296 base::Bind(&GCMService::GCMClientReady, |
| 296 service_)); | 297 service_)); |
| 297 } | 298 } |
| 298 | 299 |
| 300 void GCMService::IOWorker::OnActivityRecorded() { | |
| 301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 302 // When an activity is recorded, get all the stats and refresh the UI of | |
| 303 // gcm-internals page. | |
| 304 GetGCMStatistics(false); | |
| 305 } | |
| 306 | |
| 299 void GCMService::IOWorker::Load(const base::WeakPtr<GCMService>& service) { | 307 void GCMService::IOWorker::Load(const base::WeakPtr<GCMService>& service) { |
| 300 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 308 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 301 | 309 |
| 302 service_ = service; | 310 service_ = service; |
| 303 gcm_client_->Load(); | 311 gcm_client_->Load(); |
| 304 } | 312 } |
| 305 | 313 |
| 306 void GCMService::IOWorker::Stop() { | 314 void GCMService::IOWorker::Stop() { |
| 307 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 315 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 308 | 316 |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 845 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 838 | 846 |
| 839 std::map<std::string, GCMAppHandler*>::const_iterator iter = | 847 std::map<std::string, GCMAppHandler*>::const_iterator iter = |
| 840 app_handlers_.find(app_id); | 848 app_handlers_.find(app_id); |
| 841 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; | 849 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; |
| 842 } | 850 } |
| 843 | 851 |
| 844 void GCMService::GetGCMStatisticsFinished( | 852 void GCMService::GetGCMStatisticsFinished( |
| 845 GCMClient::GCMStatistics stats) { | 853 GCMClient::GCMStatistics stats) { |
| 846 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 854 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 847 request_gcm_statistics_callback_.Run(stats); | 855 if (!request_gcm_statistics_callback_.is_null()) |
|
jianli
2014/05/09 17:26:27
Please comment on why the callback could be NULL.
juyik
2014/05/09 18:40:04
Normally it would not be NULL, unless it is trigge
| |
| 856 request_gcm_statistics_callback_.Run(stats); | |
| 848 } | 857 } |
| 849 | 858 |
| 850 } // namespace gcm | 859 } // namespace gcm |
| OLD | NEW |