Skip to content

Commit

Permalink
Avoid nested loops when committing updater prefs.
Browse files Browse the repository at this point in the history
Fixed: 1280401
Change-Id: Ifad83da026676f339e4db8e0ebf23a1dd2bf95e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3340087
Auto-Submit: Sorin Jianu <sorin@chromium.org>
Reviewed-by: Joshua Pawlicki <waffles@chromium.org>
Commit-Queue: Joshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/main@{#952103}
  • Loading branch information
sorinj authored and Chromium LUCI CQ committed Dec 15, 2021
1 parent 7d60b1c commit 672035e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions chrome/updater/prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

#include "chrome/updater/prefs.h"

#include <functional>
#include <memory>
#include <string>
#include <utility>

#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/prefs_impl.h"
#include "chrome/updater/updater_scope.h"
Expand Down Expand Up @@ -133,12 +136,14 @@ scoped_refptr<LocalPrefs> CreateLocalPrefs(UpdaterScope scope) {
}

void PrefsCommitPendingWrites(PrefService* pref_service) {
// Waits in the run loop until pending writes complete.
base::RunLoop runloop;
pref_service->CommitPendingWrite(base::BindOnce(
[](base::OnceClosure quit_closure) { std::move(quit_closure).Run(); },
runloop.QuitWhenIdleClosure()));
runloop.Run();
base::WaitableEvent write_complete_event;
pref_service->CommitPendingWrite({}, base::BindOnce(
[](base::WaitableEvent& event) {
VLOG(1) << "Prefs committed.";
event.Signal();
},
std::ref(write_complete_event)));
write_complete_event.Wait();
}

} // namespace updater

0 comments on commit 672035e

Please sign in to comment.