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..7decaae37f35382c7ff8d57b5ea1eac83c1cc32d 100644 |
--- a/chrome/browser/ui/webui/options/website_settings_handler.cc |
+++ b/chrome/browser/ui/webui/options/website_settings_handler.cc |
@@ -31,7 +31,7 @@ using power::OriginPowerMap; |
using power::OriginPowerMapFactory; |
namespace { |
- |
Bernhard Bauer
2014/08/29 19:16:31
Instead of removing this blank line, I would rathe
Daniel Erat
2014/08/29 21:14:02
(i concur)
Daniel Nishi
2014/09/02 16:30:30
Done.
|
+const char kBattery[] = "battery"; |
const int kHttpPort = 80; |
const int kHttpsPort = 443; |
const char kPreferencesSource[] = "preference"; |
@@ -47,7 +47,7 @@ const size_t kValidTypesLength = arraysize(kValidTypes); |
namespace options { |
WebsiteSettingsHandler::WebsiteSettingsHandler() |
- : observer_(this), weak_ptr_factory_(this) { |
+ : observer_(this), power_observer_(this), weak_ptr_factory_(this) { |
Daniel Erat
2014/08/29 21:14:02
nit: chromium style is usually one member per line
Daniel Nishi
2014/09/02 16:30:30
Done.
|
} |
WebsiteSettingsHandler::~WebsiteSettingsHandler() { |
@@ -87,6 +87,10 @@ 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); |
+ power_observer_.Add(origin_power_map); |
} |
void WebsiteSettingsHandler::RegisterMessages() { |
@@ -152,6 +156,10 @@ void WebsiteSettingsHandler::OnContentSettingUsed( |
Update(); |
} |
+void WebsiteSettingsHandler::OnPowerConsumptionUpdated() { |
+ Update(); |
+} |
+ |
void WebsiteSettingsHandler::HandleUpdateOrigins(const base::ListValue* args) { |
std::string content_setting_name; |
bool rv = args->GetString(0, &content_setting_name); |
@@ -217,6 +225,8 @@ void WebsiteSettingsHandler::Update() { |
DCHECK(!last_setting_.empty()); |
if (last_setting_ == kStorage) |
UpdateLocalStorage(); |
+ else if (last_setting_ == kBattery) |
+ UpdateBatteryUsage(); |
else |
UpdateOrigins(); |
} |
@@ -378,30 +388,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 +517,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)) { |