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

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

Issue 408493003: Show local storage usage on the Website Settings options page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No longer using std::end. Created 6 years, 5 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 a1b267de2230679d0f74ec09428c0d7b6aec063a..be6aa3d8e755a5c1ceea743a53061328eff5baf9 100644
--- a/chrome/browser/ui/webui/options/website_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/website_settings_handler.cc
@@ -9,16 +9,21 @@
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_ui.h"
#include "grit/generated_resources.h"
+#include "ui/base/text/bytes_formatting.h"
namespace {
const char kPreferencesSource[] = "preference";
-
+const char kStorage[] = "storage";
+const ContentSettingsType kValidTypes[] = {CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM};
+const size_t kValidTypesLength = arraysize(kValidTypes);
} // namespace
namespace options {
-WebsiteSettingsHandler::WebsiteSettingsHandler() {
+WebsiteSettingsHandler::WebsiteSettingsHandler() : weak_ptr_factory_(this) {
}
WebsiteSettingsHandler::~WebsiteSettingsHandler() {
@@ -35,6 +40,7 @@ void WebsiteSettingsHandler::GetLocalizedValues(
{"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION},
{"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM},
{"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS},
+ {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE},
};
RegisterStrings(localized_strings, resources, arraysize(resources));
@@ -52,35 +58,68 @@ void WebsiteSettingsHandler::RegisterMessages() {
"updateOriginsSearchResults",
base::Bind(&WebsiteSettingsHandler::HandleUpdateSearchResults,
base::Unretained(this)));
+
+ web_ui()->RegisterMessageCallback(
+ "updateLocalStorage",
+ base::Bind(&WebsiteSettingsHandler::HandleUpdateLocalStorage,
+ base::Unretained(this)));
}
void WebsiteSettingsHandler::HandleUpdateOrigins(const base::ListValue* args) {
std::string content_setting_name;
bool rv = args->GetString(0, &content_setting_name);
DCHECK(rv);
- ContentSettingsType content_type;
- content_settings::GetTypeFromName(content_setting_name, &content_type);
- last_setting_ = content_type;
+ ContentSettingsType content_type;
+ rv = content_settings::GetTypeFromName(content_setting_name, &content_type);
+ DCHECK(rv);
+ DCHECK_NE(
+ kValidTypes + kValidTypesLength,
+ std::find(kValidTypes, kValidTypes + kValidTypesLength, content_type));
- UpdateOrigins(std::string());
+ last_setting_ = content_setting_name;
+ UpdateOrigins();
}
void WebsiteSettingsHandler::HandleUpdateSearchResults(
const base::ListValue* args) {
- std::string filter;
- bool rv = args->GetString(0, &filter);
+ bool rv = args->GetString(0, &last_filter_);
DCHECK(rv);
- UpdateOrigins(filter);
+ if (last_setting_ == kStorage)
+ UpdateLocalStorage();
+ else
+ UpdateOrigins();
}
-void WebsiteSettingsHandler::UpdateOrigins(const std::string& filter) {
+void WebsiteSettingsHandler::HandleUpdateLocalStorage(
+ const base::ListValue* args) {
+ if (!local_storage_) {
+ Profile* profile = Profile::FromWebUI(web_ui());
+ local_storage_ = new BrowsingDataLocalStorageHelper(profile);
+ }
+
+ last_setting_ = kStorage;
+
+ local_storage_->StartFetching(
+ base::Bind(&WebsiteSettingsHandler::OnLocalStorageFetched,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list<
+ BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) {
+ local_storage_list_ = storage;
+ UpdateLocalStorage();
+}
+
+void WebsiteSettingsHandler::UpdateOrigins() {
Profile* profile = Profile::FromWebUI(web_ui());
HostContentSettingsMap* settings = profile->GetHostContentSettingsMap();
ContentSettingsForOneType all_settings;
- settings->GetSettingsForOneType(last_setting_, std::string(), &all_settings);
+ ContentSettingsType last_setting;
+ content_settings::GetTypeFromName(last_setting_, &last_setting);
+ settings->GetSettingsForOneType(last_setting, std::string(), &all_settings);
base::DictionaryValue origins;
for (ContentSettingsForOneType::const_iterator it = all_settings.begin();
@@ -95,7 +134,7 @@ void WebsiteSettingsHandler::UpdateOrigins(const std::string& filter) {
std::string origin = it->primary_pattern.ToString();
- if (origin.find(filter) == base::string16::npos)
+ if (origin.find(last_filter_) == base::string16::npos)
continue;
// TODO(dhnishi): Change 0 to a timestamp representing last API usage.
@@ -106,4 +145,25 @@ void WebsiteSettingsHandler::UpdateOrigins(const std::string& filter) {
origins);
}
+void WebsiteSettingsHandler::UpdateLocalStorage() {
+ base::DictionaryValue local_storage_map;
+ for (LocalStorageList::const_iterator it = local_storage_list_.begin();
+ it != local_storage_list_.end();
+ it++) {
+ std::string origin = it->origin_url.spec();
+
+ if (origin.find(last_filter_) == base::string16::npos)
+ continue;
+
+ base::DictionaryValue* origin_entry = new base::DictionaryValue();
+ origin_entry->SetWithoutPathExpansion(
+ "usage", new base::FundamentalValue(static_cast<double>(it->size)));
+ origin_entry->SetWithoutPathExpansion(
+ "usageString", new base::StringValue(ui::FormatBytes(it->size)));
+ local_storage_map.SetWithoutPathExpansion(origin, origin_entry);
+ }
+ web_ui()->CallJavascriptFunction(
+ "WebsiteSettingsManager.populateLocalStorage", local_storage_map);
+}
+
} // namespace options

Powered by Google App Engine
This is Rietveld 408576698