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

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: Augment test 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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 storage::UsageInfoEntries::const_iterator i;
39 for (i = entries.begin(); i != entries.end(); ++i) {
40 if (i->usage <= 0) continue;
41 if (i->host == usage_host_) {
42 web_ui()->CallJavascriptFunction(
43 "settings.WebsiteUsagePrivateApi.returnUsageTotal",
44 base::StringValue(ui::FormatBytes(i->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 origin;
54 CHECK(args->GetString(0, &origin));
55 GURL url(origin);
56 if (url.is_valid()) {
57 usage_host_ = url.host();
58 storage_info_fetcher_ = new StorageInfoFetcher(
59 content::BrowserContext::GetDefaultStoragePartition(
60 profile_)->GetQuotaManager());
61 storage_info_fetcher_->AddObserver(this);
62 storage_info_fetcher_->Run();
63 }
64 }
65
66 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698