summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcmumford <cmumford@chromium.org>2015-05-10 09:44:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-10 16:45:27 +0000
commita1f8d834ce9fc89e5e409e08bb00173c37854329 (patch)
treeae54fc3b6dbc2a36c10cb1c755e858a4a7d10ac0
parentf2d15970289120d1b629168d9c46245a1438f10f (diff)
downloadchromium_src-a1f8d834ce9fc89e5e409e08bb00173c37854329.zip
chromium_src-a1f8d834ce9fc89e5e409e08bb00173c37854329.tar.gz
chromium_src-a1f8d834ce9fc89e5e409e08bb00173c37854329.tar.bz2
localStorage: Aggressively flush to disk for Android WebView.
Android WebView does not save data during shutdown like Chrome does. Adding an --enable-aggressive-domstorage-flushing flag to return the DOM Storage implementation to the prior implementation which had a 1 sec. timer to flush the commit queue. BUG=479767 Review URL: https://codereview.chromium.org/1129233003 Cr-Commit-Position: refs/heads/master@{#329070}
-rw-r--r--android_webview/lib/main/aw_main_delegate.cc5
-rw-r--r--content/browser/browser_main_loop.cc8
-rw-r--r--content/browser/dom_storage/dom_storage_area.cc9
-rw-r--r--content/browser/dom_storage/dom_storage_area.h8
-rw-r--r--content/public/common/content_switches.cc4
-rw-r--r--content/public/common/content_switches.h1
6 files changed, 35 insertions, 0 deletions
diff --git a/android_webview/lib/main/aw_main_delegate.cc b/android_webview/lib/main/aw_main_delegate.cc
index d9cbab8..defb379 100644
--- a/android_webview/lib/main/aw_main_delegate.cc
+++ b/android_webview/lib/main/aw_main_delegate.cc
@@ -90,6 +90,11 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
// WebView does not yet support screen orientation locking.
cl->AppendSwitch(switches::kDisableScreenOrientationLock);
+ // WebView does not (yet) save Chromium data during shutdown, so add setting
+ // for Chrome to aggressively persist DOM Storage to minimize data loss.
+ // http://crbug.com/479767
+ cl->AppendSwitch(switches::kEnableAggressiveDOMStorageFlushing);
+
// This is needed to be able to mmap the V8 snapshot and ICU data file
// directly from the WebView .apk.
// This needs to be here so that it gets to run before the code in
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index a76e226..a7178db 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -26,6 +26,7 @@
#include "base/trace_event/trace_event.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/device_sensors/device_inertial_sensor_service.h"
+#include "content/browser/dom_storage/dom_storage_area.h"
#include "content/browser/download/save_file_manager.h"
#include "content/browser/gamepad/gamepad_service.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
@@ -613,6 +614,13 @@ void BrowserMainLoop::MainMessageLoopStart() {
base::MessageLoop::current()->AddTaskObserver(memory_observer_.get());
}
+ if (parsed_command_line_.HasSwitch(
+ switches::kEnableAggressiveDOMStorageFlushing)) {
+ TRACE_EVENT0("startup",
+ "BrowserMainLoop::Subsystem:EnableAggressiveCommitDelay");
+ DOMStorageArea::EnableAggressiveCommitDelay();
+ }
+
base::trace_event::MemoryDumpManager::GetInstance()->Initialize();
// Enable the dump providers.
diff --git a/content/browser/dom_storage/dom_storage_area.cc b/content/browser/dom_storage/dom_storage_area.cc
index 56a1fd0..67c7b98 100644
--- a/content/browser/dom_storage/dom_storage_area.cc
+++ b/content/browser/dom_storage/dom_storage_area.cc
@@ -42,6 +42,8 @@ const int kMaxCommitsPerHour = 6;
} // namespace
+bool DOMStorageArea::s_aggressive_flushing_enabled_ = false;
+
DOMStorageArea::RateLimiter::RateLimiter(size_t desired_rate,
base::TimeDelta time_quantum)
: rate_(desired_rate), samples_(0), time_quantum_(time_quantum) {
@@ -90,6 +92,10 @@ GURL DOMStorageArea::OriginFromDatabaseFileName(const base::FilePath& name) {
return storage::GetOriginFromIdentifier(origin_id);
}
+void DOMStorageArea::EnableAggressiveCommitDelay() {
+ s_aggressive_flushing_enabled_ = true;
+}
+
DOMStorageArea::DOMStorageArea(const GURL& origin,
const base::FilePath& directory,
DOMStorageTaskRunner* task_runner)
@@ -388,6 +394,9 @@ void DOMStorageArea::StartCommitTimer() {
}
base::TimeDelta DOMStorageArea::ComputeCommitDelay() const {
+ if (s_aggressive_flushing_enabled_)
+ return base::TimeDelta::FromSeconds(1);
+
base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_;
base::TimeDelta delay = std::max(
base::TimeDelta::FromSeconds(kCommitDefaultDelaySecs),
diff --git a/content/browser/dom_storage/dom_storage_area.h b/content/browser/dom_storage/dom_storage_area.h
index 3a4b166..dd0df52 100644
--- a/content/browser/dom_storage/dom_storage_area.h
+++ b/content/browser/dom_storage/dom_storage_area.h
@@ -35,6 +35,12 @@ class CONTENT_EXPORT DOMStorageArea
static base::FilePath DatabaseFileNameFromOrigin(const GURL& origin);
static GURL OriginFromDatabaseFileName(const base::FilePath& file_name);
+ // Commence aggressive flushing. This should be called early in the startup -
+ // before any localStorage writing. Currently scheduled writes will not be
+ // rescheduled and will be flushed at the scheduled time after which
+ // aggressive flushing will commence.
+ static void EnableAggressiveCommitDelay();
+
// Local storage. Backed on disk if directory is nonempty.
DOMStorageArea(const GURL& origin,
const base::FilePath& directory,
@@ -153,6 +159,8 @@ class CONTENT_EXPORT DOMStorageArea
void ShutdownInCommitSequence();
+ static bool s_aggressive_flushing_enabled_;
+
int64 namespace_id_;
std::string persistent_namespace_id_;
GURL origin_;
diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc
index 48802b5..8d0b9e3 100644
--- a/content/public/common/content_switches.cc
+++ b/content/public/common/content_switches.cc
@@ -940,6 +940,10 @@ const char kRemoteDebuggingSocketName[] = "remote-debugging-socket-name";
const char kRendererWaitForJavaDebugger[] = "renderer-wait-for-java-debugger";
#endif
+// Enable the aggressive flushing of DOM Storage to minimize data loss.
+const char kEnableAggressiveDOMStorageFlushing[] =
+ "enable-aggressive-domstorage-flushing";
+
// Disable web audio API.
const char kDisableWebAudio[] = "disable-webaudio";
diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h
index 300f8b6..3b15957 100644
--- a/content/public/common/content_switches.h
+++ b/content/public/common/content_switches.h
@@ -90,6 +90,7 @@ CONTENT_EXPORT extern const char kDisableWebSecurity[];
extern const char kDisableXSSAuditor[];
CONTENT_EXPORT extern const char kDomAutomationController[];
extern const char kEnable2dCanvasClipAntialiasing[];
+CONTENT_EXPORT extern const char kEnableAggressiveDOMStorageFlushing[];
CONTENT_EXPORT extern const char kEnableBleedingEdgeRenderingFastPaths[];
CONTENT_EXPORT extern const char kEnableCompositorAnimationTimelines[];
CONTENT_EXPORT extern const char kEnableCredentialManagerAPI[];