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

Unified Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 7655019: Migrate Obsolete NotificationsSettings and remove content_settings::NotificationsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 4 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/notifications/desktop_notification_service.cc
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 53dce9d5fd6d98c8c7b14f4654567c16eb186a0b..ef95915c8c4575c215af7478214b662da0a9676f 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -7,6 +7,7 @@
#include "base/metrics/histogram.h"
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/content_settings/content_settings_provider.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/extensions/extension_service.h"
@@ -47,20 +48,23 @@ const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK;
namespace {
-typedef content_settings::ProviderInterface::Rules Rules;
+typedef HostContentSettingsMap::SettingsForOneType SettingsForOneType;
+typedef HostContentSettingsMap::PatternSettingSourceTuple
+ PatternSettingSourceTuple;
-void GetOriginsWithSettingFromContentSettingsRules(
- const Rules& content_setting_rules,
+void GetOriginsWithSettingFromSettingsForOneType(
+ const SettingsForOneType& settings,
ContentSetting setting,
std::vector<GURL>* origins) {
origins->clear();
- for (Rules::const_iterator rule = content_setting_rules.begin();
- rule != content_setting_rules.end();
- ++rule) {
- if (setting == rule->content_setting) {
- std::string url_str = rule->primary_pattern.ToString();
- if (!rule->primary_pattern.IsValid()) {
+ for (SettingsForOneType::const_iterator i = settings.begin();
+ i != settings.end();
+ ++i) {
+ const PatternSettingSourceTuple& tuple(*i);
+ if (setting == tuple.c) {
battre 2011/08/22 15:00:57 Who allowed HostContentSettingsMap::PatternSetting
markusheintz_ 2011/08/24 00:47:12 Yeah sorry I had to sell deposit my for that. But
+ std::string url_str = tuple.a.ToString();
+ if (!tuple.a.IsValid()) {
// TODO(markusheintz): This will be removed in one of the next
// refactoring steps as this entire function will disapear.
LOG(DFATAL) << "Ignoring invalid content settings pattern: "
@@ -74,9 +78,9 @@ void GetOriginsWithSettingFromContentSettingsRules(
<< "hostnames (e.g. wildcard patterns) are not supported "
<< "for notification content settings yet.";
} else {
- origins->push_back(
- content_settings::NotificationProvider::ToGURL(
- rule->primary_pattern));
+ GURL origin(tuple.a.ToString());
+ DCHECK(origin.is_valid());
+ origins->push_back(origin);
}
}
}
@@ -252,7 +256,6 @@ DesktopNotificationService::DesktopNotificationService(Profile* profile,
NotificationUIManager* ui_manager)
: profile_(profile),
ui_manager_(ui_manager) {
- prefs_registrar_.Init(profile_->GetPrefs());
InitPrefs();
StartObserving();
}
@@ -261,15 +264,9 @@ DesktopNotificationService::~DesktopNotificationService() {
StopObserving();
}
-void DesktopNotificationService::RegisterUserPrefs(PrefService* user_prefs) {
- content_settings::NotificationProvider::RegisterUserPrefs(user_prefs);
-}
-
// Initialize the cache with the allowed and denied origins, or
// create the preferences if they don't exist yet.
void DesktopNotificationService::InitPrefs() {
- provider_.reset(new content_settings::NotificationProvider(profile_));
-
std::vector<GURL> allowed_origins;
std::vector<GURL> denied_origins;
ContentSetting default_content_setting = CONTENT_SETTING_DEFAULT;
@@ -291,8 +288,6 @@ void DesktopNotificationService::InitPrefs() {
void DesktopNotificationService::StartObserving() {
if (!profile_->IsOffTheRecord()) {
- prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this);
- prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this);
notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
NotificationService::AllSources());
notification_registrar_.Add(
@@ -305,18 +300,15 @@ void DesktopNotificationService::StartObserving() {
}
void DesktopNotificationService::StopObserving() {
- if (!profile_->IsOffTheRecord()) {
- prefs_registrar_.RemoveAll();
- }
notification_registrar_.RemoveAll();
}
void DesktopNotificationService::GrantPermission(const GURL& origin) {
- ContentSettingsPattern pattern =
- content_settings::NotificationProvider::ToContentSettingsPattern(origin);
- provider_->SetContentSetting(
- pattern,
- pattern,
+ ContentSettingsPattern primary_pattern =
+ ContentSettingsPattern::FromURLNoWildcard(origin);
+ profile_->GetHostContentSettingsMap()->SetContentSetting(
+ primary_pattern,
+ ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
NO_RESOURCE_IDENTIFIER,
CONTENT_SETTING_ALLOW);
@@ -331,12 +323,11 @@ void DesktopNotificationService::GrantPermission(const GURL& origin) {
}
void DesktopNotificationService::DenyPermission(const GURL& origin) {
- // Update content settings
- ContentSettingsPattern pattern =
- content_settings::NotificationProvider::ToContentSettingsPattern(origin);
- provider_->SetContentSetting(
- pattern,
- pattern,
+ ContentSettingsPattern primary_pattern =
+ ContentSettingsPattern::FromURLNoWildcard(origin);
+ profile_->GetHostContentSettingsMap()->SetContentSetting(
+ primary_pattern,
+ ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
NO_RESOURCE_IDENTIFIER,
CONTENT_SETTING_BLOCK);
@@ -353,36 +344,28 @@ void DesktopNotificationService::DenyPermission(const GURL& origin) {
void DesktopNotificationService::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (chrome::NOTIFICATION_PREF_CHANGED == type) {
- const std::string& name = *Details<std::string>(details).ptr();
- OnPrefsChanged(name);
- } else if (chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED == type) {
- // TODO(markusheintz): Check if content settings type default was changed;
- const ContentSetting default_content_setting =
- profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
- // Schedule a cache update on the IO thread.
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- prefs_cache_.get(),
- &NotificationsPrefsCache::SetCacheDefaultContentSetting,
- default_content_setting));
- } else if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) {
- // Remove all notifications currently shown or queued by the extension
- // which was unloaded.
- const Extension* extension =
- Details<UnloadedExtensionInfo>(details)->extension;
- if (extension)
- ui_manager_->CancelAllBySourceOrigin(extension->url());
- } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) {
- StopObserving();
- }
-}
+ if (chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED == type) {
+ ContentSettingsDetails* settings_details =
+ Details<ContentSettingsDetails>(details).ptr();
+ if (!settings_details->update_all_types() &&
battre 2011/08/22 15:00:57 should this be an || ?
markusheintz_ 2011/08/24 00:47:12 That's correct this way.
+ settings_details->type() != CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ return;
+
+ if (settings_details->update_all_types() ||
+ settings_details->update_all()) {
+ const ContentSetting default_content_setting =
+ profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ // Schedule a cache update on the IO thread.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ prefs_cache_.get(),
+ &NotificationsPrefsCache::SetCacheDefaultContentSetting,
+ default_content_setting));
+ }
-void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
- if (pref_name == prefs::kDesktopNotificationAllowedOrigins) {
- // Schedule a cache update on the IO thread.
+ // TODO(markusheintz): Only update the changed patterns.
std::vector<GURL> allowed_origins(GetAllowedOrigins());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -390,8 +373,7 @@ void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
prefs_cache_.get(),
&NotificationsPrefsCache::SetCacheAllowedOrigins,
allowed_origins));
- } else if (pref_name == prefs::kDesktopNotificationDeniedOrigins) {
- // Schedule a cache update on the IO thread.
+
std::vector<GURL> denied_origins(GetBlockedOrigins());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -399,8 +381,16 @@ void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
prefs_cache_.get(),
&NotificationsPrefsCache::SetCacheDeniedOrigins,
denied_origins));
- } else {
- NOTREACHED();
+
+ } else if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) {
+ // Remove all notifications currently shown or queued by the extension
+ // which was unloaded.
+ const Extension* extension =
+ Details<UnloadedExtensionInfo>(details)->extension;
+ if (extension)
+ ui_manager_->CancelAllBySourceOrigin(extension->url());
+ } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) {
+ StopObserving();
}
}
@@ -426,66 +416,66 @@ void DesktopNotificationService::ResetToDefaultContentSetting() {
}
std::vector<GURL> DesktopNotificationService::GetAllowedOrigins() {
- content_settings::ProviderInterface::Rules content_setting_rules;
- provider_->GetAllContentSettingsRules(
+ HostContentSettingsMap::SettingsForOneType settings;
+ profile_->GetHostContentSettingsMap()->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
NO_RESOURCE_IDENTIFIER,
- &content_setting_rules);
- std::vector<GURL> allowed_origins;
+ &settings);
- GetOriginsWithSettingFromContentSettingsRules(
- content_setting_rules, CONTENT_SETTING_ALLOW, &allowed_origins);
+ std::vector<GURL> allowed_origins;
+ GetOriginsWithSettingFromSettingsForOneType(
+ settings, CONTENT_SETTING_ALLOW, &allowed_origins);
return allowed_origins;
}
std::vector<GURL> DesktopNotificationService::GetBlockedOrigins() {
- content_settings::ProviderInterface::Rules content_settings_rules;
- provider_->GetAllContentSettingsRules(
+ HostContentSettingsMap::SettingsForOneType settings;
+ profile_->GetHostContentSettingsMap()->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
NO_RESOURCE_IDENTIFIER,
- &content_settings_rules);
+ &settings);
std::vector<GURL> denied_origins;
-
- GetOriginsWithSettingFromContentSettingsRules(
- content_settings_rules, CONTENT_SETTING_BLOCK, &denied_origins);
-
+ GetOriginsWithSettingFromSettingsForOneType(
+ settings, CONTENT_SETTING_BLOCK, &denied_origins);
return denied_origins;
}
void DesktopNotificationService::ResetAllowedOrigin(const GURL& origin) {
- ContentSettingsPattern pattern =
+ ContentSettingsPattern primary_pattern =
ContentSettingsPattern::FromURLNoWildcard(origin);
- provider_->SetContentSetting(
- pattern,
- pattern,
+ profile_->GetHostContentSettingsMap()->SetContentSetting(
+ primary_pattern,
+ ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
NO_RESOURCE_IDENTIFIER,
CONTENT_SETTING_DEFAULT);
}
void DesktopNotificationService::ResetBlockedOrigin(const GURL& origin) {
- ContentSettingsPattern pattern =
+ ContentSettingsPattern primary_pattern =
ContentSettingsPattern::FromURLNoWildcard(origin);
- provider_->SetContentSetting(
- pattern,
- pattern,
+ profile_->GetHostContentSettingsMap()->SetContentSetting(
+ primary_pattern,
+ ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
NO_RESOURCE_IDENTIFIER,
CONTENT_SETTING_DEFAULT);
}
void DesktopNotificationService::ResetAllOrigins() {
- provider_->ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ profile_->GetHostContentSettingsMap()->ClearSettingsForOneType(
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
}
ContentSetting DesktopNotificationService::GetContentSetting(
const GURL& origin) {
- ContentSetting provided_setting = provider_->GetContentSetting(
- origin,
- origin,
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- NO_RESOURCE_IDENTIFIER);
+ ContentSetting provided_setting =
+ profile_->GetHostContentSettingsMap()->GetContentSetting(
+ origin,
+ origin,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ NO_RESOURCE_IDENTIFIER);
if (CONTENT_SETTING_DEFAULT == provided_setting)
return GetDefaultContentSetting();
return provided_setting;

Powered by Google App Engine
This is Rietveld 408576698