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/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 29 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
29 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 30 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
30 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 31 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
31 #include "chrome/browser/push_messaging/push_messaging_service_observer.h" | 32 #include "chrome/browser/push_messaging/push_messaging_service_observer.h" |
32 #include "chrome/browser/ui/chrome_pages.h" | 33 #include "chrome/browser/ui/chrome_pages.h" |
33 #include "chrome/common/chrome_features.h" | 34 #include "chrome/common/chrome_features.h" |
34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/features.h" | 36 #include "chrome/common/features.h" |
36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
37 #include "chrome/grit/generated_resources.h" | 38 #include "chrome/grit/generated_resources.h" |
38 #include "components/content_settings/core/browser/host_content_settings_map.h" | 39 #include "components/content_settings/core/browser/host_content_settings_map.h" |
39 #include "components/gcm_driver/gcm_driver.h" | 40 #include "components/gcm_driver/gcm_driver.h" |
40 #include "components/gcm_driver/gcm_profile_service.h" | 41 #include "components/gcm_driver/gcm_profile_service.h" |
41 #include "components/gcm_driver/instance_id/instance_id.h" | 42 #include "components/gcm_driver/instance_id/instance_id.h" |
42 #include "components/gcm_driver/instance_id/instance_id_driver.h" | 43 #include "components/gcm_driver/instance_id/instance_id_driver.h" |
43 #include "components/pref_registry/pref_registry_syncable.h" | 44 #include "components/pref_registry/pref_registry_syncable.h" |
44 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
45 #include "components/rappor/public/rappor_utils.h" | 46 #include "components/rappor/public/rappor_utils.h" |
46 #include "components/rappor/rappor_service_impl.h" | 47 #include "components/rappor/rappor_service_impl.h" |
47 #include "content/public/browser/browser_context.h" | 48 #include "content/public/browser/browser_context.h" |
49 #include "content/public/browser/notification_service.h" | |
48 #include "content/public/browser/render_frame_host.h" | 50 #include "content/public/browser/render_frame_host.h" |
49 #include "content/public/browser/service_worker_context.h" | 51 #include "content/public/browser/service_worker_context.h" |
50 #include "content/public/browser/storage_partition.h" | 52 #include "content/public/browser/storage_partition.h" |
51 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
52 #include "content/public/common/child_process_host.h" | 54 #include "content/public/common/child_process_host.h" |
53 #include "content/public/common/content_switches.h" | 55 #include "content/public/common/content_switches.h" |
54 #include "content/public/common/push_messaging_status.h" | 56 #include "content/public/common/push_messaging_status.h" |
55 #include "content/public/common/push_subscription_options.h" | 57 #include "content/public/common/push_subscription_options.h" |
56 #include "ui/base/l10n/l10n_util.h" | 58 #include "ui/base/l10n/l10n_util.h" |
57 | 59 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 | 153 |
152 PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile) | 154 PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile) |
153 : profile_(profile), | 155 : profile_(profile), |
154 push_subscription_count_(0), | 156 push_subscription_count_(0), |
155 pending_push_subscription_count_(0), | 157 pending_push_subscription_count_(0), |
156 notification_manager_(profile), | 158 notification_manager_(profile), |
157 push_messaging_service_observer_(PushMessagingServiceObserver::Create()), | 159 push_messaging_service_observer_(PushMessagingServiceObserver::Create()), |
158 weak_factory_(this) { | 160 weak_factory_(this) { |
159 DCHECK(profile); | 161 DCHECK(profile); |
160 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this); | 162 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this); |
163 | |
164 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | |
dgn
2017/03/01 11:49:53
why registering this here too? AFAICT all the obse
sammiequon
2017/03/18 00:01:39
These are here to see if xiyuan@ 's hypothesis (on
dgn
2017/03/20 11:07:22
Acknowledged.
| |
165 content::NotificationService::AllSources()); | |
166 registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | |
167 content::NotificationService::AllSources()); | |
161 } | 168 } |
162 | 169 |
163 PushMessagingServiceImpl::~PushMessagingServiceImpl() { | 170 PushMessagingServiceImpl::~PushMessagingServiceImpl() { |
164 HostContentSettingsMapFactory::GetForProfile(profile_)->RemoveObserver(this); | 171 HostContentSettingsMapFactory::GetForProfile(profile_)->RemoveObserver(this); |
165 } | 172 } |
166 | 173 |
174 void PushMessagingServiceImpl::Observe( | |
175 int type, | |
176 const content::NotificationSource& source, | |
177 const content::NotificationDetails& details) { | |
178 switch (type) { | |
179 case chrome::NOTIFICATION_APP_TERMINATING: { | |
180 LOG(ERROR) << "PushMessagingServiceImpl Terminating"; | |
181 break; | |
182 } | |
183 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { | |
184 LOG(ERROR) << "PushMessagingServiceImpl Close All Browsers Request"; | |
185 break; | |
186 } | |
187 } | |
188 } | |
189 | |
167 void PushMessagingServiceImpl::IncreasePushSubscriptionCount(int add, | 190 void PushMessagingServiceImpl::IncreasePushSubscriptionCount(int add, |
168 bool is_pending) { | 191 bool is_pending) { |
169 DCHECK(add > 0); | 192 DCHECK(add > 0); |
170 if (push_subscription_count_ + pending_push_subscription_count_ == 0) { | 193 if (push_subscription_count_ + pending_push_subscription_count_ == 0) { |
171 GetGCMDriver()->AddAppHandler(kPushMessagingAppIdentifierPrefix, this); | 194 GetGCMDriver()->AddAppHandler(kPushMessagingAppIdentifierPrefix, this); |
172 } | 195 } |
173 if (is_pending) { | 196 if (is_pending) { |
174 pending_push_subscription_count_ += add; | 197 pending_push_subscription_count_ += add; |
175 } else { | 198 } else { |
176 #if BUILDFLAG(ENABLE_BACKGROUND) | 199 #if BUILDFLAG(ENABLE_BACKGROUND) |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 } | 1006 } |
984 | 1007 |
985 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() | 1008 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() |
986 const { | 1009 const { |
987 instance_id::InstanceIDProfileService* instance_id_profile_service = | 1010 instance_id::InstanceIDProfileService* instance_id_profile_service = |
988 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); | 1011 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); |
989 CHECK(instance_id_profile_service); | 1012 CHECK(instance_id_profile_service); |
990 CHECK(instance_id_profile_service->driver()); | 1013 CHECK(instance_id_profile_service->driver()); |
991 return instance_id_profile_service->driver(); | 1014 return instance_id_profile_service->driver(); |
992 } | 1015 } |
OLD | NEW |