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

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: Fix update problem 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
« no previous file with comments | « chrome/browser/ui/webui/settings/site_settings_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..490b179cdd99f2faa87296836592619fefa73e0b
--- /dev/null
+++ b/chrome/browser/ui/webui/settings/site_settings_handler.cc
@@ -0,0 +1,63 @@
+// Copyright 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);
+
+ for (const auto& entry : entries) {
+ if (entry.usage <= 0) continue;
+ if (entry.host == usage_host_) {
+ web_ui()->CallJavascriptFunction(
+ "settings.WebsiteUsagePrivateApi.returnUsageTotal",
+ base::StringValue(entry.host),
+ base::StringValue(ui::FormatBytes(entry.usage)));
+ return;
+ }
+ }
+}
+
+void SiteSettingsHandler::HandleFetchUsageTotal(
+ const base::ListValue* args) {
+ CHECK_EQ(1U, args->GetSize());
+ std::string host;
+ CHECK(args->GetString(0, &host));
+ usage_host_ = host;
+ storage_info_fetcher_ = new StorageInfoFetcher(
+ content::BrowserContext::GetDefaultStoragePartition(
+ profile_)->GetQuotaManager());
+ storage_info_fetcher_->AddObserver(this);
+ storage_info_fetcher_->Run();
+}
+
+} // namespace settings
« no previous file with comments | « chrome/browser/ui/webui/settings/site_settings_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698