| OLD | NEW |
| 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 Loading... |
| 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 clone->database_info_ = database_info_; |
| 165 return clone; | 166 return clone; |
| 166 } | 167 } |
| 167 | 168 |
| 168 void CannedBrowsingDataDatabaseHelper::AddDatabase( | 169 void CannedBrowsingDataDatabaseHelper::AddDatabase( |
| 169 const GURL& origin, | 170 const GURL& origin, |
| 170 const std::string& name, | 171 const std::string& name, |
| 171 const std::string& description) { | 172 const std::string& description) { |
| 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 database_info_.clear(); |
| 182 pending_database_info_.clear(); | 183 pending_database_info_.clear(); |
| 183 } | 184 } |
| 184 | 185 |
| 185 bool CannedBrowsingDataDatabaseHelper::empty() const { | 186 bool CannedBrowsingDataDatabaseHelper::empty() const { |
| 186 base::AutoLock auto_lock(lock_); | 187 base::AutoLock auto_lock(lock_); |
| 187 return database_info_.empty() && pending_database_info_.empty(); | 188 return pending_database_info_.empty(); |
| 188 } | 189 } |
| 189 | 190 |
| 190 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const { | 191 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const { |
| 192 base::AutoLock auto_lock(lock_); |
| 191 return pending_database_info_.size(); | 193 return pending_database_info_.size(); |
| 192 } | 194 } |
| 193 | 195 |
| 196 const std::set<CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo>& |
| 197 CannedBrowsingDataDatabaseHelper::GetPendingDatabaseInfo() { |
| 198 return pending_database_info_; |
| 199 } |
| 200 |
| 194 void CannedBrowsingDataDatabaseHelper::StartFetching( | 201 void CannedBrowsingDataDatabaseHelper::StartFetching( |
| 195 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { | 202 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 197 DCHECK(!is_fetching_); | 204 DCHECK(!is_fetching_); |
| 198 DCHECK_EQ(false, callback.is_null()); | 205 DCHECK_EQ(false, callback.is_null()); |
| 199 | 206 |
| 200 is_fetching_ = true; | 207 is_fetching_ = true; |
| 201 completion_callback_ = callback; | 208 completion_callback_ = callback; |
| 202 BrowserThread::PostTask( | 209 BrowserThread::PostTask( |
| 203 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 210 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| 204 base::Bind(&CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread, | 211 base::Bind(&CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread, |
| 205 this)); | 212 this)); |
| 206 } | 213 } |
| 207 | 214 |
| 208 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {} | 215 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {} |
| 209 | 216 |
| 210 void CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread() { | 217 void CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread() { |
| 211 base::AutoLock auto_lock(lock_); | 218 base::AutoLock auto_lock(lock_); |
| 212 for (std::list<PendingDatabaseInfo>::const_iterator | 219 database_info_.clear(); |
| 220 for (std::set<PendingDatabaseInfo>::const_iterator |
| 213 info = pending_database_info_.begin(); | 221 info = pending_database_info_.begin(); |
| 214 info != pending_database_info_.end(); ++info) { | 222 info != pending_database_info_.end(); ++info) { |
| 215 WebSecurityOrigin web_security_origin = | 223 WebSecurityOrigin web_security_origin = |
| 216 WebSecurityOrigin::createFromString( | 224 WebSecurityOrigin::createFromString( |
| 217 UTF8ToUTF16(info->origin.spec())); | 225 UTF8ToUTF16(info->origin.spec())); |
| 218 std::string origin_identifier = | 226 std::string origin_identifier = |
| 219 web_security_origin.databaseIdentifier().utf8(); | 227 web_security_origin.databaseIdentifier().utf8(); |
| 220 | 228 |
| 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( | 229 database_info_.push_back(DatabaseInfo( |
| 234 web_security_origin.host().utf8(), | 230 web_security_origin.host().utf8(), |
| 235 info->name, | 231 info->name, |
| 236 origin_identifier, | 232 origin_identifier, |
| 237 info->description, | 233 info->description, |
| 238 web_security_origin.toString().utf8(), | 234 web_security_origin.toString().utf8(), |
| 239 0, | 235 0, |
| 240 base::Time())); | 236 base::Time())); |
| 241 } | 237 } |
| 242 pending_database_info_.clear(); | |
| 243 | 238 |
| 244 BrowserThread::PostTask( | 239 BrowserThread::PostTask( |
| 245 BrowserThread::UI, FROM_HERE, | 240 BrowserThread::UI, FROM_HERE, |
| 246 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); | 241 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); |
| 247 } | 242 } |
| OLD | NEW |