diff options
20 files changed, 258 insertions, 265 deletions
diff --git a/chrome/browser/browsing_data_indexed_db_helper.cc b/chrome/browser/browsing_data_indexed_db_helper.cc index d597d77..7da39d2 100644 --- a/chrome/browser/browsing_data_indexed_db_helper.cc +++ b/chrome/browser/browsing_data_indexed_db_helper.cc @@ -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 @@ class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { 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); private: virtual ~BrowsingDataIndexedDBHelperImpl(); @@ -38,10 +36,10 @@ class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { void FetchIndexedDBInfoInWebKitThread(); // 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); + // Delete a single indexed database in the WEBKIT thread. + void DeleteIndexedDBInWebKitThread(const GURL& origin); - Profile* profile_; + scoped_refptr<IndexedDBContext> indexed_db_context_; // This only mutates in the WEBKIT thread. std::list<IndexedDBInfo> indexed_db_info_; @@ -60,10 +58,10 @@ class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { 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 @@ void BrowsingDataIndexedDBHelperImpl::CancelNotification() { completion_callback_.reset(); } -void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBFile( - const FilePath& file_path) { +void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDB( + const GURL& origin) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); BrowserThread::PostTask( BrowserThread::WEBKIT, FROM_HERE, NewRunnableMethod( this, &BrowsingDataIndexedDBHelperImpl:: - DeleteIndexedDBFileInWebKitThread, - file_path)); + DeleteIndexedDBInWebKitThread, + origin)); } 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( - 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); - 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 = *iter; + if (origin.SchemeIs(chrome::kExtensionScheme)) + continue; // Extension state is not considered browsing data. + indexed_db_info_.push_back(IndexedDBInfo( + origin, + indexed_db_context_->GetOriginDiskUsage(origin), + indexed_db_context_->GetOriginLastModified(origin))); } BrowserThread::PostTask( @@ -151,29 +131,19 @@ void BrowsingDataIndexedDBHelperImpl::NotifyInUIThread() { is_fetching_ = false; } -void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBFileInWebKitThread( - const FilePath& file_path) { +void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread( + const GURL& origin) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); - // TODO(jochen): implement this once it's possible to delete indexed DBs. + indexed_db_context_->DeleteIndexedDBForOrigin(origin); } } // 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, int64 size, base::Time last_modified) - : protocol(protocol), - host(host), - port(port), - database_identifier(database_identifier), - origin(origin), - file_path(file_path), + : origin(origin), size(size), last_modified(last_modified) { } @@ -201,18 +171,15 @@ CannedBrowsingDataIndexedDBHelper:: 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 @@ void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { 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 == info->origin) { duplicate = true; break; } @@ -274,13 +236,7 @@ void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { 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())); } diff --git a/chrome/browser/browsing_data_indexed_db_helper.h b/chrome/browser/browsing_data_indexed_db_helper.h index 104077d..5c5ad44 100644 --- a/chrome/browser/browsing_data_indexed_db_helper.h +++ b/chrome/browser/browsing_data_indexed_db_helper.h @@ -32,26 +32,16 @@ class BrowsingDataIndexedDBHelper // Contains detailed information about an indexed database. struct 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, int64 size, base::Time last_modified); ~IndexedDBInfo(); bool IsFileSchemeData() { - return protocol == chrome::kFileScheme; + return origin.SchemeIsFile(); } - std::string protocol; - std::string host; - unsigned short port; - std::string database_identifier; - std::string origin; - FilePath file_path; + GURL origin; int64 size; base::Time last_modified; }; @@ -69,8 +59,8 @@ class BrowsingDataIndexedDBHelper // longer exists). // This must be called only in the UI thread. virtual void CancelNotification() = 0; - // Requests a single indexed database file to be deleted in the WEBKIT thread. - virtual void DeleteIndexedDBFile(const FilePath& file_path) = 0; + // Requests a single indexed database to be deleted in the WEBKIT thread. + virtual void DeleteIndexedDB(const GURL& origin) = 0; protected: friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; @@ -83,7 +73,7 @@ class BrowsingDataIndexedDBHelper class CannedBrowsingDataIndexedDBHelper : public BrowsingDataIndexedDBHelper { public: - explicit CannedBrowsingDataIndexedDBHelper(Profile* profile); + CannedBrowsingDataIndexedDBHelper(); // Return a copy of the IndexedDB helper. Only one consumer can use the // StartFetching method at a time, so we need to create a copy of the helper @@ -105,7 +95,7 @@ class CannedBrowsingDataIndexedDBHelper 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) {} private: struct PendingIndexedDBInfo { @@ -124,8 +114,6 @@ class CannedBrowsingDataIndexedDBHelper void NotifyInUIThread(); - Profile* profile_; - // Lock to protect access to pending_indexed_db_info_; mutable base::Lock lock_; diff --git a/chrome/browser/browsing_data_indexed_db_helper_browsertest.cc b/chrome/browser/browsing_data_indexed_db_helper_browsertest.cc index ae76c35..6ddd20c 100644 --- a/chrome/browser/browsing_data_indexed_db_helper_browsertest.cc +++ b/chrome/browser/browsing_data_indexed_db_helper_browsertest.cc @@ -28,13 +28,9 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedAddIndexedDB) { const GURL origin1("http://host1:1/"); const GURL origin2("http://host2:1/"); const string16 description(ASCIIToUTF16("description")); - const FilePath::CharType file1[] = - FILE_PATH_LITERAL("http_host1_1.indexeddb.leveldb"); - const FilePath::CharType file2[] = - FILE_PATH_LITERAL("http_host2_1.indexeddb.leveldb"); scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( - new CannedBrowsingDataIndexedDBHelper(browser()->profile())); + new CannedBrowsingDataIndexedDBHelper()); helper->AddIndexedDB(origin1, description); helper->AddIndexedDB(origin2, description); @@ -48,19 +44,17 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedAddIndexedDB) { ASSERT_EQ(2U, result.size()); std::list<BrowsingDataIndexedDBHelper::IndexedDBInfo>::iterator info = result.begin(); - EXPECT_EQ(FilePath(file1).value(), info->file_path.BaseName().value()); + EXPECT_EQ(origin1, info->origin); info++; - EXPECT_EQ(FilePath(file2).value(), info->file_path.BaseName().value()); + EXPECT_EQ(origin2, info->origin); } IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedUnique) { const GURL origin("http://host1:1/"); const string16 description(ASCIIToUTF16("description")); - const FilePath::CharType file[] = - FILE_PATH_LITERAL("http_host1_1.indexeddb.leveldb"); scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( - new CannedBrowsingDataIndexedDBHelper(browser()->profile())); + new CannedBrowsingDataIndexedDBHelper()); helper->AddIndexedDB(origin, description); helper->AddIndexedDB(origin, description); @@ -72,7 +66,6 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedUnique) { callback.result(); ASSERT_EQ(1U, result.size()); - EXPECT_EQ(FilePath(file).value(), - result.begin()->file_path.BaseName().value()); + EXPECT_EQ(origin, result.begin()->origin); } } // namespace diff --git a/chrome/browser/browsing_data_indexed_db_helper_unittest.cc b/chrome/browser/browsing_data_indexed_db_helper_unittest.cc index 3fa2fcf..a3304e5 100644 --- a/chrome/browser/browsing_data_indexed_db_helper_unittest.cc +++ b/chrome/browser/browsing_data_indexed_db_helper_unittest.cc @@ -7,20 +7,17 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/browsing_data_indexed_db_helper.h" #include "chrome/test/base/testing_browser_process_test.h" -#include "chrome/test/base/testing_profile.h" namespace { typedef TestingBrowserProcessTest CannedBrowsingDataIndexedDBHelperTest; TEST_F(CannedBrowsingDataIndexedDBHelperTest, Empty) { - TestingProfile profile; - const GURL origin("http://host1:1/"); const string16 description(ASCIIToUTF16("description")); scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( - new CannedBrowsingDataIndexedDBHelper(&profile)); + new CannedBrowsingDataIndexedDBHelper()); ASSERT_TRUE(helper->empty()); helper->AddIndexedDB(origin, description); diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc index 8549430..1c89bb6 100644 --- a/chrome/browser/content_settings/tab_specific_content_settings.cc +++ b/chrome/browser/content_settings/tab_specific_content_settings.cc @@ -481,7 +481,7 @@ TabSpecificContentSettings::LocalSharedObjectsContainer:: cookies_(new CannedBrowsingDataCookieHelper(profile)), databases_(new CannedBrowsingDataDatabaseHelper(profile)), file_systems_(new CannedBrowsingDataFileSystemHelper(profile)), - indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(profile)), + indexed_dbs_(new CannedBrowsingDataIndexedDBHelper()), local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)), session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { } diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index b2660ec..f0ed602 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -244,17 +244,15 @@ CookieTreeIndexedDBNode::CookieTreeIndexedDBNode( std::list<BrowsingDataIndexedDBHelper::IndexedDBInfo>::iterator indexed_db_info) : CookieTreeNode(UTF8ToUTF16( - indexed_db_info->origin.empty() ? - indexed_db_info->database_identifier : - indexed_db_info->origin)), + indexed_db_info->origin.spec())), indexed_db_info_(indexed_db_info) { } CookieTreeIndexedDBNode::~CookieTreeIndexedDBNode() {} void CookieTreeIndexedDBNode::DeleteStoredObjects() { - GetModel()->indexed_db_helper_->DeleteIndexedDBFile( - indexed_db_info_->file_path); + GetModel()->indexed_db_helper_->DeleteIndexedDB( + indexed_db_info_->origin); GetModel()->indexed_db_info_list_.erase(indexed_db_info_); } @@ -981,7 +979,7 @@ void CookiesTreeModel::PopulateIndexedDBInfoWithFilter( indexed_db_info_list_.begin(); indexed_db_info != indexed_db_info_list_.end(); ++indexed_db_info) { - GURL origin(indexed_db_info->origin); + const GURL& origin = indexed_db_info->origin; if (!filter.size() || (CookieTreeOriginNode::TitleForUrl(origin).find(filter) != diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc index 787c125..2ff88ca 100644 --- a/chrome/browser/cookies_tree_model_unittest.cc +++ b/chrome/browser/cookies_tree_model_unittest.cc @@ -52,7 +52,7 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest { mock_browsing_data_appcache_helper_ = new MockBrowsingDataAppCacheHelper(profile_.get()); mock_browsing_data_indexed_db_helper_ = - new MockBrowsingDataIndexedDBHelper(profile_.get()); + new MockBrowsingDataIndexedDBHelper(); mock_browsing_data_file_system_helper_ = new MockBrowsingDataFileSystemHelper(profile_.get()); mock_browsing_data_quota_helper_ = @@ -159,7 +159,8 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest { return node->GetDetailedInfo().appcache_info->manifest_url.spec() + ","; case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: - return node->GetDetailedInfo().indexed_db_info->origin + ","; + return node->GetDetailedInfo().indexed_db_info->origin.spec() + + ","; case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: return node->GetDetailedInfo().file_system_info->origin.spec() + ","; diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 129dfcd..bd19cd6 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -2757,14 +2757,13 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) { EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); EXPECT_TRUE(file_util::PathExists(lso_path)); - // Create indexed db. Again, it is enough to only simulate this by creating - // the file on the disk. + // Create indexed db. Similarly, it is enough to only simulate this by + // creating the directory on the disk. IndexedDBContext* idb_context = profile_->GetWebKitContext()->indexed_db_context(); FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); - EXPECT_TRUE(file_util::CreateDirectory(idb_path.DirName())); - EXPECT_EQ(0, file_util::WriteFile(idb_path, NULL, 0)); - EXPECT_TRUE(file_util::PathExists(idb_path)); + EXPECT_TRUE(file_util::CreateDirectory(idb_path)); + EXPECT_TRUE(file_util::DirectoryExists(idb_path)); // Uninstall the extension. service_->UninstallExtension(good_crx, false, NULL); @@ -2787,7 +2786,7 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) { EXPECT_FALSE(file_util::PathExists(lso_path)); // Check if the indexed db has disappeared too. - EXPECT_FALSE(file_util::PathExists(idb_path)); + EXPECT_FALSE(file_util::DirectoryExists(idb_path)); } // Tests loading single extensions (like --load-extension) diff --git a/chrome/browser/mock_browsing_data_indexed_db_helper.cc b/chrome/browser/mock_browsing_data_indexed_db_helper.cc index 9530c8f..5f17818 100644 --- a/chrome/browser/mock_browsing_data_indexed_db_helper.cc +++ b/chrome/browser/mock_browsing_data_indexed_db_helper.cc @@ -7,9 +7,7 @@ #include "base/callback.h" #include "base/logging.h" -MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper( - Profile* profile) - : profile_(profile) { +MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper() { } MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { @@ -24,24 +22,23 @@ void MockBrowsingDataIndexedDBHelper::CancelNotification() { callback_.reset(NULL); } -void MockBrowsingDataIndexedDBHelper::DeleteIndexedDBFile( - const FilePath& file_path) { - CHECK(files_.find(file_path.value()) != files_.end()); - last_deleted_file_ = file_path; - files_[file_path.value()] = false; +void MockBrowsingDataIndexedDBHelper::DeleteIndexedDB( + const GURL& origin) { + CHECK(origins_.find(origin) != origins_.end()); + origins_[origin] = false; } void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { + const GURL kOrigin1("http://idbhost1:1/"); + const GURL kOrigin2("http://idbhost2:2/"); response_.push_back( BrowsingDataIndexedDBHelper::IndexedDBInfo( - "http", "idbhost1", 1, "idb1", "http://idbhost1:1/", - FilePath(FILE_PATH_LITERAL("file1")), 1, base::Time())); - files_[FILE_PATH_LITERAL("file1")] = true; + kOrigin1, 1, base::Time())); + origins_[kOrigin1] = true; response_.push_back( BrowsingDataIndexedDBHelper::IndexedDBInfo( - "http", "idbhost2", 2, "idb2", "http://idbhost2:2/", - FilePath(FILE_PATH_LITERAL("file2")), 2, base::Time())); - files_[FILE_PATH_LITERAL("file2")] = true; + kOrigin2, 2, base::Time())); + origins_[kOrigin2] = true; } void MockBrowsingDataIndexedDBHelper::Notify() { @@ -50,14 +47,14 @@ void MockBrowsingDataIndexedDBHelper::Notify() { } void MockBrowsingDataIndexedDBHelper::Reset() { - for (std::map<const FilePath::StringType, bool>::iterator i = files_.begin(); - i != files_.end(); ++i) + for (std::map<GURL, bool>::iterator i = origins_.begin(); + i != origins_.end(); ++i) i->second = true; } bool MockBrowsingDataIndexedDBHelper::AllDeleted() { - for (std::map<const FilePath::StringType, bool>::const_iterator i = - files_.begin(); i != files_.end(); ++i) + for (std::map<GURL, bool>::const_iterator i = origins_.begin(); + i != origins_.end(); ++i) if (i->second) return false; return true; diff --git a/chrome/browser/mock_browsing_data_indexed_db_helper.h b/chrome/browser/mock_browsing_data_indexed_db_helper.h index ff38d79..f047ed4 100644 --- a/chrome/browser/mock_browsing_data_indexed_db_helper.h +++ b/chrome/browser/mock_browsing_data_indexed_db_helper.h @@ -19,7 +19,7 @@ class MockBrowsingDataIndexedDBHelper : public BrowsingDataIndexedDBHelper { public: - explicit MockBrowsingDataIndexedDBHelper(Profile* profile); + MockBrowsingDataIndexedDBHelper(); // Adds some IndexedDBInfo samples. void AddIndexedDBSamples(); @@ -38,20 +38,13 @@ class MockBrowsingDataIndexedDBHelper virtual void StartFetching( Callback1<const std::list<IndexedDBInfo>& >::Type* callback); virtual void CancelNotification(); - virtual void DeleteIndexedDBFile(const FilePath& file_path); - - FilePath last_deleted_file_; + virtual void DeleteIndexedDB(const GURL& origin); private: virtual ~MockBrowsingDataIndexedDBHelper(); - Profile* profile_; - - scoped_ptr<Callback1<const std::list<IndexedDBInfo>& >::Type > - callback_; - - std::map<const FilePath::StringType, bool> files_; - + scoped_ptr<Callback1<const std::list<IndexedDBInfo>& >::Type > callback_; + std::map<GURL, bool> origins_; std::list<IndexedDBInfo> response_; }; diff --git a/chrome/browser/ui/cocoa/content_settings/cookie_details.mm b/chrome/browser/ui/cocoa/content_settings/cookie_details.mm index 8b9bd8e..e7fc214 100644 --- a/chrome/browser/ui/cocoa/content_settings/cookie_details.mm +++ b/chrome/browser/ui/cocoa/content_settings/cookie_details.mm @@ -243,7 +243,8 @@ if ((self = [super init])) { type_ = kCocoaCookieDetailsTypeTreeIndexedDB; canEditExpiration_ = NO; - domain_.reset([base::SysUTF8ToNSString(indexedDBInfo->origin) retain]); + domain_.reset([base::SysUTF8ToNSString( + indexedDBInfo->origin.spec()) retain]); fileSize_.reset([base::SysUTF16ToNSString( ui::FormatBytes(indexedDBInfo->size)) retain]); lastModified_.reset([base::SysUTF16ToNSString( diff --git a/chrome/browser/ui/cocoa/content_settings/cookie_details_unittest.mm b/chrome/browser/ui/cocoa/content_settings/cookie_details_unittest.mm index 7a82635..bffdee8 100644 --- a/chrome/browser/ui/cocoa/content_settings/cookie_details_unittest.mm +++ b/chrome/browser/ui/cocoa/content_settings/cookie_details_unittest.mm @@ -140,27 +140,17 @@ TEST_F(CookiesDetailsTest, CreateForTreeAppCache) { TEST_F(CookiesDetailsTest, CreateForTreeIndexedDB) { scoped_nsobject<CocoaCookieDetails> details; - std::string protocol("http"); - std::string host("moose.org"); - unsigned short port = 80; - std::string database_identifier("id"); - std::string origin("moose.org"); - FilePath file_path(FILE_PATH_LITERAL("/")); + GURL origin("http://moose.org/"); int64 size = 1234; base::Time last_modified = base::Time::Now(); - BrowsingDataIndexedDBHelper::IndexedDBInfo info(protocol, - host, - port, - database_identifier, - origin, - file_path, + BrowsingDataIndexedDBHelper::IndexedDBInfo info(origin, size, last_modified); details.reset([[CocoaCookieDetails alloc] initWithIndexedDBInfo:&info]); EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeIndexedDB); - EXPECT_NSEQ(@"moose.org", [details.get() domain]); + EXPECT_NSEQ(@"http://moose.org/", [details.get() domain]); EXPECT_NSEQ(@"1,234 B", [details.get() fileSize]); EXPECT_NSNE(@"", [details.get() lastModified]); diff --git a/chrome/browser/ui/gtk/gtk_chrome_cookie_view.cc b/chrome/browser/ui/gtk/gtk_chrome_cookie_view.cc index e1844ba..c44ab46 100644 --- a/chrome/browser/ui/gtk/gtk_chrome_cookie_view.cc +++ b/chrome/browser/ui/gtk/gtk_chrome_cookie_view.cc @@ -592,7 +592,7 @@ void gtk_chrome_cookie_view_display_indexed_db( UpdateVisibleDetailedInfo(self, self->indexed_db_details_table_); gtk_entry_set_text(GTK_ENTRY(self->indexed_db_origin_entry_), - indexed_db_info.origin.c_str()); + indexed_db_info.origin.spec().c_str()); gtk_entry_set_text(GTK_ENTRY(self->indexed_db_size_entry_), UTF16ToUTF8(ui::FormatBytes( indexed_db_info.size)).c_str()); diff --git a/chrome/browser/ui/views/indexed_db_info_view.cc b/chrome/browser/ui/views/indexed_db_info_view.cc index d033dca..a617c63 100644 --- a/chrome/browser/ui/views/indexed_db_info_view.cc +++ b/chrome/browser/ui/views/indexed_db_info_view.cc @@ -34,7 +34,7 @@ IndexedDBInfoView::~IndexedDBInfoView() { void IndexedDBInfoView::SetIndexedDBInfo( const BrowsingDataIndexedDBHelper::IndexedDBInfo& indexed_db_info) { - origin_value_field_->SetText(UTF8ToWide(indexed_db_info.origin)); + origin_value_field_->SetText(UTF8ToWide(indexed_db_info.origin.spec())); size_value_field_->SetText(ui::FormatBytes(indexed_db_info.size)); last_modified_value_field_->SetText( base::TimeFormatFriendlyDateAndTime(indexed_db_info.last_modified)); diff --git a/chrome/browser/ui/webui/cookies_tree_model_util.cc b/chrome/browser/ui/webui/cookies_tree_model_util.cc index 05dc69c..599e995 100644 --- a/chrome/browser/ui/webui/cookies_tree_model_util.cc +++ b/chrome/browser/ui/webui/cookies_tree_model_util.cc @@ -168,7 +168,7 @@ bool GetCookieTreeNodeDictionary(const CookieTreeNode& node, const BrowsingDataIndexedDBHelper::IndexedDBInfo& indexed_db_info = *node.GetDetailedInfo().indexed_db_info; - dict->SetString(kKeyOrigin, indexed_db_info.origin); + dict->SetString(kKeyOrigin, indexed_db_info.origin.spec()); dict->SetString(kKeySize, ui::FormatBytes(indexed_db_info.size)); dict->SetString(kKeyModified, UTF16ToUTF8( base::TimeFormatFriendlyDateAndTime(indexed_db_info.last_modified))); diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc index 7ccc8d8..ee5386c 100644 --- a/content/browser/in_process_webkit/indexed_db_browsertest.cc +++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc @@ -17,9 +17,12 @@ #include "content/browser/in_process_webkit/webkit_context.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/common/content_switches.h" +#include "webkit/database/database_util.h" #include "webkit/quota/quota_manager.h" +#include "webkit/quota/special_storage_policy.h" using quota::QuotaManager; +using webkit_database::DatabaseUtil; // This browser test is aimed towards exercising the IndexedDB bindings and // the actual implementation that lives in the browser side (in_process_webkit). @@ -124,41 +127,48 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug84933Test) { // In proc browser test is needed here because ClearLocalState indirectly calls // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) { - // Create test files. ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); - FilePath indexeddb_dir = temp_dir.path().Append( - IndexedDBContext::kIndexedDBDirectory); - ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); - FilePath::StringType file_name_1(FILE_PATH_LITERAL("http_foo_0")); - file_name_1.append(IndexedDBContext::kIndexedDBExtension); - FilePath::StringType file_name_2(FILE_PATH_LITERAL("chrome-extension_foo_0")); - file_name_2.append(IndexedDBContext::kIndexedDBExtension); - FilePath temp_file_path_1 = indexeddb_dir.Append(file_name_1); - FilePath temp_file_path_2 = indexeddb_dir.Append(file_name_2); - - ASSERT_EQ(1, file_util::WriteFile(temp_file_path_1, ".", 1)); - ASSERT_EQ(1, file_util::WriteFile(temp_file_path_2, "o", 1)); + FilePath protected_path; + FilePath unprotected_path; // Create the scope which will ensure we run the destructor of the webkit // context which should trigger the clean up. { TestingProfile profile; + + // Test our assumptions about what is protected and what is not. + const GURL kProtectedOrigin("chrome-extension://foo/"); + const GURL kUnprotectedOrigin("http://foo/"); + quota::SpecialStoragePolicy* policy = profile.GetSpecialStoragePolicy(); + ASSERT_TRUE(policy->IsStorageProtected(kProtectedOrigin)); + ASSERT_FALSE(policy->IsStorageProtected(kUnprotectedOrigin)); + + // Create some indexedDB paths. + // With the levelDB backend, these are directories. WebKitContext *webkit_context = profile.GetWebKitContext(); - webkit_context->indexed_db_context()->set_data_path(indexeddb_dir); + IndexedDBContext* idb_context = webkit_context->indexed_db_context(); + idb_context->set_data_path(temp_dir.path()); + protected_path = idb_context->GetIndexedDBFilePath( + DatabaseUtil::GetOriginIdentifier(kProtectedOrigin)); + unprotected_path = idb_context->GetIndexedDBFilePath( + DatabaseUtil::GetOriginIdentifier(kUnprotectedOrigin)); + ASSERT_TRUE(file_util::CreateDirectory(protected_path)); + ASSERT_TRUE(file_util::CreateDirectory(unprotected_path)); + + // Setup to clear all unprotected origins on exit. webkit_context->set_clear_local_state_on_exit(true); } + // Make sure we wait until the destructor has run. scoped_refptr<base::ThreadTestHelper> helper( new base::ThreadTestHelper( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT))); ASSERT_TRUE(helper->Run()); - // Because we specified https for scheme to be skipped the second file - // should survive and the first go into vanity. - ASSERT_FALSE(file_util::PathExists(temp_file_path_1)); - ASSERT_TRUE(file_util::PathExists(temp_file_path_2)); + ASSERT_TRUE(file_util::DirectoryExists(protected_path)); + ASSERT_FALSE(file_util::DirectoryExists(unprotected_path)); } class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest { diff --git a/content/browser/in_process_webkit/indexed_db_context.cc b/content/browser/in_process_webkit/indexed_db_context.cc index 0c9c8ff..3249ba8 100644 --- a/content/browser/in_process_webkit/indexed_db_context.cc +++ b/content/browser/in_process_webkit/indexed_db_context.cc @@ -15,7 +15,6 @@ #include "content/browser/in_process_webkit/indexed_db_quota_client.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/common/content_switches.h" -#include "googleurl/src/gurl.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" @@ -33,23 +32,42 @@ using WebKit::WebSecurityOrigin; namespace { -void ClearLocalState( +void GetAllOriginsAndPaths( const FilePath& indexeddb_path, - scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { - file_util::FileEnumerator file_enumerator( - indexeddb_path, false, file_util::FileEnumerator::FILES); - // TODO(pastarmovj): We might need to consider exchanging this loop for - // something more efficient in the future. + std::vector<GURL>* origins, + std::vector<FilePath>* file_paths) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); + if (indexeddb_path.empty()) + return; + file_util::FileEnumerator file_enumerator(indexeddb_path, + 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) - continue; - WebSecurityOrigin origin = - WebSecurityOrigin::createFromDatabaseIdentifier( - webkit_glue::FilePathToWebString(file_path.BaseName())); - if (special_storage_policy->IsStorageProtected(GURL(origin.toString()))) + if (file_path.Extension() == IndexedDBContext::kIndexedDBExtension) { + WebKit::WebString origin_id_webstring = + webkit_glue::FilePathToWebString(file_path.BaseName()); + origins->push_back( + DatabaseUtil::GetOriginFromIdentifier(origin_id_webstring)); + if (file_paths) + file_paths->push_back(file_path); + } + } +} + +void ClearLocalState( + const FilePath& indexeddb_path, + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); + std::vector<GURL> origins; + std::vector<FilePath> file_paths; + GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); + DCHECK_EQ(origins.size(), file_paths.size()); + std::vector<FilePath>::const_iterator file_path_iter = file_paths.begin(); + for (std::vector<GURL>::const_iterator iter = origins.begin(); + iter != origins.end(); ++iter, ++file_path_iter) { + if (special_storage_policy->IsStorageProtected(*iter)) continue; - file_util::Delete(file_path, false); + file_util::Delete(*file_path_iter, true); } } @@ -104,7 +122,8 @@ IndexedDBContext::IndexedDBContext( : clear_local_state_on_exit_(false), special_storage_policy_(special_storage_policy), quota_manager_proxy_(quota_manager_proxy) { - data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory); + if (!webkit_context->is_incognito()) + data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory); if (quota_manager_proxy && !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { quota_manager_proxy->RegisterClient( @@ -117,7 +136,7 @@ IndexedDBContext::~IndexedDBContext() { if (factory) BrowserThread::DeleteSoon(BrowserThread::WEBKIT, FROM_HERE, factory); - if (clear_local_state_on_exit_) { + if (clear_local_state_on_exit_ && !data_path_.empty()) { // No WEBKIT thread here means we are running in a unit test where no clean // up is needed. BrowserThread::PostTask(BrowserThread::WEBKIT, FROM_HERE, @@ -127,32 +146,33 @@ IndexedDBContext::~IndexedDBContext() { } WebIDBFactory* IndexedDBContext::GetIDBFactory() { - if (!idb_factory_.get()) + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); + if (!idb_factory_.get()) { + // Prime our cache of origins with existing databases so we can + // detect when dbs are newly created. + GetOriginSet(); idb_factory_.reset(WebIDBFactory::create()); - DCHECK(idb_factory_.get()); + } return idb_factory_.get(); } -FilePath IndexedDBContext::GetIndexedDBFilePath( - const string16& origin_id) const { - FilePath::StringType id = - webkit_glue::WebStringToFilePathString(origin_id).append( - FILE_PATH_LITERAL(".indexeddb")); - return data_path_.Append(id.append(kIndexedDBExtension)); -} - -// Note: This is not called in response to a UI action in Content Settings. Only -// extension data deleter and quota manager currently call this. void IndexedDBContext::DeleteIndexedDBForOrigin(const GURL& origin_url) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); - string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); - FilePath idb_directory = GetIndexedDBFilePath(origin_id); - if (idb_directory.BaseName().value().substr(0, strlen("chrome-extension")) == - FILE_PATH_LITERAL("chrome-extension") || - connection_count_.find(origin_url) == connection_count_.end()) { + if (data_path_.empty() || !IsInOriginSet(origin_url)) + return; + // TODO(michaeln): When asked to delete an origin with open connections, + // forcibly close those connections then delete. + if (connection_count_.find(origin_url) == connection_count_.end()) { + string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); + FilePath idb_directory = GetIndexedDBFilePath(origin_id); EnsureDiskUsageCacheInitialized(origin_url); - file_util::Delete(idb_directory, true /*recursive*/); + bool deleted = file_util::Delete(idb_directory, true /*recursive*/); QueryDiskAndUpdateQuotaUsage(origin_url); + if (deleted) { + RemoveFromOriginSet(origin_url); + origin_size_map_.erase(origin_url); + space_available_map_.erase(origin_url); + } } } @@ -161,25 +181,31 @@ bool IndexedDBContext::IsUnlimitedStorageGranted( return special_storage_policy_->IsStorageUnlimited(origin); } -// TODO(dgrogan): Merge this code with the similar loop in -// BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread. -void IndexedDBContext::GetAllOriginIdentifiers( - std::vector<string16>* origin_ids) { +void IndexedDBContext::GetAllOrigins(std::vector<GURL>* origins) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); - file_util::FileEnumerator file_enumerator(data_path_, - 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) { - WebKit::WebString origin_id_webstring = - webkit_glue::FilePathToWebString(file_path.BaseName()); - origin_ids->push_back(origin_id_webstring); - } + std::set<GURL>* origins_set = GetOriginSet(); + for (std::set<GURL>::const_iterator iter = origins_set->begin(); + iter != origins_set->end(); ++iter) { + origins->push_back(*iter); } } int64 IndexedDBContext::GetOriginDiskUsage(const GURL& origin_url) { - return ResetDiskUsageCache(origin_url); + if (data_path_.empty() || !IsInOriginSet(origin_url)) + return 0; + EnsureDiskUsageCacheInitialized(origin_url); + return origin_size_map_[origin_url]; +} + +base::Time IndexedDBContext::GetOriginLastModified(const GURL& origin_url) { + if (data_path_.empty() || !IsInOriginSet(origin_url)) + return base::Time(); + string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); + FilePath idb_directory = GetIndexedDBFilePath(origin_id); + base::PlatformFileInfo file_info; + if (!file_util::GetFileInfo(idb_directory, &file_info)) + return base::Time(); + return file_info.last_modified; } void IndexedDBContext::ConnectionOpened(const GURL& origin_url) { @@ -189,8 +215,13 @@ void IndexedDBContext::ConnectionOpened(const GURL& origin_url) { quota::kStorageTypeTemporary); } connection_count_[origin_url]++; + if (AddToOriginSet(origin_url)) { + // A newly created db, notify the quota system. + QueryDiskAndUpdateQuotaUsage(origin_url); + } else { + EnsureDiskUsageCacheInitialized(origin_url); + } QueryAvailableQuota(origin_url); - EnsureDiskUsageCacheInitialized(origin_url); } void IndexedDBContext::ConnectionClosed(const GURL& origin_url) { @@ -213,6 +244,15 @@ void IndexedDBContext::TransactionComplete(const GURL& origin_url) { QueryAvailableQuota(origin_url); } +FilePath IndexedDBContext::GetIndexedDBFilePath( + const string16& origin_id) const { + DCHECK(!data_path_.empty()); + FilePath::StringType id = + webkit_glue::WebStringToFilePathString(origin_id).append( + FILE_PATH_LITERAL(".indexeddb")); + return data_path_.Append(id.append(kIndexedDBExtension)); +} + bool IndexedDBContext::WouldBeOverQuota(const GURL& origin_url, int64 additional_bytes) { if (space_available_map_.find(origin_url) == space_available_map_.end()) { @@ -233,6 +273,8 @@ quota::QuotaManagerProxy* IndexedDBContext::quota_manager_proxy() { } int64 IndexedDBContext::ReadUsageFromDisk(const GURL& origin_url) const { + if (data_path_.empty()) + return 0; string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); FilePath file_path = GetIndexedDBFilePath(origin_id); return file_util::ComputeDirectorySize(file_path); @@ -240,7 +282,7 @@ int64 IndexedDBContext::ReadUsageFromDisk(const GURL& origin_url) const { void IndexedDBContext::EnsureDiskUsageCacheInitialized(const GURL& origin_url) { if (origin_size_map_.find(origin_url) == origin_size_map_.end()) - ResetDiskUsageCache(origin_url); + origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); } void IndexedDBContext::QueryDiskAndUpdateQuotaUsage(const GURL& origin_url) { @@ -285,7 +327,21 @@ void IndexedDBContext::QueryAvailableQuota(const GURL& origin_url) { callback); } -int64 IndexedDBContext::ResetDiskUsageCache(const GURL& origin_url) { - origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); - return origin_size_map_[origin_url]; +std::set<GURL>* IndexedDBContext::GetOriginSet() { + if (!origin_set_.get()) { + origin_set_.reset(new std::set<GURL>); + std::vector<GURL> origins; + GetAllOriginsAndPaths(data_path_, &origins, NULL); + for (std::vector<GURL>::const_iterator iter = origins.begin(); + iter != origins.end(); ++iter) { + origin_set_->insert(*iter); + } + } + return origin_set_.get(); +} + +void IndexedDBContext::ResetCaches() { + origin_set_.reset(); + origin_size_map_.clear(); + space_available_map_.clear(); } diff --git a/content/browser/in_process_webkit/indexed_db_context.h b/content/browser/in_process_webkit/indexed_db_context.h index 5ce0a6a..dd8ad0f 100644 --- a/content/browser/in_process_webkit/indexed_db_context.h +++ b/content/browser/in_process_webkit/indexed_db_context.h @@ -7,12 +7,16 @@ #pragma once #include <map> +#include <set> +#include <vector> #include "base/basictypes.h" #include "base/file_path.h" +#include "base/gtest_prod_util.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/browser/browser_thread.h" +#include "googleurl/src/gurl.h" class GURL; class FilePath; @@ -48,9 +52,6 @@ class IndexedDBContext : public base::RefCountedThreadSafe<IndexedDBContext> { // The indexed db file extension. static const FilePath::CharType kIndexedDBExtension[]; - // Get the file name of the indexed db file for the given origin. - FilePath GetIndexedDBFilePath(const string16& origin_id) const; - void set_clear_local_state_on_exit(bool clear_local_state) { clear_local_state_on_exit_ = clear_local_state; } @@ -59,11 +60,12 @@ class IndexedDBContext : public base::RefCountedThreadSafe<IndexedDBContext> { void DeleteIndexedDBForOrigin(const GURL& origin_url); // Does a particular origin get unlimited storage? - bool IsUnlimitedStorageGranted(const GURL& origin) const; + bool IsUnlimitedStorageGranted(const GURL& origin_url) const; // Methods used in response to QuotaManager requests. - void GetAllOriginIdentifiers(std::vector<string16>* origin_ids); + void GetAllOrigins(std::vector<GURL>* origins); int64 GetOriginDiskUsage(const GURL& origin_url); + base::Time GetOriginLastModified(const GURL& origin_url); // Methods called by IndexedDBDispatcherHost for quota support. void ConnectionOpened(const GURL& origin_url); @@ -80,28 +82,41 @@ class IndexedDBContext : public base::RefCountedThreadSafe<IndexedDBContext> { #endif private: + FRIEND_TEST(ExtensionServiceTest, ClearExtensionData); + FRIEND_TEST(IndexedDBBrowserTest, ClearLocalState); + friend class IndexedDBQuotaClientTest; + typedef std::map<GURL, int64> OriginToSizeMap; class IndexedDBGetUsageAndQuotaCallback; + FilePath GetIndexedDBFilePath(const string16& origin_id) const; int64 ReadUsageFromDisk(const GURL& origin_url) const; void EnsureDiskUsageCacheInitialized(const GURL& origin_url); void QueryDiskAndUpdateQuotaUsage(const GURL& origin_url); void GotUpdatedQuota(const GURL& origin_url, int64 usage, int64 quota); void QueryAvailableQuota(const GURL& origin_url); - int64 ResetDiskUsageCache(const GURL& origin_url); - scoped_ptr<WebKit::WebIDBFactory> idb_factory_; + std::set<GURL>* GetOriginSet(); + bool AddToOriginSet(const GURL& origin_url) { + return GetOriginSet()->insert(origin_url).second; + } + void RemoveFromOriginSet(const GURL& origin_url) { + GetOriginSet()->erase(origin_url); + } + bool IsInOriginSet(const GURL& origin_url) { + std::set<GURL>* set = GetOriginSet(); + return set->find(origin_url) != set->end(); + } - // Path where the indexed db data is stored - FilePath data_path_; + // Only for testing. + void ResetCaches(); - // True if the destructor should delete its files. + scoped_ptr<WebKit::WebIDBFactory> idb_factory_; + FilePath data_path_; bool clear_local_state_on_exit_; - scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; - scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; - + scoped_ptr<std::set<GURL> > origin_set_; OriginToSizeMap origin_size_map_; OriginToSizeMap space_available_map_; std::map<GURL, unsigned int> connection_count_; diff --git a/content/browser/in_process_webkit/indexed_db_quota_client.cc b/content/browser/in_process_webkit/indexed_db_quota_client.cc index 606188b..618f147 100644 --- a/content/browser/in_process_webkit/indexed_db_quota_client.cc +++ b/content/browser/in_process_webkit/indexed_db_quota_client.cc @@ -88,14 +88,12 @@ class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { virtual bool ShouldAddOrigin(const GURL& origin) = 0; virtual void RunOnTargetThread() OVERRIDE { - std::vector<string16> origin_identifiers; - indexed_db_context_->GetAllOriginIdentifiers(&origin_identifiers); - for (std::vector<string16>::const_iterator iter = - origin_identifiers.begin(); - iter != origin_identifiers.end(); ++iter) { - GURL origin = DatabaseUtil::GetOriginFromIdentifier(*iter); - if (ShouldAddOrigin(origin)) - origins_.insert(origin); + std::vector<GURL> origins; + indexed_db_context_->GetAllOrigins(&origins); + for (std::vector<GURL>::const_iterator iter = origins.begin(); + iter != origins.end(); ++iter) { + if (ShouldAddOrigin(*iter)) + origins_.insert(*iter); } } diff --git a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc index a4cc8f6..19a544c 100644 --- a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc +++ b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc @@ -122,6 +122,7 @@ class IndexedDBQuotaClientTest : public TestingBrowserProcessTest { } file_path_origin = file_path_origin.Append(FILE_PATH_LITERAL("fake_file")); SetFileSizeTo(file_path_origin, size); + idb_context()->ResetCaches(); } private: |