Chromium Code Reviews| 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" |
| 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/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 14 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 15 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 15 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 16 #include "chrome/browser/services/gcm/push_messaging_application_id.h" | 16 #include "chrome/browser/services/gcm/push_messaging_application_id.h" |
| 17 #include "chrome/browser/services/gcm/push_messaging_constants.h" | |
| 17 #include "chrome/browser/services/gcm/push_messaging_permission_context.h" | 18 #include "chrome/browser/services/gcm/push_messaging_permission_context.h" |
| 18 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory. h" | 19 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory. h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "components/content_settings/core/common/permission_request_id.h" | 22 #include "components/content_settings/core/common/permission_request_id.h" |
| 22 #include "components/gcm_driver/gcm_driver.h" | 23 #include "components/gcm_driver/gcm_driver.h" |
| 23 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
| 24 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 weak_factory_.GetWeakPtr(), | 227 weak_factory_.GetWeakPtr(), |
| 227 application_id, | 228 application_id, |
| 228 sender_id, | 229 sender_id, |
| 229 callback)); | 230 callback)); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void PushMessagingServiceImpl::RegisterEnd( | 233 void PushMessagingServiceImpl::RegisterEnd( |
| 233 const content::PushMessagingService::RegisterCallback& callback, | 234 const content::PushMessagingService::RegisterCallback& callback, |
| 234 const std::string& registration_id, | 235 const std::string& registration_id, |
| 235 content::PushRegistrationStatus status) { | 236 content::PushRegistrationStatus status) { |
| 236 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); | 237 GURL endpoint = GURL(std::string(kPushMessagingEndpoint)); |
| 237 callback.Run(endpoint, registration_id, status); | 238 callback.Run(endpoint, registration_id, status); |
| 238 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) { | 239 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) { |
| 239 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. | 240 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. |
| 240 int registration_count = profile_->GetPrefs()->GetInteger( | 241 int registration_count = profile_->GetPrefs()->GetInteger( |
| 241 prefs::kPushMessagingRegistrationCount); | 242 prefs::kPushMessagingRegistrationCount); |
| 242 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, | 243 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, |
| 243 registration_count + 1); | 244 registration_count + 1); |
| 244 } | 245 } |
| 245 } | 246 } |
| 246 | 247 |
| 247 void PushMessagingServiceImpl::DidRegister( | 248 void PushMessagingServiceImpl::DidRegister( |
| 248 const content::PushMessagingService::RegisterCallback& callback, | 249 const content::PushMessagingService::RegisterCallback& callback, |
| 249 const std::string& registration_id, | 250 const std::string& registration_id, |
| 250 GCMClient::Result result) { | 251 GCMClient::Result result) { |
| 251 content::PushRegistrationStatus status = | 252 content::PushRegistrationStatus status = |
| 252 result == GCMClient::SUCCESS | 253 result == GCMClient::SUCCESS |
| 253 ? content::PUSH_REGISTRATION_STATUS_SUCCESS | 254 ? content::PUSH_REGISTRATION_STATUS_SUCCESS |
| 254 : content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; | 255 : content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; |
| 255 RegisterEnd(callback, registration_id, status); | 256 RegisterEnd(callback, registration_id, status); |
| 256 } | 257 } |
| 257 | 258 |
| 259 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { | |
|
Peter Beverloo
2014/10/20 16:35:52
nit: Move this to *before* the DeliverMessageCallb
Michael van Ouwerkerk
2014/10/20 17:06:49
Done.
| |
| 260 profile_ = profile; | |
| 261 } | |
| 262 | |
| 258 void PushMessagingServiceImpl::DidRequestPermission( | 263 void PushMessagingServiceImpl::DidRequestPermission( |
| 259 const PushMessagingApplicationId& application_id, | 264 const PushMessagingApplicationId& application_id, |
| 260 const std::string& sender_id, | 265 const std::string& sender_id, |
| 261 const content::PushMessagingService::RegisterCallback& register_callback, | 266 const content::PushMessagingService::RegisterCallback& register_callback, |
| 262 bool allow) { | 267 bool allow) { |
| 263 if (!allow) { | 268 if (!allow) { |
| 264 RegisterEnd(register_callback, | 269 RegisterEnd(register_callback, |
| 265 std::string(), | 270 std::string(), |
| 266 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 271 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
| 267 return; | 272 return; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 278 sender_ids, | 283 sender_ids, |
| 279 base::Bind(&PushMessagingServiceImpl::DidRegister, | 284 base::Bind(&PushMessagingServiceImpl::DidRegister, |
| 280 weak_factory_.GetWeakPtr(), | 285 weak_factory_.GetWeakPtr(), |
| 281 register_callback)); | 286 register_callback)); |
| 282 } | 287 } |
| 283 | 288 |
| 284 // TODO(johnme): Unregister should decrement the pref, and call | 289 // TODO(johnme): Unregister should decrement the pref, and call |
| 285 // RemoveAppHandler if the count drops to zero. | 290 // RemoveAppHandler if the count drops to zero. |
| 286 | 291 |
| 287 } // namespace gcm | 292 } // namespace gcm |
| OLD | NEW |