Skip to content

Commit

Permalink
[Merge to M62] Commit minimal migration status to local state prefs
Browse files Browse the repository at this point in the history
Commit minimal migration status to local state PrefService.
Introduces a CommitPendingWrite function with a callback to be sure that
prefs landed on disk.

BUG=747907
TBR=pmarko@chromium.org

(cherry picked from commit e1f238f)

Change-Id: I565ffbae7b8a1e934875101012c39c8a9841a139
Reviewed-on: https://chromium-review.googlesource.com/647454
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Bernhard Bauer <bauerb@chromium.org>
Commit-Queue: Pavol Marko <pmarko@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#499693}
Reviewed-on: https://chromium-review.googlesource.com/653639
Reviewed-by: Pavol Marko <pmarko@chromium.org>
Cr-Commit-Position: refs/branch-heads/3202@{#52}
Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
  • Loading branch information
Pavol Marko committed Sep 6, 2017
1 parent 52f8877 commit 755f160
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
18 changes: 12 additions & 6 deletions chrome/browser/chromeos/login/existing_user_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1063,15 +1063,19 @@ void ExistingUserController::OnPolicyFetchResult(
case apu::EcryptfsMigrationAction::kMigrate:
user_manager::known_user::SetUserHomeMinimalMigrationAttempted(
user_context.GetAccountId(), false);
ShowEncryptionMigrationScreen(user_context,
EncryptionMigrationMode::START_MIGRATION);
user_manager::UserManager::Get()->GetLocalState()->CommitPendingWrite(
base::BindOnce(&ExistingUserController::ShowEncryptionMigrationScreen,
weak_factory_.GetWeakPtr(), user_context,
EncryptionMigrationMode::START_MIGRATION));
break;

case apu::EcryptfsMigrationAction::kAskUser:
user_manager::known_user::SetUserHomeMinimalMigrationAttempted(
user_context.GetAccountId(), false);
ShowEncryptionMigrationScreen(user_context,
EncryptionMigrationMode::ASK_USER);
user_manager::UserManager::Get()->GetLocalState()->CommitPendingWrite(
base::BindOnce(&ExistingUserController::ShowEncryptionMigrationScreen,
weak_factory_.GetWeakPtr(), user_context,
EncryptionMigrationMode::ASK_USER));
break;

case apu::EcryptfsMigrationAction::kWipe:
Expand All @@ -1089,8 +1093,10 @@ void ExistingUserController::OnPolicyFetchResult(
user_context.GetAccountId());
user_manager::known_user::SetUserHomeMinimalMigrationAttempted(
user_context.GetAccountId(), true);
ShowEncryptionMigrationScreen(
user_context, EncryptionMigrationMode::START_MINIMAL_MIGRATION);
user_manager::UserManager::Get()->GetLocalState()->CommitPendingWrite(
base::BindOnce(&ExistingUserController::ShowEncryptionMigrationScreen,
weak_factory_.GetWeakPtr(), user_context,
EncryptionMigrationMode::START_MINIMAL_MIGRATION));
break;

case apu::EcryptfsMigrationAction::kAskForEcryptfsArcUsers:
Expand Down
10 changes: 2 additions & 8 deletions chrome/browser/prefs/profile_pref_store_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,8 @@ class ProfilePrefStoreManagerTest : public testing::Test,
ClearResetRecorded();
// Force everything to be written to disk, triggering the PrefHashFilter
// while our RegistryVerifier is watching.
pref_store_->CommitPendingWrite();
base::RunLoop().RunUntilIdle();
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply(
FROM_HERE, base::BindOnce(&base::DoNothing), run_loop.QuitClosure());
pref_store_->CommitPendingWrite(run_loop.QuitClosure());
run_loop.Run();

pref_store_->RemoveObserver(&registry_verifier_);
Expand All @@ -275,11 +272,8 @@ class ProfilePrefStoreManagerTest : public testing::Test,
base::MakeUnique<base::Value>(kFoobar),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
pref_store->RemoveObserver(&registry_verifier_);
pref_store->CommitPendingWrite();
base::RunLoop().RunUntilIdle();
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply(
FROM_HERE, base::BindOnce(&base::DoNothing), run_loop.QuitClosure());
pref_store->CommitPendingWrite(run_loop.QuitClosure());
run_loop.Run();
}

Expand Down
4 changes: 0 additions & 4 deletions components/prefs/persistent_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

#include "base/threading/sequenced_task_runner_handle.h"

void PersistentPrefStore::CommitPendingWrite() {
CommitPendingWrite(base::OnceClosure());
}

void PersistentPrefStore::CommitPendingWrite(base::OnceClosure done_callback) {
// Default behavior for PersistentPrefStore implementation that don't issue
// disk operations: schedule the callback immediately.
Expand Down
3 changes: 0 additions & 3 deletions components/prefs/persistent_pref_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class COMPONENTS_PREFS_EXPORT PersistentPrefStore : public WriteablePrefStore {
// Owns |error_delegate|.
virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) = 0;

// Starts an asynchronous attempt to commit pending writes to disk.
void CommitPendingWrite();

// Starts an asynchronous attempt to commit pending writes to disk. Posts a
// task to run |done_callback| on the current sequence when disk operations,
// if any, are complete (even if they are unsuccessful).
Expand Down
6 changes: 5 additions & 1 deletion components/prefs/pref_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ void PrefService::InitFromStorage(bool async) {
}

void PrefService::CommitPendingWrite() {
CommitPendingWrite(base::OnceClosure());
}

void PrefService::CommitPendingWrite(base::OnceClosure done_callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
user_pref_store_->CommitPendingWrite();
user_pref_store_->CommitPendingWrite(std::move(done_callback));
}

void PrefService::SchedulePendingLossyWrites() {
Expand Down
5 changes: 5 additions & 0 deletions components/prefs/pref_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ class COMPONENTS_PREFS_EXPORT PrefService {
// immediately (basically, during shutdown).
void CommitPendingWrite();

// Lands pending writes to disk. This should only be used if we need to save
// immediately. |done_callback| will be invoked when changes have been
// written.
void CommitPendingWrite(base::OnceClosure done_callback);

// Schedule a write if there is any lossy data pending. Unlike
// CommitPendingWrite() this does not immediately sync to disk, instead it
// triggers an eventual write if there is lossy data pending and if there
Expand Down

0 comments on commit 755f160

Please sign in to comment.