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

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

Issue 823993003: Push API: Remove AddAppHandlerIfNecessary to prevent DCHECK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 requesting_origin, service_worker_registration_id); 240 requesting_origin, service_worker_registration_id);
241 DCHECK(application_id.IsValid()); 241 DCHECK(application_id.IsValid());
242 242
243 if (push_registration_count_ >= kMaxRegistrations) { 243 if (push_registration_count_ >= kMaxRegistrations) {
244 RegisterEnd(callback, 244 RegisterEnd(callback,
245 std::string(), 245 std::string(),
246 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED); 246 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED);
247 return; 247 return;
248 } 248 }
249 249
250 // TODO(johnme): This is probably redundant due to
251 // https://codereview.chromium.org/756063002, or even if it isn't it'll
252 // interfere with auto-removing the app handler, so should be removed.
253 // If this is registering for the first time then the driver does not have
254 // this as an app handler and registration would fail.
255 AddAppHandlerIfNecessary();
256
257 content::RenderFrameHost* render_frame_host = 250 content::RenderFrameHost* render_frame_host =
258 content::RenderFrameHost::FromID(renderer_id, render_frame_id); 251 content::RenderFrameHost::FromID(renderer_id, render_frame_id);
259 if (!render_frame_host) 252 if (!render_frame_host)
260 return; 253 return;
261 254
262 content::WebContents* web_contents = 255 content::WebContents* web_contents =
263 content::WebContents::FromRenderFrameHost(render_frame_host); 256 content::WebContents::FromRenderFrameHost(render_frame_host);
264 if (!web_contents) 257 if (!web_contents)
265 return; 258 return;
266 259
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 requesting_origin, service_worker_registration_id); 301 requesting_origin, service_worker_registration_id);
309 DCHECK(application_id.IsValid()); 302 DCHECK(application_id.IsValid());
310 303
311 if (profile_->GetPrefs()->GetInteger( 304 if (profile_->GetPrefs()->GetInteger(
312 prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) { 305 prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) {
313 RegisterEnd(register_callback, std::string(), 306 RegisterEnd(register_callback, std::string(),
314 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED); 307 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED);
315 return; 308 return;
316 } 309 }
317 310
318 // If this is registering for the first time then the driver does not have
319 // this as an app handler and registration would fail.
320 AddAppHandlerIfNecessary();
321
322 GURL embedding_origin = requesting_origin; 311 GURL embedding_origin = requesting_origin;
323 blink::WebPushPermissionStatus permission_status = 312 blink::WebPushPermissionStatus permission_status =
324 PushMessagingServiceImpl::GetPermissionStatus(requesting_origin, 313 PushMessagingServiceImpl::GetPermissionStatus(requesting_origin,
325 embedding_origin); 314 embedding_origin);
326 if (permission_status != blink::WebPushPermissionStatusGranted) { 315 if (permission_status != blink::WebPushPermissionStatusGranted) {
327 RegisterEnd(register_callback, std::string(), 316 RegisterEnd(register_callback, std::string(),
328 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); 317 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
329 return; 318 return;
330 } 319 }
331 320
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 438
450 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { 439 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) {
451 gcm::PushMessagingPermissionContext* permission_context = 440 gcm::PushMessagingPermissionContext* permission_context =
452 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); 441 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
453 DCHECK(permission_context); 442 DCHECK(permission_context);
454 443
455 return permission_context->GetPermissionStatus(origin, origin) == 444 return permission_context->GetPermissionStatus(origin, origin) ==
456 CONTENT_SETTING_ALLOW; 445 CONTENT_SETTING_ALLOW;
457 } 446 }
458 447
459 void PushMessagingServiceImpl::AddAppHandlerIfNecessary() {
460 if (gcm_profile_service_->driver()->GetAppHandler(
461 kPushMessagingApplicationIdPrefix) != this)
462 gcm_profile_service_->driver()->AddAppHandler(
463 kPushMessagingApplicationIdPrefix, this);
464 }
465
466 } // namespace gcm 448 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698