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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 message)); | 123 message)); |
123 } else { | 124 } else { |
124 // Drop the message, as it is invalid. | 125 // Drop the message, as it is invalid. |
125 // TODO(mvanouwerkerk): Show a warning in the developer console of the | 126 // TODO(mvanouwerkerk): Show a warning in the developer console of the |
126 // Service Worker corresponding to app_id. | 127 // Service Worker corresponding to app_id. |
127 // TODO(johnme): Add diagnostic observers (e.g. UMA and an internals page) | 128 // TODO(johnme): Add diagnostic observers (e.g. UMA and an internals page) |
128 // to know when bad things happen. | 129 // to know when bad things happen. |
129 } | 130 } |
130 } | 131 } |
131 | 132 |
| 133 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { |
| 134 profile_ = profile; |
| 135 } |
| 136 |
132 void PushMessagingServiceImpl::DeliverMessageCallback( | 137 void PushMessagingServiceImpl::DeliverMessageCallback( |
133 const PushMessagingApplicationId& application_id, | 138 const PushMessagingApplicationId& application_id, |
134 const GCMClient::IncomingMessage& message, | 139 const GCMClient::IncomingMessage& message, |
135 content::PushDeliveryStatus status) { | 140 content::PushDeliveryStatus status) { |
136 // TODO(mvanouwerkerk): UMA logging. | 141 // TODO(mvanouwerkerk): UMA logging. |
137 // TODO(mvanouwerkerk): Is there a way to recover from failure? | 142 // TODO(mvanouwerkerk): Is there a way to recover from failure? |
138 } | 143 } |
139 | 144 |
140 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) { | 145 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) { |
141 // TODO(mvanouwerkerk): Fire push error event on the Service Worker | 146 // TODO(mvanouwerkerk): Fire push error event on the Service Worker |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 weak_factory_.GetWeakPtr(), | 231 weak_factory_.GetWeakPtr(), |
227 application_id, | 232 application_id, |
228 sender_id, | 233 sender_id, |
229 callback)); | 234 callback)); |
230 } | 235 } |
231 | 236 |
232 void PushMessagingServiceImpl::RegisterEnd( | 237 void PushMessagingServiceImpl::RegisterEnd( |
233 const content::PushMessagingService::RegisterCallback& callback, | 238 const content::PushMessagingService::RegisterCallback& callback, |
234 const std::string& registration_id, | 239 const std::string& registration_id, |
235 content::PushRegistrationStatus status) { | 240 content::PushRegistrationStatus status) { |
236 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); | 241 GURL endpoint = GURL(std::string(kPushMessagingEndpoint)); |
237 callback.Run(endpoint, registration_id, status); | 242 callback.Run(endpoint, registration_id, status); |
238 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) { | 243 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) { |
239 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. | 244 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. |
240 int registration_count = profile_->GetPrefs()->GetInteger( | 245 int registration_count = profile_->GetPrefs()->GetInteger( |
241 prefs::kPushMessagingRegistrationCount); | 246 prefs::kPushMessagingRegistrationCount); |
242 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, | 247 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, |
243 registration_count + 1); | 248 registration_count + 1); |
244 } | 249 } |
245 } | 250 } |
246 | 251 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |