Commit 5a30eb49 authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

[IndexedDB] Add switch to close backing stores immediately

R=cmp@chromium.org

Change-Id: I0d2b39043d0d3a2ef7478178bc7106dc00337171
Reviewed-on: https://chromium-review.googlesource.com/1101656
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarChase Phillips <cmp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567502}
parent 5da61dbe
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -179,6 +180,12 @@ void IndexedDBFactoryImpl::ReleaseBackingStore(const Origin& origin, ...@@ -179,6 +180,12 @@ void IndexedDBFactoryImpl::ReleaseBackingStore(const Origin& origin,
return; return;
} }
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
kIDBCloseImmediatelySwitch)) {
MaybeCloseBackingStore(origin);
return;
}
// Start a timer to close the backing store, unless something else opens it // Start a timer to close the backing store, unless something else opens it
// in the mean time. // in the mean time.
DCHECK(!backing_store_map_[origin]->close_timer()->IsRunning()); DCHECK(!backing_store_map_[origin]->close_timer()->IsRunning());
......
...@@ -32,6 +32,8 @@ class IndexedDBContextImpl; ...@@ -32,6 +32,8 @@ class IndexedDBContextImpl;
CONTENT_EXPORT extern const base::Feature kIDBTombstoneStatistics; CONTENT_EXPORT extern const base::Feature kIDBTombstoneStatistics;
CONTENT_EXPORT extern const base::Feature kIDBTombstoneDeletion; CONTENT_EXPORT extern const base::Feature kIDBTombstoneDeletion;
constexpr const char kIDBCloseImmediatelySwitch[] = "idb-close-immediately";
class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory { class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory {
public: public:
// Maximum time interval between runs of the IndexedDBSweeper. Sweeping only // Maximum time interval between runs of the IndexedDBSweeper. Sweeping only
...@@ -141,6 +143,8 @@ class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory { ...@@ -141,6 +143,8 @@ class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory {
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
BackingStoreReleaseDelayedOnClose); BackingStoreReleaseDelayedOnClose);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, BackingStoreRunPreCloseTasks); FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, BackingStoreRunPreCloseTasks);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
BackingStoreCloseImmediatelySwitch);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, BackingStoreNoSweeping); FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, BackingStoreNoSweeping);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen); FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
......
...@@ -324,6 +324,41 @@ TEST_F(IndexedDBFactoryTest, BackingStoreRunPreCloseTasks) { ...@@ -324,6 +324,41 @@ TEST_F(IndexedDBFactoryTest, BackingStoreRunPreCloseTasks) {
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
} }
TEST_F(IndexedDBFactoryTest, BackingStoreCloseImmediatelySwitch) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({kIDBTombstoneStatistics},
{kIDBTombstoneDeletion});
base::CommandLine::ForCurrentProcess()->AppendSwitch(
kIDBCloseImmediatelySwitch);
context()->TaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
[](IndexedDBContextImpl* context) {
base::SimpleTestClock clock;
clock.SetNow(base::Time::Now());
scoped_refptr<MockIDBFactory> factory =
base::MakeRefCounted<MockIDBFactory>(context, &clock);
const Origin origin = Origin::Create(GURL("http://localhost:81"));
scoped_refptr<IndexedDBBackingStore> store =
factory->TestOpenBackingStore(origin, context->data_path());
// Give up the local refptr so that the factory has the only
// outstanding reference.
IndexedDBBackingStore* store_ptr = store.get();
store = nullptr;
EXPECT_FALSE(store_ptr->close_timer()->IsRunning());
factory->TestReleaseBackingStore(store_ptr, false);
EXPECT_FALSE(factory->IsBackingStoreOpen(origin));
},
base::Unretained(context())));
RunAllTasksUntilIdle();
}
TEST_F(IndexedDBFactoryTest, MemoryBackingStoreLifetime) { TEST_F(IndexedDBFactoryTest, MemoryBackingStoreLifetime) {
context()->TaskRunner()->PostTask( context()->TaskRunner()->PostTask(
FROM_HERE, FROM_HERE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment