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

Side by Side 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, 10 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h"
6
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/content_settings/core/common/content_settings_types.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/storage_partition.h"
13 #include "content/public/browser/web_ui.h"
14 #include "ui/base/text/bytes_formatting.h"
15
16 namespace settings {
17
18 SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
19 : profile_(profile) {
20 }
21
22 SiteSettingsHandler::~SiteSettingsHandler() {
23 if (storage_info_fetcher_.get())
24 storage_info_fetcher_->RemoveObserver(this);
25 }
26
27 void SiteSettingsHandler::RegisterMessages() {
28 web_ui()->RegisterMessageCallback(
29 "fetchUsageTotal",
30 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal,
31 base::Unretained(this)));
32 }
33
34 void SiteSettingsHandler::OnGetUsageInfo(
35 const storage::UsageInfoEntries& entries) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
37
38 for (const auto& entry : entries) {
39 if (entry.usage <= 0) continue;
40 if (entry.host == usage_host_) {
41 web_ui()->CallJavascriptFunction(
42 "settings.WebsiteUsagePrivateApi.returnUsageTotal",
43 base::StringValue(entry.host),
44 base::StringValue(ui::FormatBytes(entry.usage)));
45 return;
46 }
47 }
48 }
49
50 void SiteSettingsHandler::HandleFetchUsageTotal(
51 const base::ListValue* args) {
52 CHECK_EQ(1U, args->GetSize());
53 std::string host;
54 CHECK(args->GetString(0, &host));
55 usage_host_ = host;
56 storage_info_fetcher_ = new StorageInfoFetcher(
57 content::BrowserContext::GetDefaultStoragePartition(
58 profile_)->GetQuotaManager());
59 storage_info_fetcher_->AddObserver(this);
60 storage_info_fetcher_->Run();
61 }
62
63 } // namespace settings
OLDNEW
« 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