OLD | NEW |
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // TODO(mvanouwerkerk): Show a warning in the developer console of the | 125 // TODO(mvanouwerkerk): Show a warning in the developer console of the |
126 // Service Worker corresponding to app_id. | 126 // Service Worker corresponding to app_id. |
127 // 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) |
128 // to know when bad things happen. | 128 // to know when bad things happen. |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 void PushMessagingServiceImpl::DeliverMessageCallback( | 132 void PushMessagingServiceImpl::DeliverMessageCallback( |
133 const PushMessagingApplicationId& application_id, | 133 const PushMessagingApplicationId& application_id, |
134 const GCMClient::IncomingMessage& message, | 134 const GCMClient::IncomingMessage& message, |
135 content::PushMessagingStatus status) { | 135 content::PushDeliveryStatus status) { |
136 // TODO(mvanouwerkerk): UMA logging. | 136 // TODO(mvanouwerkerk): UMA logging. |
137 // TODO(mvanouwerkerk): Is there a way to recover from failure? | 137 // TODO(mvanouwerkerk): Is there a way to recover from failure? |
138 } | 138 } |
139 | 139 |
140 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) { | 140 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) { |
141 // TODO(mvanouwerkerk): Fire push error event on the Service Worker | 141 // TODO(mvanouwerkerk): Fire push error event on the Service Worker |
142 // corresponding to app_id. | 142 // corresponding to app_id. |
143 } | 143 } |
144 | 144 |
145 void PushMessagingServiceImpl::OnSendError( | 145 void PushMessagingServiceImpl::OnSendError( |
(...skipping 22 matching lines...) Expand all Loading... |
168 | 168 |
169 PushMessagingApplicationId application_id = | 169 PushMessagingApplicationId application_id = |
170 PushMessagingApplicationId(origin, service_worker_registration_id); | 170 PushMessagingApplicationId(origin, service_worker_registration_id); |
171 DCHECK(application_id.IsValid()); | 171 DCHECK(application_id.IsValid()); |
172 | 172 |
173 if (profile_->GetPrefs()->GetInteger( | 173 if (profile_->GetPrefs()->GetInteger( |
174 prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) { | 174 prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) { |
175 RegisterEnd( | 175 RegisterEnd( |
176 callback, | 176 callback, |
177 std::string(), | 177 std::string(), |
178 content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_LIMIT_REACHED); | 178 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED); |
179 return; | 179 return; |
180 } | 180 } |
181 | 181 |
182 // If this is registering for the first time then the driver does not have | 182 // If this is registering for the first time then the driver does not have |
183 // this as an app handler and registration would fail. | 183 // this as an app handler and registration would fail. |
184 if (gcm_profile_service_->driver()->GetAppHandler( | 184 if (gcm_profile_service_->driver()->GetAppHandler( |
185 kPushMessagingApplicationIdPrefix) != this) | 185 kPushMessagingApplicationIdPrefix) != this) |
186 gcm_profile_service_->driver()->AddAppHandler( | 186 gcm_profile_service_->driver()->AddAppHandler( |
187 kPushMessagingApplicationIdPrefix, this); | 187 kPushMessagingApplicationIdPrefix, this); |
188 | 188 |
(...skipping 19 matching lines...) Expand all Loading... |
208 renderer_id, web_contents->GetRoutingID(), bridge_id, GURL()); | 208 renderer_id, web_contents->GetRoutingID(), bridge_id, GURL()); |
209 | 209 |
210 GURL embedder = web_contents->GetLastCommittedURL(); | 210 GURL embedder = web_contents->GetLastCommittedURL(); |
211 gcm::PushMessagingPermissionContext* permission_context = | 211 gcm::PushMessagingPermissionContext* permission_context = |
212 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); | 212 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); |
213 | 213 |
214 if (permission_context == NULL) { | 214 if (permission_context == NULL) { |
215 RegisterEnd( | 215 RegisterEnd( |
216 callback, | 216 callback, |
217 std::string(), | 217 std::string(), |
218 content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_PERMISSION_DENIED); | 218 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
219 return; | 219 return; |
220 } | 220 } |
221 | 221 |
222 permission_context->RequestPermission( | 222 permission_context->RequestPermission( |
223 web_contents, | 223 web_contents, |
224 id, | 224 id, |
225 embedder, | 225 embedder, |
226 user_gesture, | 226 user_gesture, |
227 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, | 227 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, |
228 weak_factory_.GetWeakPtr(), | 228 weak_factory_.GetWeakPtr(), |
229 application_id, | 229 application_id, |
230 sender_id, | 230 sender_id, |
231 callback)); | 231 callback)); |
232 } | 232 } |
233 | 233 |
234 void PushMessagingServiceImpl::RegisterEnd( | 234 void PushMessagingServiceImpl::RegisterEnd( |
235 const content::PushMessagingService::RegisterCallback& callback, | 235 const content::PushMessagingService::RegisterCallback& callback, |
236 const std::string& registration_id, | 236 const std::string& registration_id, |
237 content::PushMessagingStatus status) { | 237 content::PushRegistrationStatus status) { |
238 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); | 238 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); |
239 callback.Run(endpoint, registration_id, status); | 239 callback.Run(endpoint, registration_id, status); |
240 if (status == content::PUSH_MESSAGING_STATUS_OK) { | 240 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) { |
241 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. | 241 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. |
242 int registration_count = profile_->GetPrefs()->GetInteger( | 242 int registration_count = profile_->GetPrefs()->GetInteger( |
243 prefs::kPushMessagingRegistrationCount); | 243 prefs::kPushMessagingRegistrationCount); |
244 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, | 244 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, |
245 registration_count + 1); | 245 registration_count + 1); |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 void PushMessagingServiceImpl::DidRegister( | 249 void PushMessagingServiceImpl::DidRegister( |
250 const content::PushMessagingService::RegisterCallback& callback, | 250 const content::PushMessagingService::RegisterCallback& callback, |
251 const std::string& registration_id, | 251 const std::string& registration_id, |
252 GCMClient::Result result) { | 252 GCMClient::Result result) { |
253 content::PushMessagingStatus status = | 253 content::PushRegistrationStatus status = |
254 result == GCMClient::SUCCESS | 254 result == GCMClient::SUCCESS |
255 ? content::PUSH_MESSAGING_STATUS_OK | 255 ? content::PUSH_REGISTRATION_STATUS_SUCCESS |
256 : content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_SERVICE_ERROR; | 256 : content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; |
257 RegisterEnd(callback, registration_id, status); | 257 RegisterEnd(callback, registration_id, status); |
258 } | 258 } |
259 | 259 |
260 void PushMessagingServiceImpl::DidRequestPermission( | 260 void PushMessagingServiceImpl::DidRequestPermission( |
261 const PushMessagingApplicationId& application_id, | 261 const PushMessagingApplicationId& application_id, |
262 const std::string& sender_id, | 262 const std::string& sender_id, |
263 const content::PushMessagingService::RegisterCallback& register_callback, | 263 const content::PushMessagingService::RegisterCallback& register_callback, |
264 bool allow) { | 264 bool allow) { |
265 if (!allow) { | 265 if (!allow) { |
266 RegisterEnd( | 266 RegisterEnd( |
267 register_callback, | 267 register_callback, |
268 std::string(), | 268 std::string(), |
269 content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_PERMISSION_DENIED); | 269 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
270 return; | 270 return; |
271 } | 271 } |
272 | 272 |
273 // The GCMDriver could be NULL if GCMProfileService has been shut down. | 273 // The GCMDriver could be NULL if GCMProfileService has been shut down. |
274 if (!gcm_profile_service_->driver()) | 274 if (!gcm_profile_service_->driver()) |
275 return; | 275 return; |
276 | 276 |
277 std::vector<std::string> sender_ids(1, sender_id); | 277 std::vector<std::string> sender_ids(1, sender_id); |
278 | 278 |
279 gcm_profile_service_->driver()->Register( | 279 gcm_profile_service_->driver()->Register( |
280 application_id.ToString(), | 280 application_id.ToString(), |
281 sender_ids, | 281 sender_ids, |
282 base::Bind(&PushMessagingServiceImpl::DidRegister, | 282 base::Bind(&PushMessagingServiceImpl::DidRegister, |
283 weak_factory_.GetWeakPtr(), | 283 weak_factory_.GetWeakPtr(), |
284 register_callback)); | 284 register_callback)); |
285 } | 285 } |
286 | 286 |
287 // TODO(johnme): Unregister should decrement the pref, and call | 287 // TODO(johnme): Unregister should decrement the pref, and call |
288 // RemoveAppHandler if the count drops to zero. | 288 // RemoveAppHandler if the count drops to zero. |
289 | 289 |
290 } // namespace gcm | 290 } // namespace gcm |
OLD | NEW |