Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
|
michaelpg
2016/01/19 20:47:54
nit: include values.h
Finnur
2016/01/22 15:07:35
Done.
| |
| 8 #include "chrome/browser/content_settings/storage_info_fetcher.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "components/content_settings/core/common/content_settings_types.h" | |
| 11 #include "content/public/browser/storage_partition.h" | |
| 12 #include "content/public/browser/web_ui.h" | |
| 13 #include "ui/base/text/bytes_formatting.h" | |
| 14 | |
| 15 // Handles fetching StorageInfo and report back to the SiteSettingsHandler. | |
| 16 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.
| |
| 17 public: | |
| 18 MDSettingsStorageInfoFetcher(storage::QuotaManager* quota_manager, | |
| 19 content::WebUI* web_ui, | |
| 20 const std::string& host) | |
| 21 : StorageInfoFetcher(quota_manager), | |
| 22 web_ui_(web_ui), | |
| 23 host_(host) {} | |
| 24 | |
| 25 protected: | |
| 26 void OnGetUsageInfo(const storage::UsageInfoEntries& entries) override { | |
| 27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 28 | |
| 29 storage::UsageInfoEntries::const_iterator i; | |
| 30 for (i = entries.begin(); i != entries.end(); ++i) { | |
| 31 if (i->usage <= 0) continue; | |
| 32 if (i->host == host_) { | |
| 33 web_ui_->CallJavascriptFunction( | |
| 34 "SiteSettingsHandler.OnUsageDataAvailable", | |
| 35 base::StringValue(ui::FormatBytes(i->usage))); | |
| 36 return; | |
| 37 } | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 private: | |
| 42 ~MDSettingsStorageInfoFetcher() override {} | |
| 43 | |
| 44 content::WebUI* web_ui_; | |
| 45 std::string host_; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(MDSettingsStorageInfoFetcher); | |
| 48 }; | |
| 49 | |
| 50 namespace settings { | |
| 51 | |
| 52 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) | |
| 53 : profile_(profile) { | |
| 54 } | |
| 55 | |
| 56 SiteSettingsHandler::~SiteSettingsHandler() { | |
| 57 } | |
| 58 | |
| 59 void SiteSettingsHandler::RegisterMessages() { | |
| 60 web_ui()->RegisterMessageCallback( | |
| 61 "fetchUsageTotal", | |
| 62 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal, | |
| 63 base::Unretained(this))); | |
| 64 } | |
| 65 | |
| 66 void SiteSettingsHandler::HandleFetchUsageTotal( | |
| 67 const base::ListValue* args) { | |
| 68 CHECK_EQ(1U, args->GetSize()); | |
| 69 std::string origin; | |
| 70 CHECK(args->GetString(0, &origin)); | |
| 71 GURL url(origin); | |
| 72 if (url.is_valid()) { | |
| 73 scoped_refptr<MDSettingsStorageInfoFetcher> storage_info_fetcher( | |
| 74 new MDSettingsStorageInfoFetcher( | |
| 75 content::BrowserContext::GetDefaultStoragePartition( | |
| 76 profile_)->GetQuotaManager(), web_ui(), url.host())); | |
| 77 storage_info_fetcher->Run(); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 } // namespace settings | |
| OLD | NEW |