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

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

Issue 340773006: Dispatch push event to worker from PushServiceImpl#OnMessage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup. Created 6 years, 4 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 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"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "chrome/browser/content_settings/permission_request_id.h" 13 #include "chrome/browser/content_settings/permission_request_id.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/services/gcm/gcm_profile_service.h" 15 #include "chrome/browser/services/gcm/gcm_profile_service.h"
16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
17 #include "chrome/browser/services/gcm/push_messaging_application_id.h" 17 #include "chrome/browser/services/gcm/push_messaging_application_id.h"
18 #include "chrome/browser/services/gcm/push_messaging_permission_context.h" 18 #include "chrome/browser/services/gcm/push_messaging_permission_context.h"
19 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory. h" 19 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory. h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "components/gcm_driver/gcm_driver.h" 22 #include "components/gcm_driver/gcm_driver.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "content/public/browser/browser_context.h"
24 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 27
27 namespace gcm { 28 namespace gcm {
28 29
29 namespace { 30 namespace {
30 const int kMaxRegistrations = 1000000; 31 const int kMaxRegistrations = 1000000;
31 } // namespace 32 } // namespace
32 33
33 // static 34 // static
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // "data": "BAZ", 103 // "data": "BAZ",
103 // }, 104 // },
104 // "delay_while_idle": true, 105 // "delay_while_idle": true,
105 // } 106 // }
106 // TODO(johnme): Make sure this is clearly documented for developers. 107 // TODO(johnme): Make sure this is clearly documented for developers.
107 PushMessagingApplicationId application_id = 108 PushMessagingApplicationId application_id =
108 PushMessagingApplicationId::Parse(app_id); 109 PushMessagingApplicationId::Parse(app_id);
109 DCHECK(application_id.IsValid()); 110 DCHECK(application_id.IsValid());
110 GCMClient::MessageData::const_iterator it = message.data.find("data"); 111 GCMClient::MessageData::const_iterator it = message.data.find("data");
111 if (application_id.IsValid() && it != message.data.end()) { 112 if (application_id.IsValid() && it != message.data.end()) {
112 const std::string& data ALLOW_UNUSED = it->second; 113 const std::string& data = it->second;
113 // TODO(mvanouwerkerk): Fire push event with data on the Service Worker 114 content::BrowserContext::DeliverPushMessage(
114 // corresponding to app_id (and remove ALLOW_UNUSED above). 115 profile_,
116 application_id.origin,
117 application_id.service_worker_registration_id,
118 data,
119 base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback,
120 weak_factory_.GetWeakPtr(),
121 application_id,
122 message));
115 } else { 123 } else {
116 // Drop the message, as it is invalid. 124 // Drop the message, as it is invalid.
117 // TODO(mvanouwerkerk): Show a warning in the developer console of the 125 // TODO(mvanouwerkerk): Show a warning in the developer console of the
118 // Service Worker corresponding to app_id. 126 // Service Worker corresponding to app_id.
119 // TODO(johnme): Add diagnostic observers (e.g. UMA and an internals page) 127 // TODO(johnme): Add diagnostic observers (e.g. UMA and an internals page)
120 // to know when bad things happen. 128 // to know when bad things happen.
121 } 129 }
122 } 130 }
123 131
132 void PushMessagingServiceImpl::DeliverMessageCallback(
133 const PushMessagingApplicationId& application_id,
134 const GCMClient::IncomingMessage& message,
135 content::PushMessagingStatus status) {
136 // TODO(mvanouwerkerk): UMA logging.
137 // TODO(mvanouwerkerk): Is there a way to recover from failure?
138 }
139
124 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) { 140 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) {
125 // TODO(mvanouwerkerk): Fire push error event on the Service Worker 141 // TODO(mvanouwerkerk): Fire push error event on the Service Worker
126 // corresponding to app_id. 142 // corresponding to app_id.
127 } 143 }
128 144
129 void PushMessagingServiceImpl::OnSendError( 145 void PushMessagingServiceImpl::OnSendError(
130 const std::string& app_id, 146 const std::string& app_id,
131 const GCMClient::SendErrorDetails& send_error_details) { 147 const GCMClient::SendErrorDetails& send_error_details) {
132 NOTREACHED() << "The Push API shouldn't have sent messages upstream"; 148 NOTREACHED() << "The Push API shouldn't have sent messages upstream";
133 } 149 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 sender_ids, 275 sender_ids,
260 base::Bind(&PushMessagingServiceImpl::DidRegister, 276 base::Bind(&PushMessagingServiceImpl::DidRegister,
261 weak_factory_.GetWeakPtr(), 277 weak_factory_.GetWeakPtr(),
262 register_callback)); 278 register_callback));
263 } 279 }
264 280
265 // TODO(johnme): Unregister should decrement the pref, and call 281 // TODO(johnme): Unregister should decrement the pref, and call
266 // RemoveAppHandler if the count drops to zero. 282 // RemoveAppHandler if the count drops to zero.
267 283
268 } // namespace gcm 284 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/push_messaging_service_impl.h ('k') | content/browser/browser_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698