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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 void Reset(); | 266 void Reset(); |
267 void Load(const base::WeakPtr<GCMProfileService>& service); | 267 void Load(const base::WeakPtr<GCMProfileService>& service); |
268 void CheckOut(); | 268 void CheckOut(); |
269 void Register(const std::string& app_id, | 269 void Register(const std::string& app_id, |
270 const std::vector<std::string>& sender_ids, | 270 const std::vector<std::string>& sender_ids, |
271 const std::string& cert); | 271 const std::string& cert); |
272 void Unregister(const std::string& app_id); | 272 void Unregister(const std::string& app_id); |
273 void Send(const std::string& app_id, | 273 void Send(const std::string& app_id, |
274 const std::string& receiver_id, | 274 const std::string& receiver_id, |
275 const GCMClient::OutgoingMessage& message); | 275 const GCMClient::OutgoingMessage& message); |
276 bool IsGCMClientCreated(); | |
jianli
2014/03/06 01:55:21
It seems that none is calling it.
juyik
2014/03/06 02:23:59
Done.
| |
277 void RequestGCMStatistics(); | |
276 | 278 |
277 // For testing purpose. Can be called from UI thread. Use with care. | 279 // For testing purpose. Can be called from UI thread. Use with care. |
278 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 280 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
279 | 281 |
280 private: | 282 private: |
281 friend class base::RefCountedThreadSafe<IOWorker>; | 283 friend class base::RefCountedThreadSafe<IOWorker>; |
282 virtual ~IOWorker(); | 284 virtual ~IOWorker(); |
283 | 285 |
284 base::WeakPtr<GCMProfileService> service_; | 286 base::WeakPtr<GCMProfileService> service_; |
285 | 287 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 | 454 |
453 void GCMProfileService::IOWorker::Send( | 455 void GCMProfileService::IOWorker::Send( |
454 const std::string& app_id, | 456 const std::string& app_id, |
455 const std::string& receiver_id, | 457 const std::string& receiver_id, |
456 const GCMClient::OutgoingMessage& message) { | 458 const GCMClient::OutgoingMessage& message) { |
457 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 459 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
458 | 460 |
459 gcm_client_->Send(app_id, receiver_id, message); | 461 gcm_client_->Send(app_id, receiver_id, message); |
460 } | 462 } |
461 | 463 |
464 bool GCMProfileService::IOWorker::IsGCMClientCreated() { | |
465 return (gcm_client_.get() != NULL); | |
466 } | |
467 | |
468 void GCMProfileService::IOWorker::RequestGCMStatistics() { | |
469 gcm::GCMClient::GCMStatistics stats; | |
jianli
2014/03/06 01:55:21
nit: this should be placed after DCHECK.
juyik
2014/03/06 02:23:59
Done.
| |
470 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
471 | |
472 if (gcm_client_.get()) { | |
473 stats = gcm_client_->GetStatistics(); | |
474 } | |
475 stats.gcm_client_created = (gcm_client_.get() != NULL); | |
jianli
2014/03/06 01:55:21
this can be simply moved inside the if block above
juyik
2014/03/06 02:23:59
Done.
| |
476 | |
477 content::BrowserThread::PostTask( | |
478 content::BrowserThread::UI, | |
479 FROM_HERE, | |
480 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished, | |
481 service_, | |
482 stats)); | |
483 } | |
484 | |
485 std::string GCMProfileService::GetGCMEnabledStateString(GCMEnabledState state) { | |
486 switch (state) { | |
487 case GCMProfileService::ALWAYS_ENABLED: | |
488 return "ALWAYS_ENABLED"; | |
489 case GCMProfileService::ENABLED_FOR_APPS: | |
490 return "ENABLED_FOR_APPS"; | |
491 case GCMProfileService::ALWAYS_DISABLED: | |
492 return "ALWAYS_DISABLED"; | |
493 } | |
494 return std::string(); | |
jianli
2014/03/06 01:55:21
ditto
juyik
2014/03/06 02:23:59
Done.
| |
495 } | |
496 | |
462 GCMProfileService::RegistrationInfo::RegistrationInfo() { | 497 GCMProfileService::RegistrationInfo::RegistrationInfo() { |
463 } | 498 } |
464 | 499 |
465 GCMProfileService::RegistrationInfo::~RegistrationInfo() { | 500 GCMProfileService::RegistrationInfo::~RegistrationInfo() { |
466 } | 501 } |
467 | 502 |
468 bool GCMProfileService::RegistrationInfo::IsValid() const { | 503 bool GCMProfileService::RegistrationInfo::IsValid() const { |
469 return !sender_ids.empty() && !registration_id.empty(); | 504 return !sender_ids.empty() && !registration_id.empty(); |
470 } | 505 } |
471 | 506 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 io_worker_, | 733 io_worker_, |
699 app_id, | 734 app_id, |
700 receiver_id, | 735 receiver_id, |
701 message)); | 736 message)); |
702 } | 737 } |
703 | 738 |
704 GCMClient* GCMProfileService::GetGCMClientForTesting() const { | 739 GCMClient* GCMProfileService::GetGCMClientForTesting() const { |
705 return io_worker_ ? io_worker_->gcm_client_for_testing() : NULL; | 740 return io_worker_ ? io_worker_->gcm_client_for_testing() : NULL; |
706 } | 741 } |
707 | 742 |
743 bool GCMProfileService::IsSignedIn() const { | |
744 return !username_.empty(); | |
jianli
2014/03/06 01:55:21
This indeed means more than signed-in. We set |use
juyik
2014/03/06 02:23:59
In that case, I will just display the username her
| |
745 } | |
746 | |
747 bool GCMProfileService::IsGCMClientReady() const { | |
748 return gcm_client_ready_; | |
749 } | |
750 | |
751 void GCMProfileService::RequestGCMStatistics( | |
752 RequestGCMStatisticsCallback callback) { | |
753 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
754 DCHECK(!callback.is_null()); | |
755 | |
756 request_gcm_statistics_callback_ = callback; | |
757 content::BrowserThread::PostTask( | |
758 content::BrowserThread::IO, | |
759 FROM_HERE, | |
760 base::Bind(&GCMProfileService::IOWorker::RequestGCMStatistics, | |
761 io_worker_)); | |
762 } | |
763 | |
708 void GCMProfileService::Observe(int type, | 764 void GCMProfileService::Observe(int type, |
709 const content::NotificationSource& source, | 765 const content::NotificationSource& source, |
710 const content::NotificationDetails& details) { | 766 const content::NotificationDetails& details) { |
711 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 767 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
712 | 768 |
713 switch (type) { | 769 switch (type) { |
714 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 770 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
715 if (GetGCMEnabledState(profile_) == ALWAYS_ENABLED) | 771 if (GetGCMEnabledState(profile_) == ALWAYS_ENABLED) |
716 EnsureLoaded(); | 772 EnsureLoaded(); |
717 break; | 773 break; |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 for (size_t i = 0; i < senders_list->GetSize(); ++i) { | 1119 for (size_t i = 0; i < senders_list->GetSize(); ++i) { |
1064 std::string sender; | 1120 std::string sender; |
1065 if (!senders_list->GetString(i, &sender)) | 1121 if (!senders_list->GetString(i, &sender)) |
1066 return false; | 1122 return false; |
1067 registration_info->sender_ids.push_back(sender); | 1123 registration_info->sender_ids.push_back(sender); |
1068 } | 1124 } |
1069 | 1125 |
1070 return true; | 1126 return true; |
1071 } | 1127 } |
1072 | 1128 |
1129 void GCMProfileService::RequestGCMStatisticsFinished( | |
1130 GCMClient::GCMStatistics stats) { | |
1131 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
1132 | |
1133 request_gcm_statistics_callback_.Run(stats); | |
1134 } | |
1135 | |
1073 // static | 1136 // static |
1074 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { | 1137 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { |
1075 return kRegistrationKey; | 1138 return kRegistrationKey; |
1076 } | 1139 } |
1077 | 1140 |
1078 } // namespace gcm | 1141 } // namespace gcm |
OLD | NEW |