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

Unified Diff: chrome/browser/ui/webui/settings/site_settings_handler.cc

Issue 1607483005: Show data usage on Site Details (MDSettings) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test (WIP) Created 4 years, 11 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/settings/site_settings_handler.cc
diff --git a/chrome/browser/ui/webui/settings/site_settings_handler.cc b/chrome/browser/ui/webui/settings/site_settings_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a37b92da5a6eb8e74a5f795200088875d0e0c69
--- /dev/null
+++ b/chrome/browser/ui/webui/settings/site_settings_handler.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/settings/site_settings_handler.h"
+
+#include "base/bind.h"
+#include "base/values.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/content_settings/core/common/content_settings_types.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/storage_partition.h"
+#include "content/public/browser/web_ui.h"
+#include "ui/base/text/bytes_formatting.h"
+
+namespace settings {
+
+SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
+ : profile_(profile) {
+}
+
+SiteSettingsHandler::~SiteSettingsHandler() {
+ if (storage_info_fetcher_.get())
+ storage_info_fetcher_->RemoveObserver(this);
+}
+
+void SiteSettingsHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "fetchUsageTotal",
+ base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal,
+ base::Unretained(this)));
+}
+
+void SiteSettingsHandler::OnGetUsageInfo(
+ const storage::UsageInfoEntries& entries) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ storage::UsageInfoEntries::const_iterator i;
+ for (i = entries.begin(); i != entries.end(); ++i) {
+ if (i->usage <= 0) continue;
+ if (i->host == usage_host_) {
+ web_ui()->CallJavascriptFunction(
+ "settings.WebsiteUsagePrivateApi.returnUsageTotal",
+ base::StringValue(ui::FormatBytes(i->usage)));
+ return;
+ }
+ }
+}
+
+void SiteSettingsHandler::HandleFetchUsageTotal(
+ const base::ListValue* args) {
+ CHECK_EQ(1U, args->GetSize());
+ std::string origin;
+ CHECK(args->GetString(0, &origin));
+ GURL url(origin);
+ if (url.is_valid()) {
+ usage_host_ = url.host();
+ storage_info_fetcher_ = new StorageInfoFetcher(
+ content::BrowserContext::GetDefaultStoragePartition(
+ profile_)->GetQuotaManager());
+ storage_info_fetcher_->AddObserver(this);
+ storage_info_fetcher_->Run();
+ }
+}
+
+} // namespace settings

Powered by Google App Engine
This is Rietveld 408576698