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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_service_impl.cc

Issue 1141613003: Push API: Include origin in generated app_ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ident_test
Patch Set: Add test for reading old values from prefs Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/push_messaging/push_messaging_service_impl.h" 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 DCHECK(push_registration_count_ >= 0); 138 DCHECK(push_registration_count_ >= 0);
139 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, 139 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount,
140 push_registration_count_); 140 push_registration_count_);
141 } 141 }
142 if (push_registration_count_ + pending_push_registration_count_ == 0) { 142 if (push_registration_count_ + pending_push_registration_count_ == 0) {
143 GetGCMDriver()->RemoveAppHandler(kPushMessagingAppIdentifierPrefix); 143 GetGCMDriver()->RemoveAppHandler(kPushMessagingAppIdentifierPrefix);
144 } 144 }
145 } 145 }
146 146
147 bool PushMessagingServiceImpl::CanHandle(const std::string& app_id) const { 147 bool PushMessagingServiceImpl::CanHandle(const std::string& app_id) const {
148 return !PushMessagingAppIdentifier::Get(profile_, app_id).is_null(); 148 return !PushMessagingAppIdentifier::FindByAppId(profile_, app_id).is_null();
149 } 149 }
150 150
151 void PushMessagingServiceImpl::ShutdownHandler() { 151 void PushMessagingServiceImpl::ShutdownHandler() {
152 // Shutdown() should come before and it removes us from the list of app 152 // Shutdown() should come before and it removes us from the list of app
153 // handlers of gcm::GCMDriver so this shouldn't ever been called. 153 // handlers of gcm::GCMDriver so this shouldn't ever been called.
154 NOTREACHED(); 154 NOTREACHED();
155 } 155 }
156 156
157 // OnMessage methods ----------------------------------------------------------- 157 // OnMessage methods -----------------------------------------------------------
158 158
159 void PushMessagingServiceImpl::OnMessage( 159 void PushMessagingServiceImpl::OnMessage(
160 const std::string& app_id, 160 const std::string& app_id,
161 const gcm::GCMClient::IncomingMessage& message) { 161 const gcm::GCMClient::IncomingMessage& message) {
162 base::Closure message_handled_closure = 162 base::Closure message_handled_closure =
163 message_callback_for_testing_.is_null() ? base::Bind(&base::DoNothing) 163 message_callback_for_testing_.is_null() ? base::Bind(&base::DoNothing)
164 : message_callback_for_testing_; 164 : message_callback_for_testing_;
165 PushMessagingAppIdentifier app_identifier = 165 PushMessagingAppIdentifier app_identifier =
166 PushMessagingAppIdentifier::Get(profile_, app_id); 166 PushMessagingAppIdentifier::FindByAppId(profile_, app_id);
167 // Drop message and unregister if app_id was unknown (maybe recently deleted). 167 // Drop message and unregister if app_id was unknown (maybe recently deleted).
168 if (app_identifier.is_null()) { 168 if (app_identifier.is_null()) {
169 DeliverMessageCallback(app_id, GURL::EmptyGURL(), -1, message, 169 DeliverMessageCallback(app_id, GURL::EmptyGURL(), -1, message,
170 message_handled_closure, 170 message_handled_closure,
171 content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID); 171 content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID);
172 return; 172 return;
173 } 173 }
174 // Drop message and unregister if |origin| has lost push permission. 174 // Drop message and unregister if |origin| has lost push permission.
175 if (!HasPermission(app_identifier.origin())) { 175 if (!HasPermission(app_identifier.origin())) {
176 DeliverMessageCallback(app_id, app_identifier.origin(), 176 DeliverMessageCallback(app_id, app_identifier.origin(),
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 app_identifier, register_callback)); 462 app_identifier, register_callback));
463 } 463 }
464 464
465 // Unregister methods ---------------------------------------------------------- 465 // Unregister methods ----------------------------------------------------------
466 466
467 void PushMessagingServiceImpl::Unregister( 467 void PushMessagingServiceImpl::Unregister(
468 const GURL& requesting_origin, 468 const GURL& requesting_origin,
469 int64 service_worker_registration_id, 469 int64 service_worker_registration_id,
470 const std::string& sender_id, 470 const std::string& sender_id,
471 const content::PushMessagingService::UnregisterCallback& callback) { 471 const content::PushMessagingService::UnregisterCallback& callback) {
472 PushMessagingAppIdentifier app_identifier = PushMessagingAppIdentifier::Get( 472 PushMessagingAppIdentifier app_identifier =
473 profile_, requesting_origin, service_worker_registration_id); 473 PushMessagingAppIdentifier::FindByServiceWorker(
474 profile_, requesting_origin, service_worker_registration_id);
474 if (app_identifier.is_null()) { 475 if (app_identifier.is_null()) {
475 if (!callback.is_null()) { 476 if (!callback.is_null()) {
476 callback.Run( 477 callback.Run(
477 content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED); 478 content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED);
478 } 479 }
479 return; 480 return;
480 } 481 }
481 482
482 Unregister(app_identifier.app_id(), sender_id, callback); 483 Unregister(app_identifier.app_id(), sender_id, callback);
483 } 484 }
484 485
485 void PushMessagingServiceImpl::Unregister( 486 void PushMessagingServiceImpl::Unregister(
486 const std::string& app_id, 487 const std::string& app_id,
487 const std::string& sender_id, 488 const std::string& sender_id,
488 const content::PushMessagingService::UnregisterCallback& callback) { 489 const content::PushMessagingService::UnregisterCallback& callback) {
489 // Delete the mapping for this app_id, to guarantee that no messages get 490 // Delete the mapping for this app_id, to guarantee that no messages get
490 // delivered in future (even if unregistration fails). 491 // delivered in future (even if unregistration fails).
491 // TODO(johnme): Instead of deleting these app ids, store them elsewhere, and 492 // TODO(johnme): Instead of deleting these app ids, store them elsewhere, and
492 // retry unregistration if it fails due to network errors (crbug.com/465399). 493 // retry unregistration if it fails due to network errors (crbug.com/465399).
493 PushMessagingAppIdentifier app_identifier = 494 PushMessagingAppIdentifier app_identifier =
494 PushMessagingAppIdentifier::Get(profile_, app_id); 495 PushMessagingAppIdentifier::FindByAppId(profile_, app_id);
495 bool was_registered = !app_identifier.is_null(); 496 bool was_registered = !app_identifier.is_null();
496 if (was_registered) 497 if (was_registered)
497 app_identifier.DeleteFromPrefs(profile_); 498 app_identifier.DeleteFromPrefs(profile_);
498 499
499 const auto& unregister_callback = 500 const auto& unregister_callback =
500 base::Bind(&PushMessagingServiceImpl::DidUnregister, 501 base::Bind(&PushMessagingServiceImpl::DidUnregister,
501 weak_factory_.GetWeakPtr(), 502 weak_factory_.GetWeakPtr(),
502 was_registered, callback); 503 was_registered, callback);
503 #if defined(OS_ANDROID) 504 #if defined(OS_ANDROID)
504 // On Android the backend is different, and requires the original sender_id. 505 // On Android the backend is different, and requires the original sender_id.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 CONTENT_SETTING_ALLOW; 639 CONTENT_SETTING_ALLOW;
639 } 640 }
640 641
641 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { 642 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const {
642 gcm::GCMProfileService* gcm_profile_service = 643 gcm::GCMProfileService* gcm_profile_service =
643 gcm::GCMProfileServiceFactory::GetForProfile(profile_); 644 gcm::GCMProfileServiceFactory::GetForProfile(profile_);
644 CHECK(gcm_profile_service); 645 CHECK(gcm_profile_service);
645 CHECK(gcm_profile_service->driver()); 646 CHECK(gcm_profile_service->driver());
646 return gcm_profile_service->driver(); 647 return gcm_profile_service->driver();
647 } 648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698