Skip to content

Commit

Permalink
Cherry pick PR youtube#515: Add synchronous storage flush options. (y…
Browse files Browse the repository at this point in the history
…outube#531)

This adds a synchronous storage flush to the BrowserModule freeze
transition, and allows synchronous flushing from H5vccStorage.

b/272634936

(cherry picked from commit 50f7928)

Co-authored-by: Jelle Foks <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and jellefoks authored Jun 1, 2023
1 parent b087f12 commit 7bbfff7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,11 @@ void BrowserModule::FreezeInternal(SbTimeMonotonic timestamp) {
// First freeze all our web modules which implies that they will release
// their resource provider and all resources created through it.
FOR_EACH_OBSERVER(LifecycleObserver, lifecycle_observers_, Freeze(timestamp));

if (network_module_) {
// Synchronously wait for storage to flush before returning from freezing.
network_module_->storage_manager()->FlushSynchronous();
}
}

void BrowserModule::RevealInternal(SbTimeMonotonic timestamp) {
Expand Down
7 changes: 4 additions & 3 deletions cobalt/h5vcc/h5vcc_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ void H5vccStorage::ClearCookies() {

void H5vccStorage::Flush(const base::Optional<bool>& sync) {
if (sync.value_or(false) == true) {
DLOG(WARNING) << "Synchronous flush is not supported.";
// Synchronously wait for storage to flush before returning.
network_module_->storage_manager()->FlushSynchronous();
} else {
network_module_->storage_manager()->FlushNow();
}

network_module_->storage_manager()->FlushNow(base::Closure());
}

bool H5vccStorage::GetCookiesEnabled() {
Expand Down
12 changes: 12 additions & 0 deletions cobalt/storage/storage_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ void StorageManager::FlushNow(base::OnceClosure callback) {
QueueFlush(std::move(callback));
}

// Triggers a write to disk to happen immediately and doesn't return until the
// I/O has completed.
void StorageManager::FlushSynchronous() {
base::WaitableEvent flush_finished = {
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED};
FlushNow(base::Bind(
[](base::WaitableEvent* flush_finished) { flush_finished->Signal(); },
base::Unretained(&flush_finished)));
flush_finished.Wait();
}

void StorageManager::FinishInit() {
TRACE_EVENT0("cobalt::storage", __FUNCTION__);
DCHECK(storage_task_runner_->RunsTasksInCurrentSequence());
Expand Down
4 changes: 4 additions & 0 deletions cobalt/storage/storage_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class StorageManager : public base::MessageLoop::DestructionObserver {
// This call returns immediately.
void FlushNow(base::OnceClosure callback = base::Closure());

// Triggers a write to disk to happen immediately and doesn't return until the
// I/O has completed.
void FlushSynchronous();

const Options& options() const { return options_; }

void set_network_task_runner(
Expand Down

0 comments on commit 7bbfff7

Please sign in to comment.