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