OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_profile_service.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 void Reset(); | 167 void Reset(); |
168 void Load(const base::WeakPtr<GCMProfileService>& service); | 168 void Load(const base::WeakPtr<GCMProfileService>& service); |
169 void Stop(); | 169 void Stop(); |
170 void CheckOut(); | 170 void CheckOut(); |
171 void Register(const std::string& app_id, | 171 void Register(const std::string& app_id, |
172 const std::vector<std::string>& sender_ids); | 172 const std::vector<std::string>& sender_ids); |
173 void Unregister(const std::string& app_id); | 173 void Unregister(const std::string& app_id); |
174 void Send(const std::string& app_id, | 174 void Send(const std::string& app_id, |
175 const std::string& receiver_id, | 175 const std::string& receiver_id, |
176 const GCMClient::OutgoingMessage& message); | 176 const GCMClient::OutgoingMessage& message); |
177 void RequestGCMStatistics(); | 177 void GetGCMStatistics(bool clear_logs); |
| 178 void SetGCMRecording(bool recording); |
178 | 179 |
179 // For testing purpose. Can be called from UI thread. Use with care. | 180 // For testing purpose. Can be called from UI thread. Use with care. |
180 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 181 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
181 | 182 |
182 private: | 183 private: |
183 friend class base::RefCountedThreadSafe<IOWorker>; | 184 friend class base::RefCountedThreadSafe<IOWorker>; |
184 virtual ~IOWorker(); | 185 virtual ~IOWorker(); |
185 | 186 |
186 base::WeakPtr<GCMProfileService> service_; | 187 base::WeakPtr<GCMProfileService> service_; |
187 | 188 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 364 |
364 void GCMProfileService::IOWorker::Send( | 365 void GCMProfileService::IOWorker::Send( |
365 const std::string& app_id, | 366 const std::string& app_id, |
366 const std::string& receiver_id, | 367 const std::string& receiver_id, |
367 const GCMClient::OutgoingMessage& message) { | 368 const GCMClient::OutgoingMessage& message) { |
368 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 369 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
369 | 370 |
370 gcm_client_->Send(app_id, receiver_id, message); | 371 gcm_client_->Send(app_id, receiver_id, message); |
371 } | 372 } |
372 | 373 |
373 void GCMProfileService::IOWorker::RequestGCMStatistics() { | 374 void GCMProfileService::IOWorker::GetGCMStatistics(bool clear_logs) { |
374 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 375 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
375 gcm::GCMClient::GCMStatistics stats; | 376 gcm::GCMClient::GCMStatistics stats; |
376 | 377 |
377 if (gcm_client_.get()) { | 378 if (gcm_client_.get()) { |
378 stats.gcm_client_created = true; | 379 if (clear_logs) |
| 380 gcm_client_->ClearActivityLogs(); |
379 stats = gcm_client_->GetStatistics(); | 381 stats = gcm_client_->GetStatistics(); |
380 } | 382 } |
381 | 383 |
382 content::BrowserThread::PostTask( | 384 content::BrowserThread::PostTask( |
383 content::BrowserThread::UI, | 385 content::BrowserThread::UI, |
384 FROM_HERE, | 386 FROM_HERE, |
385 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished, | 387 base::Bind(&GCMProfileService::GetGCMStatisticsFinished, |
386 service_, | 388 service_, |
387 stats)); | 389 stats)); |
388 } | 390 } |
| 391 |
| 392 void GCMProfileService::IOWorker::SetGCMRecording(bool recording) { |
| 393 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 394 gcm::GCMClient::GCMStatistics stats; |
| 395 |
| 396 if (gcm_client_.get()) { |
| 397 gcm_client_->SetRecording(recording); |
| 398 stats = gcm_client_->GetStatistics(); |
| 399 stats.gcm_client_created = true; |
| 400 } |
| 401 |
| 402 content::BrowserThread::PostTask( |
| 403 content::BrowserThread::UI, |
| 404 FROM_HERE, |
| 405 base::Bind(&GCMProfileService::GetGCMStatisticsFinished, |
| 406 service_, |
| 407 stats)); |
| 408 } |
389 | 409 |
390 std::string GCMProfileService::GetGCMEnabledStateString(GCMEnabledState state) { | 410 std::string GCMProfileService::GetGCMEnabledStateString(GCMEnabledState state) { |
391 switch (state) { | 411 switch (state) { |
392 case GCMProfileService::ALWAYS_ENABLED: | 412 case GCMProfileService::ALWAYS_ENABLED: |
393 return "ALWAYS_ENABLED"; | 413 return "ALWAYS_ENABLED"; |
394 case GCMProfileService::ENABLED_FOR_APPS: | 414 case GCMProfileService::ENABLED_FOR_APPS: |
395 return "ENABLED_FOR_APPS"; | 415 return "ENABLED_FOR_APPS"; |
396 case GCMProfileService::ALWAYS_DISABLED: | 416 case GCMProfileService::ALWAYS_DISABLED: |
397 return "ALWAYS_DISABLED"; | 417 return "ALWAYS_DISABLED"; |
398 default: | 418 default: |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 } | 699 } |
680 | 700 |
681 std::string GCMProfileService::SignedInUserName() const { | 701 std::string GCMProfileService::SignedInUserName() const { |
682 return username_; | 702 return username_; |
683 } | 703 } |
684 | 704 |
685 bool GCMProfileService::IsGCMClientReady() const { | 705 bool GCMProfileService::IsGCMClientReady() const { |
686 return gcm_client_ready_; | 706 return gcm_client_ready_; |
687 } | 707 } |
688 | 708 |
689 void GCMProfileService::RequestGCMStatistics( | 709 void GCMProfileService::GetGCMStatistics( |
690 RequestGCMStatisticsCallback callback) { | 710 GetGCMStatisticsCallback callback, bool clear_logs) { |
691 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 711 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
692 DCHECK(!callback.is_null()); | 712 DCHECK(!callback.is_null()); |
693 | 713 |
694 request_gcm_statistics_callback_ = callback; | 714 request_gcm_statistics_callback_ = callback; |
695 content::BrowserThread::PostTask( | 715 content::BrowserThread::PostTask( |
696 content::BrowserThread::IO, | 716 content::BrowserThread::IO, |
697 FROM_HERE, | 717 FROM_HERE, |
698 base::Bind(&GCMProfileService::IOWorker::RequestGCMStatistics, | 718 base::Bind(&GCMProfileService::IOWorker::GetGCMStatistics, |
699 io_worker_)); | 719 io_worker_, |
| 720 clear_logs)); |
| 721 } |
| 722 |
| 723 void GCMProfileService::SetGCMRecording( |
| 724 GetGCMStatisticsCallback callback, bool recording) { |
| 725 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 726 |
| 727 request_gcm_statistics_callback_ = callback; |
| 728 content::BrowserThread::PostTask( |
| 729 content::BrowserThread::IO, |
| 730 FROM_HERE, |
| 731 base::Bind(&GCMProfileService::IOWorker::SetGCMRecording, |
| 732 io_worker_, |
| 733 recording)); |
700 } | 734 } |
701 | 735 |
702 void GCMProfileService::Observe(int type, | 736 void GCMProfileService::Observe(int type, |
703 const content::NotificationSource& source, | 737 const content::NotificationSource& source, |
704 const content::NotificationDetails& details) { | 738 const content::NotificationDetails& details) { |
705 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 739 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
706 | 740 |
707 switch (type) { | 741 switch (type) { |
708 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 742 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
709 ResetGCMClient(); | 743 ResetGCMClient(); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 | 929 |
896 delayed_task_controller_->SetReady(); | 930 delayed_task_controller_->SetReady(); |
897 } | 931 } |
898 | 932 |
899 GCMAppHandler* GCMProfileService::GetAppHandler(const std::string& app_id) { | 933 GCMAppHandler* GCMProfileService::GetAppHandler(const std::string& app_id) { |
900 std::map<std::string, GCMAppHandler*>::const_iterator iter = | 934 std::map<std::string, GCMAppHandler*>::const_iterator iter = |
901 app_handlers_.find(app_id); | 935 app_handlers_.find(app_id); |
902 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; | 936 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; |
903 } | 937 } |
904 | 938 |
905 void GCMProfileService::RequestGCMStatisticsFinished( | 939 void GCMProfileService::GetGCMStatisticsFinished( |
906 GCMClient::GCMStatistics stats) { | 940 GCMClient::GCMStatistics stats) { |
907 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 941 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
908 | |
909 request_gcm_statistics_callback_.Run(stats); | 942 request_gcm_statistics_callback_.Run(stats); |
910 } | 943 } |
911 | 944 |
912 } // namespace gcm | 945 } // namespace gcm |
OLD | NEW |