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(); |
| 159 void Register(const std::string& app_id, | 160 void Register(const std::string& app_id, |
| 160 const std::vector<std::string>& sender_ids); | 161 const std::vector<std::string>& sender_ids); |
| 161 void Unregister(const std::string& app_id); | 162 void Unregister(const std::string& app_id); |
| 162 void Send(const std::string& app_id, | 163 void Send(const std::string& app_id, |
| 163 const std::string& receiver_id, | 164 const std::string& receiver_id, |
| 164 const GCMClient::OutgoingMessage& message); | 165 const GCMClient::OutgoingMessage& message); |
| 165 void GetGCMStatistics(bool clear_logs); | 166 void GetGCMStatistics(bool clear_logs); |
| 166 void SetGCMRecording(bool recording); | 167 void SetGCMRecording(bool recording); |
| 167 | 168 |
| 168 // For testing purpose. Can be called from UI thread. Use with care. | 169 // For testing purpose. Can be called from UI thread. Use with care. |
| 169 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 170 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
| 170 | 171 |
| 171 private: | 172 private: |
| 173 // Do the actual work of fetching GCM stats from GCM client and post back. | |
| 174 void DoGetGCMStatistics(); | |
| 175 | |
| 172 base::WeakPtr<GCMService> service_; | 176 base::WeakPtr<GCMService> service_; |
| 173 | 177 |
| 174 scoped_ptr<GCMClient> gcm_client_; | 178 scoped_ptr<GCMClient> gcm_client_; |
| 175 | 179 |
| 176 DISALLOW_COPY_AND_ASSIGN(IOWorker); | 180 DISALLOW_COPY_AND_ASSIGN(IOWorker); |
| 177 }; | 181 }; |
| 178 | 182 |
| 179 GCMService::IOWorker::IOWorker() { | 183 GCMService::IOWorker::IOWorker() { |
| 180 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 184 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 181 } | 185 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 send_error_details)); | 293 send_error_details)); |
| 290 } | 294 } |
| 291 | 295 |
| 292 void GCMService::IOWorker::OnGCMReady() { | 296 void GCMService::IOWorker::OnGCMReady() { |
| 293 content::BrowserThread::PostTask(content::BrowserThread::UI, | 297 content::BrowserThread::PostTask(content::BrowserThread::UI, |
| 294 FROM_HERE, | 298 FROM_HERE, |
| 295 base::Bind(&GCMService::GCMClientReady, | 299 base::Bind(&GCMService::GCMClientReady, |
| 296 service_)); | 300 service_)); |
| 297 } | 301 } |
| 298 | 302 |
| 303 void GCMService::IOWorker::OnActivityRecorded() { | |
| 304 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 305 // When an activity is recorded, get all the stats and refresh the UI of | |
| 306 // gcm-internals page. | |
| 307 DoGetGCMStatistics(); | |
|
jianli
2014/05/06 22:54:53
Why not just calleding GetGCMStatistics with false
juyik
2014/05/07 00:07:48
Done.
| |
| 308 } | |
| 309 | |
| 299 void GCMService::IOWorker::Load(const base::WeakPtr<GCMService>& service) { | 310 void GCMService::IOWorker::Load(const base::WeakPtr<GCMService>& service) { |
| 300 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 311 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 301 | 312 |
| 302 service_ = service; | 313 service_ = service; |
| 303 gcm_client_->Load(); | 314 gcm_client_->Load(); |
| 304 } | 315 } |
| 305 | 316 |
| 306 void GCMService::IOWorker::Stop() { | 317 void GCMService::IOWorker::Stop() { |
| 307 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 318 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 308 | 319 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 335 void GCMService::IOWorker::Send(const std::string& app_id, | 346 void GCMService::IOWorker::Send(const std::string& app_id, |
| 336 const std::string& receiver_id, | 347 const std::string& receiver_id, |
| 337 const GCMClient::OutgoingMessage& message) { | 348 const GCMClient::OutgoingMessage& message) { |
| 338 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 349 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 339 | 350 |
| 340 gcm_client_->Send(app_id, receiver_id, message); | 351 gcm_client_->Send(app_id, receiver_id, message); |
| 341 } | 352 } |
| 342 | 353 |
| 343 void GCMService::IOWorker::GetGCMStatistics(bool clear_logs) { | 354 void GCMService::IOWorker::GetGCMStatistics(bool clear_logs) { |
| 344 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 355 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 345 gcm::GCMClient::GCMStatistics stats; | |
| 346 | 356 |
| 347 if (gcm_client_.get()) { | 357 if (gcm_client_.get()) { |
|
jianli
2014/05/06 22:54:53
It seems that there is behavior change when gcm_cl
juyik
2014/05/07 00:07:48
Done.
| |
| 348 if (clear_logs) | 358 if (clear_logs) |
| 349 gcm_client_->ClearActivityLogs(); | 359 gcm_client_->ClearActivityLogs(); |
| 360 DoGetGCMStatistics(); | |
| 361 } | |
| 362 } | |
| 363 | |
| 364 void GCMService::IOWorker::DoGetGCMStatistics() { | |
| 365 gcm::GCMClient::GCMStatistics stats; | |
| 366 | |
| 367 if (gcm_client_.get()) { | |
|
jianli
2014/05/06 22:54:53
nit: brackets not needed
juyik
2014/05/07 00:07:48
Done.
| |
| 350 stats = gcm_client_->GetStatistics(); | 368 stats = gcm_client_->GetStatistics(); |
| 351 } | 369 } |
| 352 | 370 |
| 353 content::BrowserThread::PostTask( | 371 content::BrowserThread::PostTask( |
| 354 content::BrowserThread::UI, | 372 content::BrowserThread::UI, |
| 355 FROM_HERE, | 373 FROM_HERE, |
| 356 base::Bind(&GCMService::GetGCMStatisticsFinished, service_, stats)); | 374 base::Bind(&GCMService::GetGCMStatisticsFinished, service_, stats)); |
| 357 } | 375 } |
| 358 | 376 |
| 359 void GCMService::IOWorker::SetGCMRecording(bool recording) { | 377 void GCMService::IOWorker::SetGCMRecording(bool recording) { |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; | 859 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; |
| 842 } | 860 } |
| 843 | 861 |
| 844 void GCMService::GetGCMStatisticsFinished( | 862 void GCMService::GetGCMStatisticsFinished( |
| 845 GCMClient::GCMStatistics stats) { | 863 GCMClient::GCMStatistics stats) { |
| 846 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 864 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 847 request_gcm_statistics_callback_.Run(stats); | 865 request_gcm_statistics_callback_.Run(stats); |
| 848 } | 866 } |
| 849 | 867 |
| 850 } // namespace gcm | 868 } // namespace gcm |
| OLD | NEW |