Chromium Code Reviews| Index: chrome/browser/browsing_data_indexed_db_helper.cc |
| =================================================================== |
| --- chrome/browser/browsing_data_indexed_db_helper.cc (revision 97265) |
| +++ chrome/browser/browsing_data_indexed_db_helper.cc (working copy) |
| @@ -11,14 +11,12 @@ |
| #include "base/string_util.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/profiles/profile.h" |
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| #include "content/browser/browser_thread.h" |
| #include "content/browser/in_process_webkit/webkit_context.h" |
| +#include "webkit/database/database_util.h" |
| #include "webkit/glue/webkit_glue.h" |
| -using WebKit::WebSecurityOrigin; |
| +using webkit_database::DatabaseUtil; |
| namespace { |
| @@ -29,7 +27,7 @@ |
| virtual void StartFetching( |
| Callback1<const std::list<IndexedDBInfo>& >::Type* callback); |
| virtual void CancelNotification(); |
| - virtual void DeleteIndexedDBFile(const FilePath& file_path); |
| + virtual void DeleteIndexedDB(const GURL& origin_url); |
|
michaeln
2011/08/23 20:39:48
Changed this method signature to use origin_url to
|
| private: |
| virtual ~BrowsingDataIndexedDBHelperImpl(); |
| @@ -39,9 +37,9 @@ |
| // Notifies the completion callback in the UI thread. |
| void NotifyInUIThread(); |
| // Delete a single indexed database file in the WEBKIT thread. |
| - void DeleteIndexedDBFileInWebKitThread(const FilePath& file_path); |
| + void DeleteIndexedDBInWebKitThread(const GURL& origin); |
| - Profile* profile_; |
|
michaeln
2011/08/23 20:39:48
Removed the profile ptr since it's not safe to acc
|
| + scoped_refptr<IndexedDBContext> indexed_db_context_; |
| // This only mutates in the WEBKIT thread. |
| std::list<IndexedDBInfo> indexed_db_info_; |
| @@ -60,10 +58,10 @@ |
| BrowsingDataIndexedDBHelperImpl::BrowsingDataIndexedDBHelperImpl( |
| Profile* profile) |
| - : profile_(profile), |
| + : indexed_db_context_(profile->GetWebKitContext()->indexed_db_context()), |
| completion_callback_(NULL), |
| is_fetching_(false) { |
| - DCHECK(profile_); |
| + DCHECK(indexed_db_context_.get()); |
| } |
| BrowsingDataIndexedDBHelperImpl::~BrowsingDataIndexedDBHelperImpl() { |
| @@ -88,49 +86,31 @@ |
| completion_callback_.reset(); |
| } |
| -void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBFile( |
| - const FilePath& file_path) { |
| +void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDB( |
| + const GURL& origin_url) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| BrowserThread::PostTask( |
| BrowserThread::WEBKIT, FROM_HERE, |
| NewRunnableMethod( |
| this, |
| &BrowsingDataIndexedDBHelperImpl:: |
| - DeleteIndexedDBFileInWebKitThread, |
| - file_path)); |
| + DeleteIndexedDBInWebKitThread, |
| + origin_url)); |
| } |
| void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| - file_util::FileEnumerator file_enumerator( |
| - profile_->GetWebKitContext()->data_path().Append( |
| - IndexedDBContext::kIndexedDBDirectory), |
| - false, file_util::FileEnumerator::DIRECTORIES); |
| - for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| - file_path = file_enumerator.Next()) { |
| - if (file_path.Extension() == IndexedDBContext::kIndexedDBExtension) { |
| - WebSecurityOrigin web_security_origin = |
| - WebSecurityOrigin::createFromDatabaseIdentifier( |
|
michaeln
2011/08/23 20:39:48
Got rid of WebKit api usage in this chrome code si
|
| - webkit_glue::FilePathToWebString(file_path.BaseName())); |
| - if (EqualsASCII(web_security_origin.protocol(), |
| - chrome::kExtensionScheme)) { |
| - // Extension state is not considered browsing data. |
| - continue; |
| - } |
| - base::PlatformFileInfo file_info; |
| - bool ret = file_util::GetFileInfo(file_path, &file_info); |
|
michaeln
2011/08/23 20:39:48
The actual file_path is an internal impl detail of
|
| - if (ret) { |
| - indexed_db_info_.push_back(IndexedDBInfo( |
| - web_security_origin.protocol().utf8(), |
| - web_security_origin.host().utf8(), |
| - web_security_origin.port(), |
| - web_security_origin.databaseIdentifier().utf8(), |
| - web_security_origin.toString().utf8(), |
| - file_path, |
| - file_info.size, |
| - file_info.last_modified)); |
| - } |
| - } |
| + std::vector<GURL> origins; |
| + indexed_db_context_->GetAllOrigins(&origins); |
| + for (std::vector<GURL>::const_iterator iter = origins.begin(); |
| + iter != origins.end(); ++iter) { |
| + const GURL& origin_url = *iter; |
| + if (origin_url.SchemeIs(chrome::kExtensionScheme)) |
| + continue; // Extension state is not considered browsing data. |
| + indexed_db_info_.push_back(IndexedDBInfo( |
| + origin_url, |
| + indexed_db_context_->GetOriginDiskUsage(origin_url), |
| + indexed_db_context_->GetOriginLastModified(origin_url))); |
| } |
| BrowserThread::PostTask( |
| @@ -151,29 +131,19 @@ |
| is_fetching_ = false; |
| } |
| -void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBFileInWebKitThread( |
| - const FilePath& file_path) { |
| +void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread( |
| + const GURL& origin_url) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| - // TODO(jochen): implement this once it's possible to delete indexed DBs. |
| + indexed_db_context_->DeleteIndexedDBForOrigin(origin_url); |
|
michaeln
2011/08/23 20:39:48
This is actually what i set out to to, wire the UI
|
| } |
| } // namespace |
| BrowsingDataIndexedDBHelper::IndexedDBInfo::IndexedDBInfo( |
| - const std::string& protocol, |
| - const std::string& host, |
| - unsigned short port, |
| - const std::string& database_identifier, |
| - const std::string& origin, |
| - const FilePath& file_path, |
| + const GURL& origin_url, |
| int64 size, |
| base::Time last_modified) |
| - : protocol(protocol), |
| - host(host), |
| - port(port), |
| - database_identifier(database_identifier), |
| - origin(origin), |
| - file_path(file_path), |
| + : origin_url(origin_url), |
| size(size), |
| last_modified(last_modified) { |
| } |
| @@ -201,18 +171,15 @@ |
| PendingIndexedDBInfo::~PendingIndexedDBInfo() { |
| } |
| -CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper( |
| - Profile* profile) |
| - : profile_(profile), |
| - completion_callback_(NULL), |
| +CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper() |
| + : completion_callback_(NULL), |
| is_fetching_(false) { |
| - DCHECK(profile); |
| } |
| CannedBrowsingDataIndexedDBHelper* CannedBrowsingDataIndexedDBHelper::Clone() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| CannedBrowsingDataIndexedDBHelper* clone = |
| - new CannedBrowsingDataIndexedDBHelper(profile_); |
| + new CannedBrowsingDataIndexedDBHelper(); |
| base::AutoLock auto_lock(lock_); |
| clone->pending_indexed_db_info_ = pending_indexed_db_info_; |
| @@ -256,16 +223,11 @@ |
| for (std::list<PendingIndexedDBInfo>::const_iterator |
| info = pending_indexed_db_info_.begin(); |
| info != pending_indexed_db_info_.end(); ++info) { |
| - WebSecurityOrigin web_security_origin = |
| - WebSecurityOrigin::createFromString( |
| - UTF8ToUTF16(info->origin.spec())); |
| - std::string security_origin(web_security_origin.toString().utf8()); |
| - |
| bool duplicate = false; |
| for (std::list<IndexedDBInfo>::iterator |
| indexed_db = indexed_db_info_.begin(); |
| indexed_db != indexed_db_info_.end(); ++indexed_db) { |
| - if (indexed_db->origin == security_origin) { |
| + if (indexed_db->origin_url == info->origin) { |
| duplicate = true; |
| break; |
| } |
| @@ -274,13 +236,7 @@ |
| continue; |
| indexed_db_info_.push_back(IndexedDBInfo( |
| - web_security_origin.protocol().utf8(), |
| - web_security_origin.host().utf8(), |
| - web_security_origin.port(), |
| - web_security_origin.databaseIdentifier().utf8(), |
| - security_origin, |
| - profile_->GetWebKitContext()->indexed_db_context()-> |
| - GetIndexedDBFilePath(web_security_origin.databaseIdentifier()), |
| + info->origin, |
| 0, |
| base::Time())); |
| } |