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..966d26cdbea8173d9dbddeaffb6e40a667d68c6f |
--- /dev/null |
+++ b/chrome/browser/ui/webui/settings/site_settings_handler.cc |
@@ -0,0 +1,81 @@ |
+// 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" |
michaelpg
2016/01/19 20:47:54
nit: include values.h
Finnur
2016/01/22 15:07:35
Done.
|
+#include "chrome/browser/content_settings/storage_info_fetcher.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "components/content_settings/core/common/content_settings_types.h" |
+#include "content/public/browser/storage_partition.h" |
+#include "content/public/browser/web_ui.h" |
+#include "ui/base/text/bytes_formatting.h" |
+ |
+// Handles fetching StorageInfo and report back to the SiteSettingsHandler. |
+class MDSettingsStorageInfoFetcher : public StorageInfoFetcher { |
michaelpg
2016/01/19 20:47:54
discussion question: Would it be better to compose
Finnur
2016/01/22 15:07:35
Yeah, I like that.
|
+ public: |
+ MDSettingsStorageInfoFetcher(storage::QuotaManager* quota_manager, |
+ content::WebUI* web_ui, |
+ const std::string& host) |
+ : StorageInfoFetcher(quota_manager), |
+ web_ui_(web_ui), |
+ host_(host) {} |
+ |
+ protected: |
+ void OnGetUsageInfo(const storage::UsageInfoEntries& entries) override { |
+ 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 == host_) { |
+ web_ui_->CallJavascriptFunction( |
+ "SiteSettingsHandler.OnUsageDataAvailable", |
+ base::StringValue(ui::FormatBytes(i->usage))); |
+ return; |
+ } |
+ } |
+ } |
+ |
+ private: |
+ ~MDSettingsStorageInfoFetcher() override {} |
+ |
+ content::WebUI* web_ui_; |
+ std::string host_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MDSettingsStorageInfoFetcher); |
+}; |
+ |
+namespace settings { |
+ |
+SiteSettingsHandler::SiteSettingsHandler(Profile* profile) |
+ : profile_(profile) { |
+} |
+ |
+SiteSettingsHandler::~SiteSettingsHandler() { |
+} |
+ |
+void SiteSettingsHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback( |
+ "fetchUsageTotal", |
+ base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal, |
+ base::Unretained(this))); |
+} |
+ |
+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()) { |
+ scoped_refptr<MDSettingsStorageInfoFetcher> storage_info_fetcher( |
+ new MDSettingsStorageInfoFetcher( |
+ content::BrowserContext::GetDefaultStoragePartition( |
+ profile_)->GetQuotaManager(), web_ui(), url.host())); |
+ storage_info_fetcher->Run(); |
+ } |
+} |
+ |
+} // namespace settings |