| 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/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #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" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | |
| 19 | 20 |
| 20 using content::BrowserContext; | 21 using content::BrowserContext; |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 using WebKit::WebSecurityOrigin; | 23 using WebKit::WebSecurityOrigin; |
| 23 | 24 |
| 24 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo() | 25 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo() |
| 25 : size(0) { | 26 : size(0) { |
| 26 } | 27 } |
| 27 | 28 |
| 28 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo( | 29 BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 base::Bind(&BrowsingDataDatabaseHelper::DeleteDatabaseOnFileThread, this, | 81 base::Bind(&BrowsingDataDatabaseHelper::DeleteDatabaseOnFileThread, this, |
| 81 origin, name)); | 82 origin, name)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void BrowsingDataDatabaseHelper::FetchDatabaseInfoOnFileThread() { | 85 void BrowsingDataDatabaseHelper::FetchDatabaseInfoOnFileThread() { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 86 std::vector<webkit_database::OriginInfo> origins_info; | 87 std::vector<webkit_database::OriginInfo> origins_info; |
| 87 if (tracker_.get() && tracker_->GetAllOriginsInfo(&origins_info)) { | 88 if (tracker_.get() && tracker_->GetAllOriginsInfo(&origins_info)) { |
| 88 for (std::vector<webkit_database::OriginInfo>::const_iterator ori = | 89 for (std::vector<webkit_database::OriginInfo>::const_iterator ori = |
| 89 origins_info.begin(); ori != origins_info.end(); ++ori) { | 90 origins_info.begin(); ori != origins_info.end(); ++ori) { |
| 90 const std::string origin_identifier(UTF16ToUTF8(ori->GetOrigin())); | 91 const GURL origin(UTF16ToUTF8(ori->GetOrigin())); |
| 91 if (StartsWithASCII(origin_identifier, | 92 if (!BrowsingDataHelper::HasValidScheme(origin)) { |
| 92 std::string(chrome::kExtensionScheme), | 93 // Non-websafe state is not considered browsing data. |
| 93 true)) { | |
| 94 // Extension state is not considered browsing data. | |
| 95 continue; | 94 continue; |
| 96 } | 95 } |
| 97 WebSecurityOrigin web_security_origin = | 96 WebSecurityOrigin web_security_origin = |
| 98 WebSecurityOrigin::createFromDatabaseIdentifier( | 97 WebSecurityOrigin::createFromDatabaseIdentifier( |
| 99 ori->GetOrigin()); | 98 ori->GetOrigin()); |
| 100 std::vector<string16> databases; | 99 std::vector<string16> databases; |
| 101 ori->GetAllDatabaseNames(&databases); | 100 ori->GetAllDatabaseNames(&databases); |
| 102 for (std::vector<string16>::const_iterator db = databases.begin(); | 101 for (std::vector<string16>::const_iterator db = databases.begin(); |
| 103 db != databases.end(); ++db) { | 102 db != databases.end(); ++db) { |
| 104 FilePath file_path = tracker_->GetFullDBFilePath(ori->GetOrigin(), *db); | 103 FilePath file_path = tracker_->GetFullDBFilePath(ori->GetOrigin(), *db); |
| 105 base::PlatformFileInfo file_info; | 104 base::PlatformFileInfo file_info; |
| 106 if (file_util::GetFileInfo(file_path, &file_info)) { | 105 if (file_util::GetFileInfo(file_path, &file_info)) { |
| 107 database_info_.push_back(DatabaseInfo( | 106 database_info_.push_back(DatabaseInfo( |
| 108 web_security_origin.host().utf8(), | 107 web_security_origin.host().utf8(), |
| 109 UTF16ToUTF8(*db), | 108 UTF16ToUTF8(*db), |
| 110 origin_identifier, | 109 UTF16ToUTF8(ori->GetOrigin()), |
| 111 UTF16ToUTF8(ori->GetDatabaseDescription(*db)), | 110 UTF16ToUTF8(ori->GetDatabaseDescription(*db)), |
| 112 web_security_origin.toString().utf8(), | 111 web_security_origin.toString().utf8(), |
| 113 file_info.size, | 112 file_info.size, |
| 114 file_info.last_modified)); | 113 file_info.last_modified)); |
| 115 } | 114 } |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 } | 117 } |
| 119 | 118 |
| 120 BrowserThread::PostTask( | 119 BrowserThread::PostTask( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 clone->pending_database_info_ = pending_database_info_; | 172 clone->pending_database_info_ = pending_database_info_; |
| 174 clone->database_info_ = database_info_; | 173 clone->database_info_ = database_info_; |
| 175 return clone; | 174 return clone; |
| 176 } | 175 } |
| 177 | 176 |
| 178 void CannedBrowsingDataDatabaseHelper::AddDatabase( | 177 void CannedBrowsingDataDatabaseHelper::AddDatabase( |
| 179 const GURL& origin, | 178 const GURL& origin, |
| 180 const std::string& name, | 179 const std::string& name, |
| 181 const std::string& description) { | 180 const std::string& description) { |
| 182 base::AutoLock auto_lock(lock_); | 181 base::AutoLock auto_lock(lock_); |
| 183 pending_database_info_.push_back(PendingDatabaseInfo( | 182 if (BrowsingDataHelper::HasValidScheme(origin)) { |
| 184 origin, name, description)); | 183 pending_database_info_.push_back(PendingDatabaseInfo( |
| 184 origin, name, description)); |
| 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 void CannedBrowsingDataDatabaseHelper::Reset() { | 188 void CannedBrowsingDataDatabaseHelper::Reset() { |
| 188 base::AutoLock auto_lock(lock_); | 189 base::AutoLock auto_lock(lock_); |
| 189 database_info_.clear(); | 190 database_info_.clear(); |
| 190 pending_database_info_.clear(); | 191 pending_database_info_.clear(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 bool CannedBrowsingDataDatabaseHelper::empty() const { | 194 bool CannedBrowsingDataDatabaseHelper::empty() const { |
| 194 base::AutoLock auto_lock(lock_); | 195 base::AutoLock auto_lock(lock_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 web_security_origin.toString().utf8(), | 243 web_security_origin.toString().utf8(), |
| 243 0, | 244 0, |
| 244 base::Time())); | 245 base::Time())); |
| 245 } | 246 } |
| 246 pending_database_info_.clear(); | 247 pending_database_info_.clear(); |
| 247 | 248 |
| 248 BrowserThread::PostTask( | 249 BrowserThread::PostTask( |
| 249 BrowserThread::UI, FROM_HERE, | 250 BrowserThread::UI, FROM_HERE, |
| 250 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); | 251 base::Bind(&CannedBrowsingDataDatabaseHelper::NotifyInUIThread, this)); |
| 251 } | 252 } |
| OLD | NEW |