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/push_messaging/push_messaging_service_impl.h" | 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
10 #include "base/base64url.h" | 10 #include "base/base64url.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
23 #include "chrome/browser/gcm/gcm_profile_service_factory.h" | 24 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
24 #include "chrome/browser/gcm/instance_id/instance_id_profile_service.h" | 25 #include "chrome/browser/gcm/instance_id/instance_id_profile_service.h" |
25 #include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h" | 26 #include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h" |
26 #include "chrome/browser/permissions/permission_manager.h" | 27 #include "chrome/browser/permissions/permission_manager.h" |
27 #include "chrome/browser/permissions/permission_result.h" | 28 #include "chrome/browser/permissions/permission_result.h" |
28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 30 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
30 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 31 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
31 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 32 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
32 #include "chrome/browser/push_messaging/push_messaging_service_observer.h" | 33 #include "chrome/browser/push_messaging/push_messaging_service_observer.h" |
33 #include "chrome/browser/ui/chrome_pages.h" | 34 #include "chrome/browser/ui/chrome_pages.h" |
34 #include "chrome/common/chrome_features.h" | 35 #include "chrome/common/chrome_features.h" |
35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/features.h" | 37 #include "chrome/common/features.h" |
37 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
38 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
39 #include "components/content_settings/core/browser/host_content_settings_map.h" | 40 #include "components/content_settings/core/browser/host_content_settings_map.h" |
40 #include "components/gcm_driver/gcm_driver.h" | 41 #include "components/gcm_driver/gcm_driver.h" |
41 #include "components/gcm_driver/gcm_profile_service.h" | 42 #include "components/gcm_driver/gcm_profile_service.h" |
42 #include "components/gcm_driver/instance_id/instance_id.h" | 43 #include "components/gcm_driver/instance_id/instance_id.h" |
43 #include "components/gcm_driver/instance_id/instance_id_driver.h" | 44 #include "components/gcm_driver/instance_id/instance_id_driver.h" |
44 #include "components/pref_registry/pref_registry_syncable.h" | 45 #include "components/pref_registry/pref_registry_syncable.h" |
45 #include "components/prefs/pref_service.h" | 46 #include "components/prefs/pref_service.h" |
46 #include "components/rappor/public/rappor_utils.h" | 47 #include "components/rappor/public/rappor_utils.h" |
47 #include "components/rappor/rappor_service_impl.h" | 48 #include "components/rappor/rappor_service_impl.h" |
48 #include "content/public/browser/browser_context.h" | 49 #include "content/public/browser/browser_context.h" |
| 50 #include "content/public/browser/notification_service.h" |
49 #include "content/public/browser/render_frame_host.h" | 51 #include "content/public/browser/render_frame_host.h" |
50 #include "content/public/browser/service_worker_context.h" | 52 #include "content/public/browser/service_worker_context.h" |
51 #include "content/public/browser/storage_partition.h" | 53 #include "content/public/browser/storage_partition.h" |
52 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
53 #include "content/public/common/child_process_host.h" | 55 #include "content/public/common/child_process_host.h" |
54 #include "content/public/common/content_switches.h" | 56 #include "content/public/common/content_switches.h" |
55 #include "content/public/common/push_messaging_status.h" | 57 #include "content/public/common/push_messaging_status.h" |
56 #include "content/public/common/push_subscription_options.h" | 58 #include "content/public/common/push_subscription_options.h" |
57 #include "ui/base/l10n/l10n_util.h" | 59 #include "ui/base/l10n/l10n_util.h" |
58 | 60 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 156 |
155 PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile) | 157 PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile) |
156 : profile_(profile), | 158 : profile_(profile), |
157 push_subscription_count_(0), | 159 push_subscription_count_(0), |
158 pending_push_subscription_count_(0), | 160 pending_push_subscription_count_(0), |
159 notification_manager_(profile), | 161 notification_manager_(profile), |
160 push_messaging_service_observer_(PushMessagingServiceObserver::Create()), | 162 push_messaging_service_observer_(PushMessagingServiceObserver::Create()), |
161 weak_factory_(this) { | 163 weak_factory_(this) { |
162 DCHECK(profile); | 164 DCHECK(profile); |
163 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this); | 165 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this); |
| 166 |
| 167 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 168 content::NotificationService::AllSources()); |
| 169 registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
| 170 content::NotificationService::AllSources()); |
164 } | 171 } |
165 | 172 |
166 PushMessagingServiceImpl::~PushMessagingServiceImpl() { | 173 PushMessagingServiceImpl::~PushMessagingServiceImpl() { |
167 HostContentSettingsMapFactory::GetForProfile(profile_)->RemoveObserver(this); | 174 HostContentSettingsMapFactory::GetForProfile(profile_)->RemoveObserver(this); |
168 } | 175 } |
169 | 176 |
| 177 void PushMessagingServiceImpl::Observe( |
| 178 int type, |
| 179 const content::NotificationSource& source, |
| 180 const content::NotificationDetails& details) { |
| 181 switch (type) { |
| 182 case chrome::NOTIFICATION_APP_TERMINATING: { |
| 183 DVLOG(1) << "PushMessagingServiceImpl Terminating"; |
| 184 break; |
| 185 } |
| 186 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { |
| 187 DVLOG(1) << "PushMessagingServiceImpl Close All Browsers Request"; |
| 188 break; |
| 189 } |
| 190 } |
| 191 } |
| 192 |
170 void PushMessagingServiceImpl::IncreasePushSubscriptionCount(int add, | 193 void PushMessagingServiceImpl::IncreasePushSubscriptionCount(int add, |
171 bool is_pending) { | 194 bool is_pending) { |
172 DCHECK(add > 0); | 195 DCHECK(add > 0); |
173 if (push_subscription_count_ + pending_push_subscription_count_ == 0) { | 196 if (push_subscription_count_ + pending_push_subscription_count_ == 0) { |
174 GetGCMDriver()->AddAppHandler(kPushMessagingAppIdentifierPrefix, this); | 197 GetGCMDriver()->AddAppHandler(kPushMessagingAppIdentifierPrefix, this); |
175 } | 198 } |
176 if (is_pending) { | 199 if (is_pending) { |
177 pending_push_subscription_count_ += add; | 200 pending_push_subscription_count_ += add; |
178 } else { | 201 } else { |
179 #if BUILDFLAG(ENABLE_BACKGROUND) | 202 #if BUILDFLAG(ENABLE_BACKGROUND) |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 } | 1012 } |
990 | 1013 |
991 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() | 1014 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() |
992 const { | 1015 const { |
993 instance_id::InstanceIDProfileService* instance_id_profile_service = | 1016 instance_id::InstanceIDProfileService* instance_id_profile_service = |
994 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); | 1017 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); |
995 CHECK(instance_id_profile_service); | 1018 CHECK(instance_id_profile_service); |
996 CHECK(instance_id_profile_service->driver()); | 1019 CHECK(instance_id_profile_service->driver()); |
997 return instance_id_profile_service->driver(); | 1020 return instance_id_profile_service->driver(); |
998 } | 1021 } |
OLD | NEW |