Chromium Code Reviews| 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/browsing_data_database_helper.h" | 5 #include "chrome/browser/browsing_data/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/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 12 #include "chrome/browser/browsing_data/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 "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "third_party/WebKit/public/platform/WebCString.h" | 18 #include "third_party/WebKit/public/platform/WebCString.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 20 #include "webkit/common/database/database_identifier.h" |
| 21 | 21 |
| 22 using content::BrowserContext; | 22 using content::BrowserContext; |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 using WebKit::WebSecurityOrigin; | 24 using webkit_database::DatabaseIdentifier; |
| 25 | 25 |
| 26 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo( | 26 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo( |
| 27 const std::string& host, | 27 const DatabaseIdentifier& identifier, |
| 28 const std::string& database_name, | 28 const std::string& database_name, |
| 29 const std::string& origin_identifier, | |
| 30 const std::string& description, | 29 const std::string& description, |
| 31 const std::string& origin, | |
| 32 int64 size, | 30 int64 size, |
| 33 base::Time last_modified) | 31 base::Time last_modified) |
| 34 : host(host), | 32 : identifier(identifier), |
| 35 database_name(database_name), | 33 database_name(database_name), |
| 36 origin_identifier(origin_identifier), | |
| 37 description(description), | 34 description(description), |
| 38 origin(origin), | |
| 39 size(size), | 35 size(size), |
| 40 last_modified(last_modified) { | 36 last_modified(last_modified) { |
| 41 } | 37 } |
| 42 | 38 |
| 43 BrowsingDataDatabaseHelper::DatabaseInfo::~DatabaseInfo() {} | 39 BrowsingDataDatabaseHelper::DatabaseInfo::~DatabaseInfo() {} |
| 44 | 40 |
| 45 BrowsingDataDatabaseHelper::BrowsingDataDatabaseHelper(Profile* profile) | 41 BrowsingDataDatabaseHelper::BrowsingDataDatabaseHelper(Profile* profile) |
| 46 : is_fetching_(false), | 42 : is_fetching_(false), |
| 47 tracker_(BrowserContext:: | 43 tracker_(BrowserContext:: |
| 48 GetDefaultStoragePartition(profile)->GetDatabaseTracker()) { | 44 GetDefaultStoragePartition(profile)->GetDatabaseTracker()) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 74 base::Bind(&BrowsingDataDatabaseHelper::DeleteDatabaseOnFileThread, this, | 70 base::Bind(&BrowsingDataDatabaseHelper::DeleteDatabaseOnFileThread, this, |
| 75 origin, name)); | 71 origin, name)); |
| 76 } | 72 } |
| 77 | 73 |
| 78 void BrowsingDataDatabaseHelper::FetchDatabaseInfoOnFileThread() { | 74 void BrowsingDataDatabaseHelper::FetchDatabaseInfoOnFileThread() { |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 80 std::vector<webkit_database::OriginInfo> origins_info; | 76 std::vector<webkit_database::OriginInfo> origins_info; |
| 81 if (tracker_.get() && tracker_->GetAllOriginsInfo(&origins_info)) { | 77 if (tracker_.get() && tracker_->GetAllOriginsInfo(&origins_info)) { |
| 82 for (std::vector<webkit_database::OriginInfo>::const_iterator ori = | 78 for (std::vector<webkit_database::OriginInfo>::const_iterator ori = |
| 83 origins_info.begin(); ori != origins_info.end(); ++ori) { | 79 origins_info.begin(); ori != origins_info.end(); ++ori) { |
| 84 WebSecurityOrigin web_security_origin = | 80 DatabaseIdentifier identifier = |
| 85 WebSecurityOrigin::createFromDatabaseIdentifier( | 81 DatabaseIdentifier::Parse(ori->GetOriginIdentifier()); |
| 86 WebKit::WebString::fromUTF8(ori->GetOriginIdentifier())); | 82 if (!BrowsingDataHelper::HasWebScheme(identifier.ToOrigin())) { |
| 87 GURL origin_url(web_security_origin.toString().utf8()); | |
| 88 if (!BrowsingDataHelper::HasWebScheme(origin_url)) { | |
| 89 // Non-websafe state is not considered browsing data. | 83 // Non-websafe state is not considered browsing data. |
| 90 continue; | 84 continue; |
| 91 } | 85 } |
| 92 std::vector<string16> databases; | 86 std::vector<string16> databases; |
| 93 ori->GetAllDatabaseNames(&databases); | 87 ori->GetAllDatabaseNames(&databases); |
| 94 for (std::vector<string16>::const_iterator db = databases.begin(); | 88 for (std::vector<string16>::const_iterator db = databases.begin(); |
| 95 db != databases.end(); ++db) { | 89 db != databases.end(); ++db) { |
| 96 base::FilePath file_path = | 90 base::FilePath file_path = |
| 97 tracker_->GetFullDBFilePath(ori->GetOriginIdentifier(), *db); | 91 tracker_->GetFullDBFilePath(ori->GetOriginIdentifier(), *db); |
| 98 base::PlatformFileInfo file_info; | 92 base::PlatformFileInfo file_info; |
| 99 if (file_util::GetFileInfo(file_path, &file_info)) { | 93 if (file_util::GetFileInfo(file_path, &file_info)) { |
| 100 database_info_.push_back(DatabaseInfo( | 94 database_info_.push_back(DatabaseInfo( |
| 101 web_security_origin.host().utf8(), | 95 identifier, |
| 102 UTF16ToUTF8(*db), | 96 UTF16ToUTF8(*db), |
| 103 ori->GetOriginIdentifier(), | |
| 104 UTF16ToUTF8(ori->GetDatabaseDescription(*db)), | 97 UTF16ToUTF8(ori->GetDatabaseDescription(*db)), |
| 105 origin_url.spec(), | |
| 106 file_info.size, | 98 file_info.size, |
| 107 file_info.last_modified)); | 99 file_info.last_modified)); |
| 108 } | 100 } |
| 109 } | 101 } |
| 110 } | 102 } |
| 111 } | 103 } |
| 112 | 104 |
| 113 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
| 114 BrowserThread::UI, FROM_HERE, | 106 BrowserThread::UI, FROM_HERE, |
| 115 base::Bind(&BrowsingDataDatabaseHelper::NotifyInUIThread, this)); | 107 base::Bind(&BrowsingDataDatabaseHelper::NotifyInUIThread, this)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 Profile* profile) | 148 Profile* profile) |
| 157 : BrowsingDataDatabaseHelper(profile), | 149 : BrowsingDataDatabaseHelper(profile), |
| 158 profile_(profile) { | 150 profile_(profile) { |
| 159 } | 151 } |
| 160 | 152 |
| 161 CannedBrowsingDataDatabaseHelper* CannedBrowsingDataDatabaseHelper::Clone() { | 153 CannedBrowsingDataDatabaseHelper* CannedBrowsingDataDatabaseHelper::Clone() { |
| 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 163 CannedBrowsingDataDatabaseHelper* clone = | 155 CannedBrowsingDataDatabaseHelper* clone = |
| 164 new CannedBrowsingDataDatabaseHelper(profile_); | 156 new CannedBrowsingDataDatabaseHelper(profile_); |
| 165 | 157 |
| 166 base::AutoLock auto_lock(lock_); | |
| 167 clone->pending_database_info_ = pending_database_info_; | 158 clone->pending_database_info_ = pending_database_info_; |
| 168 return clone; | 159 return clone; |
| 169 } | 160 } |
| 170 | 161 |
| 171 void CannedBrowsingDataDatabaseHelper::AddDatabase( | 162 void CannedBrowsingDataDatabaseHelper::AddDatabase( |
| 172 const GURL& origin, | 163 const GURL& origin, |
| 173 const std::string& name, | 164 const std::string& name, |
| 174 const std::string& description) { | 165 const std::string& description) { |
| 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 176 base::AutoLock auto_lock(lock_); | |
| 177 if (BrowsingDataHelper::HasWebScheme(origin)) { | 167 if (BrowsingDataHelper::HasWebScheme(origin)) { |
| 178 pending_database_info_.insert(PendingDatabaseInfo( | 168 pending_database_info_.insert(PendingDatabaseInfo( |
| 179 origin, name, description)); | 169 origin, name, description)); |
| 180 } | 170 } |
| 181 } | 171 } |
| 182 | 172 |
| 183 void CannedBrowsingDataDatabaseHelper::Reset() { | 173 void CannedBrowsingDataDatabaseHelper::Reset() { |
| 184 base::AutoLock auto_lock(lock_); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 185 pending_database_info_.clear(); | 175 pending_database_info_.clear(); |
| 186 } | 176 } |
| 187 | 177 |
| 188 bool CannedBrowsingDataDatabaseHelper::empty() const { | 178 bool CannedBrowsingDataDatabaseHelper::empty() const { |
| 189 base::AutoLock auto_lock(lock_); | 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 190 return pending_database_info_.empty(); | 180 return pending_database_info_.empty(); |
| 191 } | 181 } |
| 192 | 182 |
| 193 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const { | 183 size_t CannedBrowsingDataDatabaseHelper::GetDatabaseCount() const { |
| 194 base::AutoLock auto_lock(lock_); | 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 195 return pending_database_info_.size(); | 185 return pending_database_info_.size(); |
| 196 } | 186 } |
| 197 | 187 |
| 198 const std::set<CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo>& | 188 const std::set<CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo>& |
| 199 CannedBrowsingDataDatabaseHelper::GetPendingDatabaseInfo() { | 189 CannedBrowsingDataDatabaseHelper::GetPendingDatabaseInfo() { |
| 200 return pending_database_info_; | 190 return pending_database_info_; |
| 201 } | 191 } |
| 202 | 192 |
| 203 void CannedBrowsingDataDatabaseHelper::StartFetching( | 193 void CannedBrowsingDataDatabaseHelper::StartFetching( |
| 204 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { | 194 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { |
| 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 206 DCHECK(!is_fetching_); | 196 DCHECK(!is_fetching_); |
| 207 DCHECK_EQ(false, callback.is_null()); | 197 DCHECK_EQ(false, callback.is_null()); |
| 208 | 198 |
| 209 is_fetching_ = true; | 199 is_fetching_ = true; |
| 210 completion_callback_ = callback; | 200 completion_callback_ = callback; |
| 211 BrowserThread::PostTask( | |
| 212 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | |
| 213 base::Bind(&CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread, | |
| 214 this)); | |
| 215 } | |
| 216 | 201 |
| 217 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {} | |
| 218 | |
| 219 void CannedBrowsingDataDatabaseHelper::ConvertInfoInWebKitThread() { | |
| 220 base::AutoLock auto_lock(lock_); | |
| 221 database_info_.clear(); | 202 database_info_.clear(); |
| 222 for (std::set<PendingDatabaseInfo>::const_iterator | 203 for (std::set<PendingDatabaseInfo>::const_iterator |
| 223 info = pending_database_info_.begin(); | 204 info = pending_database_info_.begin(); |
| 224 info != pending_database_info_.end(); ++info) { | 205 info != pending_database_info_.end(); ++info) { |
| 225 WebSecurityOrigin web_security_origin = | 206 DatabaseIdentifier identifier = |
| 226 WebSecurityOrigin::createFromString( | 207 DatabaseIdentifier::CreateFromOrigin(info->origin); |
|
michaeln
2013/06/19 23:28:29
this was silly code, there was never really a need
| |
| 227 UTF8ToUTF16(info->origin.spec())); | |
| 228 std::string origin_identifier = | |
| 229 web_security_origin.databaseIdentifier().utf8(); | |
| 230 | 208 |
| 231 database_info_.push_back(DatabaseInfo( | 209 database_info_.push_back(DatabaseInfo( |
| 232 web_security_origin.host().utf8(), | 210 identifier, |
| 233 info->name, | 211 info->name, |
| 234 origin_identifier, | |
| 235 info->description, | 212 info->description, |
| 236 web_security_origin.toString().utf8(), | |
| 237 0, | 213 0, |
| 238 base::Time())); | 214 base::Time())); |
| 239 } | 215 } |
| 240 | 216 |
| 241 BrowserThread::PostTask( | 217 BrowserThread::PostTask( |
|
jamesr
2013/06/19 22:12:48
this still PostTask()s to its own thread just to k
michaeln
2013/06/19 23:28:29
we should keep the behavior async so this mock exh
| |
| 242 BrowserThread::UI, FROM_HERE, | 218 BrowserThread::UI, FROM_HERE, |
| 243 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); | 219 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); |
| 244 } | 220 } |
| 221 | |
| 222 CannedBrowsingDataDatabaseHelper::~CannedBrowsingDataDatabaseHelper() {} | |
| OLD | NEW |