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

Unified Diff: chrome/browser/ui/webui/options/website_settings_handler.cc

Issue 519883002: Update the Website Settings page when the power consumption is updated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove the Observer, replace with Subscription. Created 6 years, 3 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/ui/webui/options/website_settings_handler.cc
diff --git a/chrome/browser/ui/webui/options/website_settings_handler.cc b/chrome/browser/ui/webui/options/website_settings_handler.cc
index a31bbb1e8ad6ed64e4f921974001596fb772261a..bbb556bc6b161bae01b803fe321d2da0ea90cef9 100644
--- a/chrome/browser/ui/webui/options/website_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/website_settings_handler.cc
@@ -32,6 +32,7 @@ using power::OriginPowerMapFactory;
namespace {
+const char kBattery[] = "battery";
const int kHttpPort = 80;
const int kHttpsPort = 443;
const char kPreferencesSource[] = "preference";
@@ -42,6 +43,7 @@ const ContentSettingsType kValidTypes[] = {
CONTENT_SETTINGS_TYPE_MEDIASTREAM,
CONTENT_SETTINGS_TYPE_COOKIES};
const size_t kValidTypesLength = arraysize(kValidTypes);
+
} // namespace
namespace options {
@@ -87,6 +89,11 @@ void WebsiteSettingsHandler::InitializeHandler() {
Profile* profile = Profile::FromWebUI(web_ui());
HostContentSettingsMap* settings = profile->GetHostContentSettingsMap();
observer_.Add(settings);
+
+ power::OriginPowerMap* origin_power_map =
+ power::OriginPowerMapFactory::GetForBrowserContext(profile);
+ subscription_ = origin_power_map->AddPowerConsumptionUpdatedCallback(
+ base::Bind(&WebsiteSettingsHandler::Update, base::Unretained(this)));
}
void WebsiteSettingsHandler::RegisterMessages() {
@@ -217,6 +224,8 @@ void WebsiteSettingsHandler::Update() {
DCHECK(!last_setting_.empty());
if (last_setting_ == kStorage)
UpdateLocalStorage();
+ else if (last_setting_ == kBattery)
+ UpdateBatteryUsage();
else
UpdateOrigins();
}
@@ -378,30 +387,8 @@ void WebsiteSettingsHandler::HandleSetOriginPermission(
void WebsiteSettingsHandler::HandleUpdateBatteryUsage(
const base::ListValue* args) {
- base::DictionaryValue power_map;
- OriginPowerMap* origins =
- OriginPowerMapFactory::GetForBrowserContext(Profile::FromWebUI(web_ui()));
- OriginPowerMap::PercentOriginMap percent_map = origins->GetPercentOriginMap();
- for (std::map<GURL, int>::iterator it = percent_map.begin();
- it != percent_map.end();
- ++it) {
- std::string origin = it->first.spec();
-
- if (origin.find(last_filter_) == base::string16::npos)
- continue;
-
- base::DictionaryValue* origin_entry = new base::DictionaryValue();
- origin_entry->SetInteger("usage", it->second);
- origin_entry->SetString(
- "usageString",
- l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT,
- it->second));
- origin_entry->SetStringWithoutPathExpansion(
- "readableName", GetReadableName(it->first));
- power_map.SetWithoutPathExpansion(origin, origin_entry);
- }
- web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins",
- power_map);
+ last_setting_ = kBattery;
+ UpdateBatteryUsage();
}
void WebsiteSettingsHandler::HandleDeleteLocalStorage(
@@ -529,6 +516,33 @@ void WebsiteSettingsHandler::UpdateLocalStorage() {
local_storage_map);
}
+void WebsiteSettingsHandler::UpdateBatteryUsage() {
+ base::DictionaryValue power_map;
+ OriginPowerMap* origins =
+ OriginPowerMapFactory::GetForBrowserContext(Profile::FromWebUI(web_ui()));
+ OriginPowerMap::PercentOriginMap percent_map = origins->GetPercentOriginMap();
+ for (std::map<GURL, int>::iterator it = percent_map.begin();
+ it != percent_map.end();
+ ++it) {
+ std::string origin = it->first.spec();
+
+ if (origin.find(last_filter_) == base::string16::npos)
+ continue;
+
+ base::DictionaryValue* origin_entry = new base::DictionaryValue();
+ origin_entry->SetInteger("usage", it->second);
+ origin_entry->SetString(
+ "usageString",
+ l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT,
+ it->second));
+ origin_entry->SetStringWithoutPathExpansion("readableName",
+ GetReadableName(it->first));
+ power_map.SetWithoutPathExpansion(origin, origin_entry);
+ }
+ web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins",
+ power_map);
+}
+
void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) {
Profile* profile = Profile::FromWebUI(web_ui());
if (site_url.SchemeIs(extensions::kExtensionScheme)) {

Powered by Google App Engine
This is Rietveld 408576698