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