Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1293)

Side by Side Diff: chrome/browser/services/gcm/gcm_profile_service.cc

Issue 179043005: [GCM] Remove the requirement for manifest key (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove cert Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Called on IO thread. 260 // Called on IO thread.
261 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory, 261 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory,
262 const base::FilePath& store_path, 262 const base::FilePath& store_path,
263 const std::vector<std::string>& account_ids, 263 const std::vector<std::string>& account_ids,
264 const scoped_refptr<net::URLRequestContextGetter>& 264 const scoped_refptr<net::URLRequestContextGetter>&
265 url_request_context_getter); 265 url_request_context_getter);
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);
272 void Unregister(const std::string& app_id); 271 void Unregister(const std::string& app_id);
273 void Send(const std::string& app_id, 272 void Send(const std::string& app_id,
274 const std::string& receiver_id, 273 const std::string& receiver_id,
275 const GCMClient::OutgoingMessage& message); 274 const GCMClient::OutgoingMessage& message);
276 275
277 // For testing purpose. Can be called from UI thread. Use with care. 276 // For testing purpose. Can be called from UI thread. Use with care.
278 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 277 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
279 278
280 private: 279 private:
281 friend class base::RefCountedThreadSafe<IOWorker>; 280 friend class base::RefCountedThreadSafe<IOWorker>;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 429 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
431 430
432 gcm_client_->CheckOut(); 431 gcm_client_->CheckOut();
433 432
434 // Note that we still need to keep GCMClient instance alive since the profile 433 // Note that we still need to keep GCMClient instance alive since the profile
435 // might be signed in again. 434 // might be signed in again.
436 } 435 }
437 436
438 void GCMProfileService::IOWorker::Register( 437 void GCMProfileService::IOWorker::Register(
439 const std::string& app_id, 438 const std::string& app_id,
440 const std::vector<std::string>& sender_ids, 439 const std::vector<std::string>& sender_ids) {
441 const std::string& cert) {
442 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 440 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
443 441
444 gcm_client_->Register(app_id, cert, sender_ids); 442 gcm_client_->Register(app_id, sender_ids);
445 } 443 }
446 444
447 void GCMProfileService::IOWorker::Unregister(const std::string& app_id) { 445 void GCMProfileService::IOWorker::Unregister(const std::string& app_id) {
448 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 446 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
449 447
450 gcm_client_->Unregister(app_id); 448 gcm_client_->Unregister(app_id);
451 } 449 }
452 450
453 void GCMProfileService::IOWorker::Send( 451 void GCMProfileService::IOWorker::Send(
454 const std::string& app_id, 452 const std::string& app_id,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 url_request_context_getter)); 552 url_request_context_getter));
555 553
556 // Load from the GCM store and initiate the GCM check-in if the rollout signal 554 // Load from the GCM store and initiate the GCM check-in if the rollout signal
557 // indicates yes. 555 // indicates yes.
558 if (GetGCMEnabledState(profile_) == ALWAYS_ENABLED) 556 if (GetGCMEnabledState(profile_) == ALWAYS_ENABLED)
559 EnsureLoaded(); 557 EnsureLoaded();
560 } 558 }
561 559
562 void GCMProfileService::Register(const std::string& app_id, 560 void GCMProfileService::Register(const std::string& app_id,
563 const std::vector<std::string>& sender_ids, 561 const std::vector<std::string>& sender_ids,
564 const std::string& cert,
565 RegisterCallback callback) { 562 RegisterCallback callback) {
566 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 563 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
567 DCHECK(!app_id.empty() && !sender_ids.empty() && !callback.is_null()); 564 DCHECK(!app_id.empty() && !sender_ids.empty() && !callback.is_null());
568 565
569 // Ensure that check-in has been done. 566 // Ensure that check-in has been done.
570 EnsureLoaded(); 567 EnsureLoaded();
571 568
572 // If the profile was not signed in, bail out. 569 // If the profile was not signed in, bail out.
573 if (username_.empty()) { 570 if (username_.empty()) {
574 callback.Run(std::string(), GCMClient::NOT_SIGNED_IN); 571 callback.Run(std::string(), GCMClient::NOT_SIGNED_IN);
(...skipping 10 matching lines...) Expand all
585 582
586 EnsureAppReady(app_id); 583 EnsureAppReady(app_id);
587 584
588 // Delay the register operation until GCMClient is ready. 585 // Delay the register operation until GCMClient is ready.
589 if (!delayed_task_controller_->CanRunTaskWithoutDelay(app_id)) { 586 if (!delayed_task_controller_->CanRunTaskWithoutDelay(app_id)) {
590 delayed_task_controller_->AddTask( 587 delayed_task_controller_->AddTask(
591 app_id, 588 app_id,
592 base::Bind(&GCMProfileService::DoRegister, 589 base::Bind(&GCMProfileService::DoRegister,
593 weak_ptr_factory_.GetWeakPtr(), 590 weak_ptr_factory_.GetWeakPtr(),
594 app_id, 591 app_id,
595 sender_ids, 592 sender_ids));
596 cert));
597 return; 593 return;
598 } 594 }
599 595
600 DoRegister(app_id, sender_ids, cert); 596 DoRegister(app_id, sender_ids);
601 } 597 }
602 598
603 void GCMProfileService::DoRegister(const std::string& app_id, 599 void GCMProfileService::DoRegister(const std::string& app_id,
604 const std::vector<std::string>& sender_ids, 600 const std::vector<std::string>& sender_ids) {
605 const std::string& cert) {
606 std::map<std::string, RegisterCallback>::iterator callback_iter = 601 std::map<std::string, RegisterCallback>::iterator callback_iter =
607 register_callbacks_.find(app_id); 602 register_callbacks_.find(app_id);
608 if (callback_iter == register_callbacks_.end()) { 603 if (callback_iter == register_callbacks_.end()) {
609 // The callback could have been removed when the app is uninstalled. 604 // The callback could have been removed when the app is uninstalled.
610 return; 605 return;
611 } 606 }
612 607
613 // Normalize the sender IDs by making them sorted. 608 // Normalize the sender IDs by making them sorted.
614 std::vector<std::string> normalized_sender_ids = sender_ids; 609 std::vector<std::string> normalized_sender_ids = sender_ids;
615 std::sort(normalized_sender_ids.begin(), normalized_sender_ids.end()); 610 std::sort(normalized_sender_ids.begin(), normalized_sender_ids.end());
(...skipping 20 matching lines...) Expand all
636 // Save the IDs of all registered apps such that we know what to remove from 631 // Save the IDs of all registered apps such that we know what to remove from
637 // the the app's state store when the profile is signed out. 632 // the the app's state store when the profile is signed out.
638 WriteRegisteredAppIDs(); 633 WriteRegisteredAppIDs();
639 634
640 content::BrowserThread::PostTask( 635 content::BrowserThread::PostTask(
641 content::BrowserThread::IO, 636 content::BrowserThread::IO,
642 FROM_HERE, 637 FROM_HERE,
643 base::Bind(&GCMProfileService::IOWorker::Register, 638 base::Bind(&GCMProfileService::IOWorker::Register,
644 io_worker_, 639 io_worker_,
645 app_id, 640 app_id,
646 normalized_sender_ids, 641 normalized_sender_ids));
647 cert));
648 } 642 }
649 643
650 void GCMProfileService::Send(const std::string& app_id, 644 void GCMProfileService::Send(const std::string& app_id,
651 const std::string& receiver_id, 645 const std::string& receiver_id,
652 const GCMClient::OutgoingMessage& message, 646 const GCMClient::OutgoingMessage& message,
653 SendCallback callback) { 647 SendCallback callback) {
654 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 648 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
655 DCHECK(!app_id.empty() && !receiver_id.empty() && !callback.is_null()); 649 DCHECK(!app_id.empty() && !receiver_id.empty() && !callback.is_null());
656 650
657 // Ensure that check-in has been done. 651 // Ensure that check-in has been done.
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 1063
1070 return true; 1064 return true;
1071 } 1065 }
1072 1066
1073 // static 1067 // static
1074 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { 1068 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() {
1075 return kRegistrationKey; 1069 return kRegistrationKey;
1076 } 1070 }
1077 1071
1078 } // namespace gcm 1072 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_profile_service.h ('k') | chrome/browser/services/gcm/gcm_profile_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698