Commit 62bd9e3d authored by sdefresne's avatar sdefresne Committed by Commit bot

Commit History transaction when app is backgrounded on iOS

Request time from the OS when the application is backgrounded on iOS to
try to commit all pending history transactions.

BUG=429756

Review URL: https://codereview.chromium.org/1015153002

Cr-Commit-Position: refs/heads/master@{#321329}
parent 4788d01b
......@@ -44,6 +44,10 @@
#include "url/gurl.h"
#include "url/url_constants.h"
#if defined(OS_IOS)
#include "base/ios/scoped_critical_action.h"
#endif
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
......@@ -260,6 +264,12 @@ void HistoryBackend::Closing() {
delegate_.reset();
}
#if defined(OS_IOS)
void HistoryBackend::PersistState() {
Commit();
}
#endif
void HistoryBackend::ClearCachedDataForContextID(ContextID context_id) {
tracker_.ClearCachedDataForContextID(context_id);
}
......@@ -2168,6 +2178,12 @@ void HistoryBackend::Commit() {
if (!db_)
return;
#if defined(OS_IOS)
// Attempts to get the application running long enough to commit the database
// transaction if it is currently being backgrounded.
base::ios::ScopedCriticalAction scoped_critical_action;
#endif
// Note that a commit may not actually have been scheduled if a caller
// explicitly calls this instead of using ScheduleCommit. Likewise, we
// may reset the flag written by a pending commit. But this is OK! It
......
......@@ -191,6 +191,12 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// actually be deleted.
void Closing();
#if defined(OS_IOS)
// Persists any in-flight state, without actually shutting down the history
// system. This is intended for use when the application is backgrounded.
void PersistState();
#endif
void ClearCachedDataForContextID(ContextID context_id);
// Navigation ----------------------------------------------------------------
......
......@@ -46,6 +46,10 @@
#include "sync/api/sync_error_factory.h"
#include "third_party/skia/include/core/SkBitmap.h"
#if defined(OS_IOS)
#include "base/critical_closure.h"
#endif
using base::Time;
namespace history {
......@@ -205,6 +209,17 @@ bool HistoryService::BackendLoaded() {
return backend_loaded_;
}
#if defined(OS_IOS)
void HistoryService::HandleBackgrounding() {
if (!thread_ || !history_backend_.get())
return;
ScheduleTask(PRIORITY_NORMAL,
base::MakeCriticalClosure(base::Bind(
&HistoryBackend::PersistState, history_backend_.get())));
}
#endif
void HistoryService::ClearCachedDataForContextID(ContextID context_id) {
DCHECK(thread_) << "History service being called after cleanup";
DCHECK(thread_checker_.CalledOnValidThread());
......
......@@ -105,6 +105,12 @@ class HistoryService : public syncer::SyncableService, public KeyedService {
// Returns true if the backend has finished loading.
bool backend_loaded() const { return backend_loaded_; }
#if defined(OS_IOS)
// Causes the history backend to commit any in-progress transactions. Called
// when the application is being backgrounded.
void HandleBackgrounding();
#endif
// Context ids are used to scope page IDs (see AddPage). These contexts
// must tell us when they are being invalidated so that we can clear
// out any cached data associated with that context.
......
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