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

Side by Side Diff: chrome/browser/ui/webui/settings/site_settings_handler.cc

Issue 1661533002: Implement deletion of storage per site. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h" 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "components/content_settings/core/common/content_settings_types.h" 11 #include "components/content_settings/core/common/content_settings_types.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/storage_partition.h" 13 #include "content/public/browser/storage_partition.h"
13 #include "content/public/browser/web_ui.h" 14 #include "content/public/browser/web_ui.h"
14 #include "ui/base/text/bytes_formatting.h" 15 #include "ui/base/text/bytes_formatting.h"
15 16
16 namespace settings { 17 namespace settings {
17 18
18 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) 19 SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
19 : profile_(profile) { 20 : profile_(profile) {
20 } 21 }
21 22
22 SiteSettingsHandler::~SiteSettingsHandler() { 23 SiteSettingsHandler::~SiteSettingsHandler() {
23 if (storage_info_fetcher_.get()) 24 if (storage_info_fetcher_.get())
24 storage_info_fetcher_->RemoveObserver(this); 25 storage_info_fetcher_->RemoveObserver(this);
25 } 26 }
26 27
27 void SiteSettingsHandler::RegisterMessages() { 28 void SiteSettingsHandler::RegisterMessages() {
28 web_ui()->RegisterMessageCallback( 29 web_ui()->RegisterMessageCallback(
29 "fetchUsageTotal", 30 "fetchUsageTotal",
30 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal, 31 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal,
31 base::Unretained(this))); 32 base::Unretained(this)));
33 web_ui()->RegisterMessageCallback(
34 "clearUsage",
35 base::Bind(&SiteSettingsHandler::HandleClearUsage,
36 base::Unretained(this)));
32 } 37 }
33 38
34 void SiteSettingsHandler::OnGetUsageInfo( 39 void SiteSettingsHandler::OnGetUsageInfo(
35 const storage::UsageInfoEntries& entries) { 40 const storage::UsageInfoEntries& entries) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
37 42
38 for (const auto& entry : entries) { 43 for (const auto& entry : entries) {
39 if (entry.usage <= 0) continue; 44 if (entry.usage <= 0) continue;
40 if (entry.host == usage_host_) { 45 if (entry.host == usage_host_) {
41 web_ui()->CallJavascriptFunction( 46 web_ui()->CallJavascriptFunction(
42 "settings.WebsiteUsagePrivateApi.returnUsageTotal", 47 "settings.WebsiteUsagePrivateApi.returnUsageTotal",
43 base::StringValue(entry.host), 48 base::StringValue(entry.host),
44 base::StringValue(ui::FormatBytes(entry.usage))); 49 base::StringValue(ui::FormatBytes(entry.usage)),
45 return; 50 base::FundamentalValue(entry.type));
46 } 51 }
47 } 52 }
48 } 53 }
49 54
55 void SiteSettingsHandler::OnUsageInfoCleared() {
56 }
57
50 void SiteSettingsHandler::HandleFetchUsageTotal( 58 void SiteSettingsHandler::HandleFetchUsageTotal(
51 const base::ListValue* args) { 59 const base::ListValue* args) {
52 CHECK_EQ(1U, args->GetSize()); 60 CHECK_EQ(1U, args->GetSize());
53 std::string host; 61 std::string host;
54 CHECK(args->GetString(0, &host)); 62 CHECK(args->GetString(0, &host));
55 usage_host_ = host; 63 usage_host_ = host;
56 storage_info_fetcher_ = new StorageInfoFetcher( 64 storage::QuotaManager* quota_manager =
57 content::BrowserContext::GetDefaultStoragePartition( 65 content::BrowserContext::GetDefaultStoragePartition(
58 profile_)->GetQuotaManager()); 66 profile_)->GetQuotaManager();
67 storage_info_fetcher_ = new StorageInfoFetcher(quota_manager);
59 storage_info_fetcher_->AddObserver(this); 68 storage_info_fetcher_->AddObserver(this);
60 storage_info_fetcher_->Run(); 69 storage_info_fetcher_->FetchStorageInfo();
70 }
71
72 void SiteSettingsHandler::HandleClearUsage(
73 const base::ListValue* args) {
74 CHECK_EQ(2U, args->GetSize());
75 std::string origin;
76 CHECK(args->GetString(0, &origin));
77 int type;
78 CHECK(args->GetInteger(1, &type));
79
80 GURL url(origin);
81 if (url.is_valid()) {
82 // Start by clearing the storage data asynchronously.
83 storage::QuotaManager* quota_manager =
84 content::BrowserContext::GetDefaultStoragePartition(
85 profile_)->GetQuotaManager();
86 storage_info_fetcher_ = new StorageInfoFetcher(quota_manager);
michaelpg 2016/02/03 18:39:13 Why is it necessary to re-initialize this if it al
Finnur 2016/02/04 14:56:58 I suppose it isn't necessary. I do have an upcomin
87 storage_info_fetcher_->AddObserver(this);
88 storage_info_fetcher_->ClearStorage(
89 url.host(), static_cast<storage::StorageType>(type));
90
91 // Also clear the *local* storage data.
92 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper =
93 new BrowsingDataLocalStorageHelper(profile_);
94 local_storage_helper->DeleteOrigin(url);
95 }
61 } 96 }
62 97
63 } // namespace settings 98 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698