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

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

Issue 931113003: [Push] Use proper accessors for PushMessagingApplicationId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/services/gcm/push_messaging_service_impl.h" 5 #include "chrome/browser/services/gcm/push_messaging_service_impl.h"
6 6
7 #include <bitset> 7 #include <bitset>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 const GCMClient::IncomingMessage& message) { 184 const GCMClient::IncomingMessage& message) {
185 PushMessagingApplicationId application_id = 185 PushMessagingApplicationId application_id =
186 PushMessagingApplicationId::Get(profile_, app_id); 186 PushMessagingApplicationId::Get(profile_, app_id);
187 // Drop message and unregister if app id was unknown (maybe recently deleted). 187 // Drop message and unregister if app id was unknown (maybe recently deleted).
188 if (!application_id.IsValid()) { 188 if (!application_id.IsValid()) {
189 DeliverMessageCallback(app_id, GURL::EmptyGURL(), -1, message, 189 DeliverMessageCallback(app_id, GURL::EmptyGURL(), -1, message,
190 content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID); 190 content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID);
191 return; 191 return;
192 } 192 }
193 // Drop message and unregister if |origin| has lost push permission. 193 // Drop message and unregister if |origin| has lost push permission.
194 if (!HasPermission(application_id.origin)) { 194 if (!HasPermission(application_id.origin())) {
195 DeliverMessageCallback(app_id, application_id.origin, 195 DeliverMessageCallback(app_id, application_id.origin(),
196 application_id.service_worker_registration_id, 196 application_id.service_worker_registration_id(),
197 message, 197 message,
198 content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED); 198 content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED);
199 return; 199 return;
200 } 200 }
201 201
202 // The Push API only exposes a single string of data in the push event fired 202 // The Push API only exposes a single string of data in the push event fired
203 // on the Service Worker. When developers send messages using GCM to the Push 203 // on the Service Worker. When developers send messages using GCM to the Push
204 // API and want to include a message payload, they must pass a single key- 204 // API and want to include a message payload, they must pass a single key-
205 // value pair, where the key is "data" and the value is the string they want 205 // value pair, where the key is "data" and the value is the string they want
206 // to be passed to their Service Worker. For example, they could send the 206 // to be passed to their Service Worker. For example, they could send the
(...skipping 11 matching lines...) Expand all
218 // https://crbug.com/449184 218 // https://crbug.com/449184
219 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 219 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
220 switches::kEnablePushMessagePayload)) { 220 switches::kEnablePushMessagePayload)) {
221 GCMClient::MessageData::const_iterator it = message.data.find("data"); 221 GCMClient::MessageData::const_iterator it = message.data.find("data");
222 if (it != message.data.end()) 222 if (it != message.data.end())
223 data = it->second; 223 data = it->second;
224 } 224 }
225 225
226 content::BrowserContext::DeliverPushMessage( 226 content::BrowserContext::DeliverPushMessage(
227 profile_, 227 profile_,
228 application_id.origin, 228 application_id.origin(),
229 application_id.service_worker_registration_id, 229 application_id.service_worker_registration_id(),
230 data, 230 data,
231 base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback, 231 base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback,
232 weak_factory_.GetWeakPtr(), 232 weak_factory_.GetWeakPtr(),
233 application_id.app_id_guid, application_id.origin, 233 application_id.app_id_guid(), application_id.origin(),
234 application_id.service_worker_registration_id, message)); 234 application_id.service_worker_registration_id(), message));
235 } 235 }
236 236
237 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { 237 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) {
238 profile_ = profile; 238 profile_ = profile;
239 } 239 }
240 240
241 void PushMessagingServiceImpl::DeliverMessageCallback( 241 void PushMessagingServiceImpl::DeliverMessageCallback(
242 const std::string& app_id_guid, 242 const std::string& app_id_guid,
243 const GURL& requesting_origin, 243 const GURL& requesting_origin,
244 int64 service_worker_registration_id, 244 int64 service_worker_registration_id,
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 embedding_origin); 543 embedding_origin);
544 if (permission_status != blink::WebPushPermissionStatusGranted) { 544 if (permission_status != blink::WebPushPermissionStatusGranted) {
545 RegisterEnd(register_callback, std::string(), 545 RegisterEnd(register_callback, std::string(),
546 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); 546 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
547 return; 547 return;
548 } 548 }
549 549
550 IncreasePushRegistrationCount(1, true /* is_pending */); 550 IncreasePushRegistrationCount(1, true /* is_pending */);
551 std::vector<std::string> sender_ids(1, sender_id); 551 std::vector<std::string> sender_ids(1, sender_id);
552 gcm_profile_service_->driver()->Register( 552 gcm_profile_service_->driver()->Register(
553 application_id.app_id_guid, sender_ids, 553 application_id.app_id_guid(), sender_ids,
554 base::Bind(&PushMessagingServiceImpl::DidRegister, 554 base::Bind(&PushMessagingServiceImpl::DidRegister,
555 weak_factory_.GetWeakPtr(), 555 weak_factory_.GetWeakPtr(),
556 application_id, register_callback)); 556 application_id, register_callback));
557 } 557 }
558 558
559 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( 559 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
560 const GURL& requesting_origin, 560 const GURL& requesting_origin,
561 const GURL& embedding_origin) { 561 const GURL& embedding_origin) {
562 PushMessagingPermissionContext* permission_context = 562 PushMessagingPermissionContext* permission_context =
563 PushMessagingPermissionContextFactory::GetForProfile(profile_); 563 PushMessagingPermissionContextFactory::GetForProfile(profile_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 return; 600 return;
601 } 601 }
602 602
603 // The GCMDriver could be NULL if GCMProfileService has been shut down. 603 // The GCMDriver could be NULL if GCMProfileService has been shut down.
604 if (!gcm_profile_service_->driver()) 604 if (!gcm_profile_service_->driver())
605 return; 605 return;
606 606
607 IncreasePushRegistrationCount(1, true /* is_pending */); 607 IncreasePushRegistrationCount(1, true /* is_pending */);
608 std::vector<std::string> sender_ids(1, sender_id); 608 std::vector<std::string> sender_ids(1, sender_id);
609 gcm_profile_service_->driver()->Register( 609 gcm_profile_service_->driver()->Register(
610 application_id.app_id_guid, 610 application_id.app_id_guid(),
611 sender_ids, 611 sender_ids,
612 base::Bind(&PushMessagingServiceImpl::DidRegister, 612 base::Bind(&PushMessagingServiceImpl::DidRegister,
613 weak_factory_.GetWeakPtr(), 613 weak_factory_.GetWeakPtr(),
614 application_id, register_callback)); 614 application_id, register_callback));
615 } 615 }
616 616
617 void PushMessagingServiceImpl::Unregister( 617 void PushMessagingServiceImpl::Unregister(
618 const GURL& requesting_origin, 618 const GURL& requesting_origin,
619 int64 service_worker_registration_id, 619 int64 service_worker_registration_id,
620 bool retry_on_failure, 620 bool retry_on_failure,
621 const content::PushMessagingService::UnregisterCallback& callback) { 621 const content::PushMessagingService::UnregisterCallback& callback) {
622 DCHECK(gcm_profile_service_->driver()); 622 DCHECK(gcm_profile_service_->driver());
623 623
624 PushMessagingApplicationId application_id = PushMessagingApplicationId::Get( 624 PushMessagingApplicationId application_id = PushMessagingApplicationId::Get(
625 profile_, requesting_origin, service_worker_registration_id); 625 profile_, requesting_origin, service_worker_registration_id);
626 if (!application_id.IsValid()) { 626 if (!application_id.IsValid()) {
627 callback.Run( 627 callback.Run(
628 content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED); 628 content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED);
629 return; 629 return;
630 } 630 }
631 631
632 Unregister(application_id.app_id_guid, retry_on_failure, callback); 632 Unregister(application_id.app_id_guid(), retry_on_failure, callback);
633 } 633 }
634 634
635 void PushMessagingServiceImpl::Unregister( 635 void PushMessagingServiceImpl::Unregister(
636 const std::string& app_id_guid, 636 const std::string& app_id_guid,
637 bool retry_on_failure, 637 bool retry_on_failure,
638 const content::PushMessagingService::UnregisterCallback& callback) { 638 const content::PushMessagingService::UnregisterCallback& callback) {
639 DCHECK(gcm_profile_service_->driver()); 639 DCHECK(gcm_profile_service_->driver());
640 640
641 if (retry_on_failure) { 641 if (retry_on_failure) {
642 // Delete the mapping for this app id, to guarantee that no messages get 642 // Delete the mapping for this app id, to guarantee that no messages get
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { 701 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) {
702 gcm::PushMessagingPermissionContext* permission_context = 702 gcm::PushMessagingPermissionContext* permission_context =
703 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); 703 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
704 DCHECK(permission_context); 704 DCHECK(permission_context);
705 705
706 return permission_context->GetPermissionStatus(origin, origin) == 706 return permission_context->GetPermissionStatus(origin, origin) ==
707 CONTENT_SETTING_ALLOW; 707 CONTENT_SETTING_ALLOW;
708 } 708 }
709 709
710 } // namespace gcm 710 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698