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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_cache_storage_helper.cc

Issue 1297093002: Cache Storage API: Hook up to chrome://settings/cookies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: copy/paste in OSX, sigh Created 5 years, 4 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 2015 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/browsing_data/browsing_data_cache_storage_helper.h"
6
7 #include <vector>
8
9 #include "base/bind.h"
10 #include "chrome/browser/browsing_data/browsing_data_helper.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/cache_storage_context.h"
13
14 using content::BrowserThread;
15 using content::CacheStorageContext;
16 using content::CacheStorageUsageInfo;
17
18 BrowsingDataCacheStorageHelper::BrowsingDataCacheStorageHelper(
19 CacheStorageContext* cache_storage_context)
20 : cache_storage_context_(cache_storage_context) {
21 DCHECK(cache_storage_context_);
22 }
23
24 BrowsingDataCacheStorageHelper::~BrowsingDataCacheStorageHelper() {}
25
26 void BrowsingDataCacheStorageHelper::StartFetching(
27 const FetchCallback& callback) {
28 DCHECK_CURRENTLY_ON(BrowserThread::UI);
29 BrowserThread::PostTask(
30 BrowserThread::IO, FROM_HERE,
31 base::Bind(
32 &BrowsingDataCacheStorageHelper::FetchCacheStorageUsageInfoOnIOThread,
33 this, callback));
34 }
35
36 void BrowsingDataCacheStorageHelper::DeleteCacheStorage(const GURL& origin) {
37 DCHECK_CURRENTLY_ON(BrowserThread::UI);
38 BrowserThread::PostTask(
39 BrowserThread::IO, FROM_HERE,
40 base::Bind(&BrowsingDataCacheStorageHelper::DeleteCacheStorageOnIOThread,
41 this, origin));
42 }
43
44 void BrowsingDataCacheStorageHelper::FetchCacheStorageUsageInfoOnIOThread(
45 const FetchCallback& callback) {
46 DCHECK_CURRENTLY_ON(BrowserThread::IO);
47 cache_storage_context_->GetAllOriginsInfo(
48 base::Bind(&BrowsingDataCacheStorageHelper::GetAllOriginsInfoCallback,
49 this, callback));
50 }
51
52 void BrowsingDataCacheStorageHelper::GetAllOriginsInfoCallback(
53 const FetchCallback& callback,
54 const std::vector<CacheStorageUsageInfo>& origins) {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO);
56
57 std::list<content::CacheStorageUsageInfo> result;
58 for (const CacheStorageUsageInfo& origin : origins) {
59 if (!BrowsingDataHelper::HasWebScheme(origin.origin))
60 continue; // Non-websafe state is not considered browsing data.
61 result.push_back(origin);
62 }
63
64 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
65 base::Bind(callback, result));
66 }
67
68 void BrowsingDataCacheStorageHelper::DeleteCacheStorageOnIOThread(
69 const GURL& origin) {
70 DCHECK_CURRENTLY_ON(BrowserThread::IO);
71 cache_storage_context_->DeleteForOrigin(origin);
72 }
73
74 CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo::
75 PendingCacheStorageUsageInfo(const GURL& origin,
76 int64 total_size_bytes,
77 const base::Time& last_modified)
78 : origin(origin),
79 total_size_bytes(total_size_bytes),
80 last_modified(last_modified) {}
81
82 CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo::
83 ~PendingCacheStorageUsageInfo() {}
84
85 bool CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo::
86 operator<(const PendingCacheStorageUsageInfo& other) const {
87 return origin < other.origin;
88 }
89
90 CannedBrowsingDataCacheStorageHelper::CannedBrowsingDataCacheStorageHelper(
91 content::CacheStorageContext* context)
92 : BrowsingDataCacheStorageHelper(context) {}
93
94 CannedBrowsingDataCacheStorageHelper::~CannedBrowsingDataCacheStorageHelper() {}
95
96 void CannedBrowsingDataCacheStorageHelper::AddCacheStorage(const GURL& origin) {
97 if (!BrowsingDataHelper::HasWebScheme(origin))
98 return; // Non-websafe state is not considered browsing data.
99
100 pending_cache_storage_info_.insert(
101 PendingCacheStorageUsageInfo(origin, 0, base::Time()));
102 }
103
104 void CannedBrowsingDataCacheStorageHelper::Reset() {
105 pending_cache_storage_info_.clear();
106 }
107
108 bool CannedBrowsingDataCacheStorageHelper::empty() const {
109 return pending_cache_storage_info_.empty();
110 }
111
112 size_t CannedBrowsingDataCacheStorageHelper::GetCacheStorageCount() const {
113 return pending_cache_storage_info_.size();
114 }
115
116 const std::set<
117 CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo>&
118 CannedBrowsingDataCacheStorageHelper::GetCacheStorageUsageInfo() const {
119 return pending_cache_storage_info_;
120 }
121
122 void CannedBrowsingDataCacheStorageHelper::StartFetching(
123 const base::Callback<void(const std::list<CacheStorageUsageInfo>&)>&
124 callback) {
125 DCHECK_CURRENTLY_ON(BrowserThread::UI);
126 DCHECK(!callback.is_null());
127
128 std::list<CacheStorageUsageInfo> result;
129 for (const PendingCacheStorageUsageInfo& pending_info :
130 pending_cache_storage_info_) {
131 CacheStorageUsageInfo info(pending_info.origin,
132 pending_info.total_size_bytes,
133 pending_info.last_modified);
134 result.push_back(info);
135 }
136
137 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
138 base::Bind(callback, result));
139 }
140
141 void CannedBrowsingDataCacheStorageHelper::DeleteCacheStorage(
142 const GURL& origin) {
143 for (std::set<PendingCacheStorageUsageInfo>::iterator it =
144 pending_cache_storage_info_.begin();
145 it != pending_cache_storage_info_.end();) {
146 if (it->origin == origin)
147 pending_cache_storage_info_.erase(it++);
148 else
149 ++it;
150 }
151 BrowsingDataCacheStorageHelper::DeleteCacheStorage(origin);
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698