| 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 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 30 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 31 #include "chrome/common/chrome_version_info.h" | 31 #include "chrome/common/chrome_version_info.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "components/user_prefs/pref_registry_syncable.h" | 33 #include "components/user_prefs/pref_registry_syncable.h" |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
| 36 #include "content/public/browser/notification_source.h" | 36 #include "content/public/browser/notification_source.h" |
| 37 #include "extensions/browser/extension_system.h" | 37 #include "extensions/browser/extension_system.h" |
| 38 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
| 39 #include "google_apis/gcm/gcm_client.h" |
| 39 #include "google_apis/gcm/protocol/android_checkin.pb.h" | 40 #include "google_apis/gcm/protocol/android_checkin.pb.h" |
| 40 #include "net/url_request/url_request_context_getter.h" | 41 #include "net/url_request/url_request_context_getter.h" |
| 41 | 42 |
| 42 using extensions::Extension; | 43 using extensions::Extension; |
| 43 | 44 |
| 44 namespace gcm { | 45 namespace gcm { |
| 45 | 46 |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 const char kRegistrationKey[] = "gcm.registration"; | 49 const char kRegistrationKey[] = "gcm.registration"; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 url_request_context_getter); | 266 url_request_context_getter); |
| 266 void Reset(); | 267 void Reset(); |
| 267 void CheckOut(); | 268 void CheckOut(); |
| 268 void Register(const std::string& app_id, | 269 void Register(const std::string& app_id, |
| 269 const std::vector<std::string>& sender_ids, | 270 const std::vector<std::string>& sender_ids, |
| 270 const std::string& cert); | 271 const std::string& cert); |
| 271 void Unregister(const std::string& app_id); | 272 void Unregister(const std::string& app_id); |
| 272 void Send(const std::string& app_id, | 273 void Send(const std::string& app_id, |
| 273 const std::string& receiver_id, | 274 const std::string& receiver_id, |
| 274 const GCMClient::OutgoingMessage& message); | 275 const GCMClient::OutgoingMessage& message); |
| 276 bool IsGCMClientCreated(); |
| 277 void RequestGCMStatistics(); |
| 275 | 278 |
| 276 private: | 279 private: |
| 277 friend class base::RefCountedThreadSafe<IOWorker>; | 280 friend class base::RefCountedThreadSafe<IOWorker>; |
| 278 virtual ~IOWorker(); | 281 virtual ~IOWorker(); |
| 279 | 282 |
| 280 const base::WeakPtr<GCMProfileService> service_; | 283 const base::WeakPtr<GCMProfileService> service_; |
| 281 | 284 |
| 282 scoped_ptr<GCMClient> gcm_client_; | 285 scoped_ptr<GCMClient> gcm_client_; |
| 283 }; | 286 }; |
| 284 | 287 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 450 |
| 448 void GCMProfileService::IOWorker::Send( | 451 void GCMProfileService::IOWorker::Send( |
| 449 const std::string& app_id, | 452 const std::string& app_id, |
| 450 const std::string& receiver_id, | 453 const std::string& receiver_id, |
| 451 const GCMClient::OutgoingMessage& message) { | 454 const GCMClient::OutgoingMessage& message) { |
| 452 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 455 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 453 | 456 |
| 454 gcm_client_->Send(app_id, receiver_id, message); | 457 gcm_client_->Send(app_id, receiver_id, message); |
| 455 } | 458 } |
| 456 | 459 |
| 460 bool GCMProfileService::IOWorker::IsGCMClientCreated() { |
| 461 return (gcm_client_.get() != NULL); |
| 462 } |
| 463 |
| 464 void GCMProfileService::IOWorker::RequestGCMStatistics() { |
| 465 gcm::GCMClient::GCMStatistics stats; |
| 466 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 467 |
| 468 stats.gcm_client_created = (gcm_client_.get() != NULL); |
| 469 if (gcm_client_.get()) { |
| 470 gcm_client_->GetStatistics(&stats); |
| 471 } |
| 472 |
| 473 content::BrowserThread::PostTask( |
| 474 content::BrowserThread::UI, |
| 475 FROM_HERE, |
| 476 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished, |
| 477 service_, |
| 478 stats)); |
| 479 } |
| 480 |
| 457 GCMProfileService::RegistrationInfo::RegistrationInfo() { | 481 GCMProfileService::RegistrationInfo::RegistrationInfo() { |
| 458 } | 482 } |
| 459 | 483 |
| 460 GCMProfileService::RegistrationInfo::~RegistrationInfo() { | 484 GCMProfileService::RegistrationInfo::~RegistrationInfo() { |
| 461 } | 485 } |
| 462 | 486 |
| 463 bool GCMProfileService::RegistrationInfo::IsValid() const { | 487 bool GCMProfileService::RegistrationInfo::IsValid() const { |
| 464 return !sender_ids.empty() && !registration_id.empty(); | 488 return !sender_ids.empty() && !registration_id.empty(); |
| 465 } | 489 } |
| 466 | 490 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 content::BrowserThread::PostTask( | 697 content::BrowserThread::PostTask( |
| 674 content::BrowserThread::IO, | 698 content::BrowserThread::IO, |
| 675 FROM_HERE, | 699 FROM_HERE, |
| 676 base::Bind(&GCMProfileService::IOWorker::Send, | 700 base::Bind(&GCMProfileService::IOWorker::Send, |
| 677 io_worker_, | 701 io_worker_, |
| 678 app_id, | 702 app_id, |
| 679 receiver_id, | 703 receiver_id, |
| 680 message)); | 704 message)); |
| 681 } | 705 } |
| 682 | 706 |
| 707 bool GCMProfileService::IsSignedIn() const { |
| 708 return !username_.empty(); |
| 709 } |
| 710 |
| 711 bool GCMProfileService::IsGCMClientCreated() const { |
| 712 return io_worker_->IsGCMClientCreated(); |
| 713 } |
| 714 |
| 715 bool GCMProfileService::IsGCMClientReady() const { |
| 716 return gcm_client_ready_; |
| 717 } |
| 718 |
| 719 void GCMProfileService::RequestGCMStatistics( |
| 720 RequestGCMStatisticsCallback callback) { |
| 721 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 722 DCHECK(!callback.is_null()); |
| 723 |
| 724 request_gcm_statistics_callback_ = callback; |
| 725 content::BrowserThread::PostTask( |
| 726 content::BrowserThread::IO, |
| 727 FROM_HERE, |
| 728 base::Bind(&GCMProfileService::IOWorker::RequestGCMStatistics, |
| 729 io_worker_)); |
| 730 } |
| 731 |
| 683 void GCMProfileService::Observe(int type, | 732 void GCMProfileService::Observe(int type, |
| 684 const content::NotificationSource& source, | 733 const content::NotificationSource& source, |
| 685 const content::NotificationDetails& details) { | 734 const content::NotificationDetails& details) { |
| 686 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 735 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 687 | 736 |
| 688 switch (type) { | 737 switch (type) { |
| 689 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 738 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
| 690 const GoogleServiceSigninSuccessDetails* signin_details = | 739 const GoogleServiceSigninSuccessDetails* signin_details = |
| 691 content::Details<GoogleServiceSigninSuccessDetails>(details).ptr(); | 740 content::Details<GoogleServiceSigninSuccessDetails>(details).ptr(); |
| 692 // This could be called multiple times when the password changed. | 741 // This could be called multiple times when the password changed. |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 for (size_t i = 0; i < senders_list->GetSize(); ++i) { | 1085 for (size_t i = 0; i < senders_list->GetSize(); ++i) { |
| 1037 std::string sender; | 1086 std::string sender; |
| 1038 if (!senders_list->GetString(i, &sender)) | 1087 if (!senders_list->GetString(i, &sender)) |
| 1039 return false; | 1088 return false; |
| 1040 registration_info->sender_ids.push_back(sender); | 1089 registration_info->sender_ids.push_back(sender); |
| 1041 } | 1090 } |
| 1042 | 1091 |
| 1043 return true; | 1092 return true; |
| 1044 } | 1093 } |
| 1045 | 1094 |
| 1095 void GCMProfileService::RequestGCMStatisticsFinished( |
| 1096 GCMClient::GCMStatistics stats) { |
| 1097 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 1098 |
| 1099 request_gcm_statistics_callback_.Run(stats); |
| 1100 } |
| 1101 |
| 1046 // static | 1102 // static |
| 1047 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { | 1103 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { |
| 1048 return kRegistrationKey; | 1104 return kRegistrationKey; |
| 1049 } | 1105 } |
| 1050 | 1106 |
| 1051 } // namespace gcm | 1107 } // namespace gcm |
| OLD | NEW |