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

Side by Side Diff: chrome/browser/browsing_data_database_helper.cc

Issue 10092013: Display third party cookies and site data counts in the WebsiteSettings UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browsing_data_database_helper.h" 5 #include "chrome/browser/browsing_data_database_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browsing_data_helper.h" 12 #include "chrome/browser/browsing_data_helper.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
20 20
21 using content::BrowserContext; 21 using content::BrowserContext;
22 using content::BrowserThread; 22 using content::BrowserThread;
23 using WebKit::WebSecurityOrigin; 23 using WebKit::WebSecurityOrigin;
24 24
25 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo()
26 : size(0) {
27 }
28
29 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo( 25 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo(
30 const std::string& host, 26 const std::string& host,
31 const std::string& database_name, 27 const std::string& database_name,
32 const std::string& origin_identifier, 28 const std::string& origin_identifier,
33 const std::string& description, 29 const std::string& description,
34 const std::string& origin, 30 const std::string& origin,
35 int64 size, 31 int64 size,
36 base::Time last_modified) 32 base::Time last_modified)
37 : host(host), 33 : host(host),
38 database_name(database_name), 34 database_name(database_name),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void BrowsingDataDatabaseHelper::DeleteDatabaseOnFileThread( 124 void BrowsingDataDatabaseHelper::DeleteDatabaseOnFileThread(
129 const std::string& origin, 125 const std::string& origin,
130 const std::string& name) { 126 const std::string& name) {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
132 if (!tracker_.get()) 128 if (!tracker_.get())
133 return; 129 return;
134 tracker_->DeleteDatabase(UTF8ToUTF16(origin), UTF8ToUTF16(name), 130 tracker_->DeleteDatabase(UTF8ToUTF16(origin), UTF8ToUTF16(name),
135 net::CompletionCallback()); 131 net::CompletionCallback());
136 } 132 }
137 133
138 CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo::PendingDatabaseInfo() {}
139
140 CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo::PendingDatabaseInfo( 134 CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo::PendingDatabaseInfo(
141 const GURL& origin, 135 const GURL& origin,
142 const std::string& name, 136 const std::string& name,
143 const std::string& description) 137 const std::string& description)
144 : origin(origin), 138 : origin(origin),
145 name(name), 139 name(name),
146 description(description) { 140 description(description) {
147 } 141 }
148 142
149 CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo::~PendingDatabaseInfo() {} 143 CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo::~PendingDatabaseInfo() {}
150 144
145 bool CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo::operator<(
146 const PendingDatabaseInfo& other) const {
147 return origin < other.origin;
Bernhard Bauer 2012/05/10 17:18:59 Doesn't this allow only one database per origin? I
markusheintz_ 2012/05/11 12:18:28 Done. I think we can ignore the description here.
148 }
149
151 CannedBrowsingDataDatabaseHelper::CannedBrowsingDataDatabaseHelper( 150 CannedBrowsingDataDatabaseHelper::CannedBrowsingDataDatabaseHelper(
152 Profile* profile) 151 Profile* profile)
153 : BrowsingDataDatabaseHelper(profile), 152 : BrowsingDataDatabaseHelper(profile),
154 profile_(profile) { 153 profile_(profile) {
155 } 154 }
156 155
157 CannedBrowsingDataDatabaseHelper* CannedBrowsingDataDatabaseHelper::Clone() { 156 CannedBrowsingDataDatabaseHelper* CannedBrowsingDataDatabaseHelper::Clone() {
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
159 CannedBrowsingDataDatabaseHelper* clone = 158 CannedBrowsingDataDatabaseHelper* clone =
160 new CannedBrowsingDataDatabaseHelper(profile_); 159 new CannedBrowsingDataDatabaseHelper(profile_);
161 160
162 base::AutoLock auto_lock(lock_); 161 base::AutoLock auto_lock(lock_);
163 clone->pending_database_info_ = pending_database_info_; 162 clone->pending_database_info_ = pending_database_info_;
164 clone->database_info_ = database_info_; 163 clone->database_info_ = database_info_;
165 return clone; 164 return clone;
166 } 165 }
167 166
168 void CannedBrowsingDataDatabaseHelper::AddDatabase( 167 void CannedBrowsingDataDatabaseHelper::AddDatabase(
169 const GURL& origin, 168 const GURL& origin,
170 const std::string& name, 169 const std::string& name,
171 const std::string& description) { 170 const std::string& description) {
172 base::AutoLock auto_lock(lock_); 171 base::AutoLock auto_lock(lock_);
173 if (BrowsingDataHelper::HasValidScheme(origin)) { 172 if (BrowsingDataHelper::HasValidScheme(origin)) {
174 pending_database_info_.push_back(PendingDatabaseInfo( 173 pending_database_info_.insert(PendingDatabaseInfo(
175 origin, name, description)); 174 origin, name, description));
176 } 175 }
177 } 176 }
178 177
179 void CannedBrowsingDataDatabaseHelper::Reset() { 178 void CannedBrowsingDataDatabaseHelper::Reset() {
180 base::AutoLock auto_lock(lock_); 179 base::AutoLock auto_lock(lock_);
181 database_info_.clear(); 180 database_info_.clear();
182 pending_database_info_.clear(); 181 pending_database_info_.clear();
183 } 182 }
184 183
185 bool CannedBrowsingDataDatabaseHelper::empty() const { 184 bool CannedBrowsingDataDatabaseHelper::empty() const {
186 base::AutoLock auto_lock(lock_); 185 base::AutoLock auto_lock(lock_);
187 return database_info_.empty() && pending_database_info_.empty(); 186 return pending_database_info_.empty();
188 } 187 }
189 188
190 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const { 189 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const {
190 base::AutoLock auto_lock(lock_);
191 return pending_database_info_.size(); 191 return pending_database_info_.size();
192 } 192 }
193 193
194 const std::set<CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo>&
195 CannedBrowsingDataDatabaseHelper::GetPendingDatabaseInfo() {
196 return pending_database_info_;
197 }
198
194 void CannedBrowsingDataDatabaseHelper::StartFetching( 199 void CannedBrowsingDataDatabaseHelper::StartFetching(
195 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { 200 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
197 DCHECK(!is_fetching_); 202 DCHECK(!is_fetching_);
198 DCHECK_EQ(false, callback.is_null()); 203 DCHECK_EQ(false, callback.is_null());
199 204
200 is_fetching_ = true; 205 is_fetching_ = true;
201 completion_callback_ = callback; 206 completion_callback_ = callback;
202 BrowserThread::PostTask( 207 BrowserThread::PostTask(
203 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, 208 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
204 base::Bind(&CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread, 209 base::Bind(&CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread,
205 this)); 210 this));
206 } 211 }
207 212
208 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {} 213 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {}
209 214
210 void CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread() { 215 void CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread() {
211 base::AutoLock auto_lock(lock_); 216 base::AutoLock auto_lock(lock_);
212 for (std::list<PendingDatabaseInfo>::const_iterator 217 database_info_.clear();
218 for (std::set<PendingDatabaseInfo>::const_iterator
213 info = pending_database_info_.begin(); 219 info = pending_database_info_.begin();
214 info != pending_database_info_.end(); ++info) { 220 info != pending_database_info_.end(); ++info) {
215 WebSecurityOrigin web_security_origin = 221 WebSecurityOrigin web_security_origin =
216 WebSecurityOrigin::createFromString( 222 WebSecurityOrigin::createFromString(
217 UTF8ToUTF16(info->origin.spec())); 223 UTF8ToUTF16(info->origin.spec()));
218 std::string origin_identifier = 224 std::string origin_identifier =
219 web_security_origin.databaseIdentifier().utf8(); 225 web_security_origin.databaseIdentifier().utf8();
220 226
221 bool duplicate = false;
222 for (std::list<DatabaseInfo>::iterator database = database_info_.begin();
223 database != database_info_.end(); ++database) {
224 if (database->origin_identifier == origin_identifier &&
225 database->database_name == info->name) {
226 duplicate = true;
227 break;
228 }
229 }
230 if (duplicate)
231 continue;
232
233 database_info_.push_back(DatabaseInfo( 227 database_info_.push_back(DatabaseInfo(
234 web_security_origin.host().utf8(), 228 web_security_origin.host().utf8(),
235 info->name, 229 info->name,
236 origin_identifier, 230 origin_identifier,
237 info->description, 231 info->description,
238 web_security_origin.toString().utf8(), 232 web_security_origin.toString().utf8(),
239 0, 233 0,
240 base::Time())); 234 base::Time()));
241 } 235 }
242 pending_database_info_.clear();
243 236
244 BrowserThread::PostTask( 237 BrowserThread::PostTask(
245 BrowserThread::UI, FROM_HERE, 238 BrowserThread::UI, FROM_HERE,
246 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); 239 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this));
247 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698