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

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: Address feedback and add owner 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.
michaelpg 2016/01/27 18:42:48 no (c)
Finnur 2016/01/28 11:17:49 Done.
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) {
michaelpg 2016/01/27 18:42:48 opt nit: consider "for (const auto& entry : entrie
Finnur 2016/01/28 11:17:49 Done.
40 if (i->usage <= 0) continue;
41 if (i->host == usage_host_) {
42 web_ui()->CallJavascriptFunction(
43 "settings.WebsiteUsagePrivateApi.returnUsageTotal",
44 base::StringValue(i->host),
45 base::StringValue(ui::FormatBytes(i->usage)));
46 return;
47 }
48 }
49 }
50
51 void SiteSettingsHandler::HandleFetchUsageTotal(
52 const base::ListValue* args) {
53 CHECK_EQ(1U, args->GetSize());
54 std::string host;
55 CHECK(args->GetString(0, &host));
56 usage_host_ = host;
57 storage_info_fetcher_ = new StorageInfoFetcher(
58 content::BrowserContext::GetDefaultStoragePartition(
59 profile_)->GetQuotaManager());
60 storage_info_fetcher_->AddObserver(this);
61 storage_info_fetcher_->Run();
62 }
63
64 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698