Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Unified Diff: chrome/browser/services/gcm/push_messaging_service_impl.cc

Issue 930083002: Unregister with push service and SW database when permission is lost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add copy ctor Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/services/gcm/push_messaging_service_impl.cc
diff --git a/chrome/browser/services/gcm/push_messaging_service_impl.cc b/chrome/browser/services/gcm/push_messaging_service_impl.cc
index a3ad6a2e54c9539da348522329e47ba4776519b0..73a5a463983290f06a677356c42d523ce1b0ec2f 100644
--- a/chrome/browser/services/gcm/push_messaging_service_impl.cc
+++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc
@@ -27,10 +27,12 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/permission_request_id.h"
#include "components/gcm_driver/gcm_driver.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/storage_partition.h"
@@ -130,11 +132,17 @@ PushMessagingServiceImpl::PushMessagingServiceImpl(
push_registration_count_(0),
pending_push_registration_count_(0),
weak_factory_(this) {
+ // In some tests, we might end up with |profile_| being null at this point.
+ // When that is the case |profile_| will be set in SetProfileForTesting(), at
+ // which point the service will start to observe HostContentSettingsMap.
+ if (profile_)
+ profile_->GetHostContentSettingsMap()->AddObserver(this);
}
PushMessagingServiceImpl::~PushMessagingServiceImpl() {
// TODO(johnme): If it's possible for this to be destroyed before GCMDriver,
// then we should call RemoveAppHandler.
+ profile_->GetHostContentSettingsMap()->RemoveObserver(this);
}
void PushMessagingServiceImpl::IncreasePushRegistrationCount(int add,
@@ -234,8 +242,37 @@ void PushMessagingServiceImpl::OnMessage(
application_id.service_worker_registration_id, message));
}
+void PushMessagingServiceImpl::OnContentSettingChanged(
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type,
+ std::string resource_identifier) {
+ if (content_type != CONTENT_SETTINGS_TYPE_PUSH_MESSAGING &&
+ content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
+ return;
+ }
+
+ for (const auto& id : PushMessagingApplicationId::GetAll(profile_)) {
+ if (primary_pattern.IsValid() && !primary_pattern.Matches(id.origin))
+ continue;
+
+ // |primary_pattern| might be invalid or it does matches the origin, thus
Bernhard Bauer 2015/02/16 22:41:05 This sentence doesn't parse.
mlamouri (slow - plz ping) 2015/02/16 23:34:35 Wrote something else.
+ // the origin permission status might have changed.
+ if (HasPermission(id.origin))
+ continue;
+
+ // Unregister the PushMessagingApplicationId with the push service.
+ Unregister(id.app_id_guid, true /* retry */, UnregisterCallback());
+
+ // Clear the associated service worker push registration id.
+ PushMessagingService::ClearPushRegistrationID(
+ profile_, id.origin, id.service_worker_registration_id);
+ }
+}
+
void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) {
profile_ = profile;
+ profile_->GetHostContentSettingsMap()->AddObserver(this);
}
void PushMessagingServiceImpl::DeliverMessageCallback(
@@ -624,8 +661,10 @@ void PushMessagingServiceImpl::Unregister(
PushMessagingApplicationId application_id = PushMessagingApplicationId::Get(
profile_, requesting_origin, service_worker_registration_id);
if (!application_id.IsValid()) {
- callback.Run(
- content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED);
+ if (!callback.is_null()) {
+ callback.Run(
+ content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED);
+ }
return;
}
@@ -664,8 +703,15 @@ void PushMessagingServiceImpl::DidUnregister(
if (result == GCMClient::SUCCESS) {
PushMessagingApplicationId application_id =
PushMessagingApplicationId::Get(profile_, app_id_guid);
- if (application_id.IsValid())
- application_id.DeleteFromDisk(profile_);
+ if (!application_id.IsValid()) {
+ if (!callback.is_null()) {
+ callback.Run(
+ content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED);
+ }
+ return;
+ }
+
+ application_id.DeleteFromDisk(profile_);
DecreasePushRegistrationCount(1, false /* was_pending */);
}

Powered by Google App Engine
This is Rietveld 408576698