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

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: "Fix CannedBrowsingDataDatabaseHelperTest.*" 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 if (origin == other.origin)
148 return name < other.name;
149 return origin < other.origin;
150 }
151
151 CannedBrowsingDataDatabaseHelper::CannedBrowsingDataDatabaseHelper( 152 CannedBrowsingDataDatabaseHelper::CannedBrowsingDataDatabaseHelper(
152 Profile* profile) 153 Profile* profile)
153 : BrowsingDataDatabaseHelper(profile), 154 : BrowsingDataDatabaseHelper(profile),
154 profile_(profile) { 155 profile_(profile) {
155 } 156 }
156 157
157 CannedBrowsingDataDatabaseHelper* CannedBrowsingDataDatabaseHelper::Clone() { 158 CannedBrowsingDataDatabaseHelper* CannedBrowsingDataDatabaseHelper::Clone() {
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
159 CannedBrowsingDataDatabaseHelper* clone = 160 CannedBrowsingDataDatabaseHelper* clone =
160 new CannedBrowsingDataDatabaseHelper(profile_); 161 new CannedBrowsingDataDatabaseHelper(profile_);
161 162
162 base::AutoLock auto_lock(lock_); 163 base::AutoLock auto_lock(lock_);
163 clone->pending_database_info_ = pending_database_info_; 164 clone->pending_database_info_ = pending_database_info_;
164 clone->database_info_ = database_info_;
165 return clone; 165 return clone;
166 } 166 }
167 167
168 void CannedBrowsingDataDatabaseHelper::AddDatabase( 168 void CannedBrowsingDataDatabaseHelper::AddDatabase(
169 const GURL& origin, 169 const GURL& origin,
170 const std::string& name, 170 const std::string& name,
171 const std::string& description) { 171 const std::string& description) {
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
172 base::AutoLock auto_lock(lock_); 173 base::AutoLock auto_lock(lock_);
173 if (BrowsingDataHelper::HasValidScheme(origin)) { 174 if (BrowsingDataHelper::HasValidScheme(origin)) {
174 pending_database_info_.push_back(PendingDatabaseInfo( 175 pending_database_info_.insert(PendingDatabaseInfo(
175 origin, name, description)); 176 origin, name, description));
176 } 177 }
177 } 178 }
178 179
179 void CannedBrowsingDataDatabaseHelper::Reset() { 180 void CannedBrowsingDataDatabaseHelper::Reset() {
180 base::AutoLock auto_lock(lock_); 181 base::AutoLock auto_lock(lock_);
181 database_info_.clear();
182 pending_database_info_.clear(); 182 pending_database_info_.clear();
183 } 183 }
184 184
185 bool CannedBrowsingDataDatabaseHelper::empty() const { 185 bool CannedBrowsingDataDatabaseHelper::empty() const {
186 base::AutoLock auto_lock(lock_); 186 base::AutoLock auto_lock(lock_);
187 return database_info_.empty() && pending_database_info_.empty(); 187 return pending_database_info_.empty();
188 } 188 }
189 189
190 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const { 190 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const {
191 base::AutoLock auto_lock(lock_);
191 return pending_database_info_.size(); 192 return pending_database_info_.size();
192 } 193 }
193 194
195 const std::set<CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo>&
196 CannedBrowsingDataDatabaseHelper::GetPendingDatabaseInfo() {
197 return pending_database_info_;
198 }
199
194 void CannedBrowsingDataDatabaseHelper::StartFetching( 200 void CannedBrowsingDataDatabaseHelper::StartFetching(
195 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { 201 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
197 DCHECK(!is_fetching_); 203 DCHECK(!is_fetching_);
198 DCHECK_EQ(false, callback.is_null()); 204 DCHECK_EQ(false, callback.is_null());
199 205
200 is_fetching_ = true; 206 is_fetching_ = true;
201 completion_callback_ = callback; 207 completion_callback_ = callback;
202 BrowserThread::PostTask( 208 BrowserThread::PostTask(
203 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, 209 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
204 base::Bind(&CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread, 210 base::Bind(&CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread,
205 this)); 211 this));
206 } 212 }
207 213
208 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {} 214 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {}
209 215
210 void CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread() { 216 void CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread() {
211 base::AutoLock auto_lock(lock_); 217 base::AutoLock auto_lock(lock_);
212 for (std::list<PendingDatabaseInfo>::const_iterator 218 database_info_.clear();
219 for (std::set<PendingDatabaseInfo>::const_iterator
213 info = pending_database_info_.begin(); 220 info = pending_database_info_.begin();
214 info != pending_database_info_.end(); ++info) { 221 info != pending_database_info_.end(); ++info) {
215 WebSecurityOrigin web_security_origin = 222 WebSecurityOrigin web_security_origin =
216 WebSecurityOrigin::createFromString( 223 WebSecurityOrigin::createFromString(
217 UTF8ToUTF16(info->origin.spec())); 224 UTF8ToUTF16(info->origin.spec()));
218 std::string origin_identifier = 225 std::string origin_identifier =
219 web_security_origin.databaseIdentifier().utf8(); 226 web_security_origin.databaseIdentifier().utf8();
220 227
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( 228 database_info_.push_back(DatabaseInfo(
234 web_security_origin.host().utf8(), 229 web_security_origin.host().utf8(),
235 info->name, 230 info->name,
236 origin_identifier, 231 origin_identifier,
237 info->description, 232 info->description,
238 web_security_origin.toString().utf8(), 233 web_security_origin.toString().utf8(),
239 0, 234 0,
240 base::Time())); 235 base::Time()));
241 } 236 }
242 pending_database_info_.clear();
243 237
244 BrowserThread::PostTask( 238 BrowserThread::PostTask(
245 BrowserThread::UI, FROM_HERE, 239 BrowserThread::UI, FROM_HERE,
246 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); 240 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this));
247 } 241 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_database_helper.h ('k') | chrome/browser/browsing_data_database_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698