Skip to content

Commit 755f160

Browse files
author
Pavol Marko
committed
[Merge to M62] Commit minimal migration status to local state prefs
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 [email protected] (cherry picked from commit e1f238f) Change-Id: I565ffbae7b8a1e934875101012c39c8a9841a139 Reviewed-on: https://chromium-review.googlesource.com/647454 Reviewed-by: Xiyuan Xia <[email protected]> Reviewed-by: Bernhard Bauer <[email protected]> Commit-Queue: Pavol Marko <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#499693} Reviewed-on: https://chromium-review.googlesource.com/653639 Reviewed-by: Pavol Marko <[email protected]> Cr-Commit-Position: refs/branch-heads/3202@{#52} Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
1 parent 52f8877 commit 755f160

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

chrome/browser/chromeos/login/existing_user_controller.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,15 +1063,19 @@ void ExistingUserController::OnPolicyFetchResult(
10631063
case apu::EcryptfsMigrationAction::kMigrate:
10641064
user_manager::known_user::SetUserHomeMinimalMigrationAttempted(
10651065
user_context.GetAccountId(), false);
1066-
ShowEncryptionMigrationScreen(user_context,
1067-
EncryptionMigrationMode::START_MIGRATION);
1066+
user_manager::UserManager::Get()->GetLocalState()->CommitPendingWrite(
1067+
base::BindOnce(&ExistingUserController::ShowEncryptionMigrationScreen,
1068+
weak_factory_.GetWeakPtr(), user_context,
1069+
EncryptionMigrationMode::START_MIGRATION));
10681070
break;
10691071

10701072
case apu::EcryptfsMigrationAction::kAskUser:
10711073
user_manager::known_user::SetUserHomeMinimalMigrationAttempted(
10721074
user_context.GetAccountId(), false);
1073-
ShowEncryptionMigrationScreen(user_context,
1074-
EncryptionMigrationMode::ASK_USER);
1075+
user_manager::UserManager::Get()->GetLocalState()->CommitPendingWrite(
1076+
base::BindOnce(&ExistingUserController::ShowEncryptionMigrationScreen,
1077+
weak_factory_.GetWeakPtr(), user_context,
1078+
EncryptionMigrationMode::ASK_USER));
10751079
break;
10761080

10771081
case apu::EcryptfsMigrationAction::kWipe:
@@ -1089,8 +1093,10 @@ void ExistingUserController::OnPolicyFetchResult(
10891093
user_context.GetAccountId());
10901094
user_manager::known_user::SetUserHomeMinimalMigrationAttempted(
10911095
user_context.GetAccountId(), true);
1092-
ShowEncryptionMigrationScreen(
1093-
user_context, EncryptionMigrationMode::START_MINIMAL_MIGRATION);
1096+
user_manager::UserManager::Get()->GetLocalState()->CommitPendingWrite(
1097+
base::BindOnce(&ExistingUserController::ShowEncryptionMigrationScreen,
1098+
weak_factory_.GetWeakPtr(), user_context,
1099+
EncryptionMigrationMode::START_MINIMAL_MIGRATION));
10941100
break;
10951101

10961102
case apu::EcryptfsMigrationAction::kAskForEcryptfsArcUsers:

chrome/browser/prefs/profile_pref_store_manager_unittest.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,8 @@ class ProfilePrefStoreManagerTest : public testing::Test,
245245
ClearResetRecorded();
246246
// Force everything to be written to disk, triggering the PrefHashFilter
247247
// while our RegistryVerifier is watching.
248-
pref_store_->CommitPendingWrite();
249-
base::RunLoop().RunUntilIdle();
250248
base::RunLoop run_loop;
251-
base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply(
252-
FROM_HERE, base::BindOnce(&base::DoNothing), run_loop.QuitClosure());
249+
pref_store_->CommitPendingWrite(run_loop.QuitClosure());
253250
run_loop.Run();
254251

255252
pref_store_->RemoveObserver(&registry_verifier_);
@@ -275,11 +272,8 @@ class ProfilePrefStoreManagerTest : public testing::Test,
275272
base::MakeUnique<base::Value>(kFoobar),
276273
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
277274
pref_store->RemoveObserver(&registry_verifier_);
278-
pref_store->CommitPendingWrite();
279-
base::RunLoop().RunUntilIdle();
280275
base::RunLoop run_loop;
281-
base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply(
282-
FROM_HERE, base::BindOnce(&base::DoNothing), run_loop.QuitClosure());
276+
pref_store->CommitPendingWrite(run_loop.QuitClosure());
283277
run_loop.Run();
284278
}
285279

components/prefs/persistent_pref_store.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
#include "base/threading/sequenced_task_runner_handle.h"
1010

11-
void PersistentPrefStore::CommitPendingWrite() {
12-
CommitPendingWrite(base::OnceClosure());
13-
}
14-
1511
void PersistentPrefStore::CommitPendingWrite(base::OnceClosure done_callback) {
1612
// Default behavior for PersistentPrefStore implementation that don't issue
1713
// disk operations: schedule the callback immediately.

components/prefs/persistent_pref_store.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ class COMPONENTS_PREFS_EXPORT PersistentPrefStore : public WriteablePrefStore {
6262
// Owns |error_delegate|.
6363
virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) = 0;
6464

65-
// Starts an asynchronous attempt to commit pending writes to disk.
66-
void CommitPendingWrite();
67-
6865
// Starts an asynchronous attempt to commit pending writes to disk. Posts a
6966
// task to run |done_callback| on the current sequence when disk operations,
7067
// if any, are complete (even if they are unsuccessful).

components/prefs/pref_service.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ void PrefService::InitFromStorage(bool async) {
104104
}
105105

106106
void PrefService::CommitPendingWrite() {
107+
CommitPendingWrite(base::OnceClosure());
108+
}
109+
110+
void PrefService::CommitPendingWrite(base::OnceClosure done_callback) {
107111
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
108-
user_pref_store_->CommitPendingWrite();
112+
user_pref_store_->CommitPendingWrite(std::move(done_callback));
109113
}
110114

111115
void PrefService::SchedulePendingLossyWrites() {

components/prefs/pref_service.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ class COMPONENTS_PREFS_EXPORT PrefService {
177177
// immediately (basically, during shutdown).
178178
void CommitPendingWrite();
179179

180+
// Lands pending writes to disk. This should only be used if we need to save
181+
// immediately. |done_callback| will be invoked when changes have been
182+
// written.
183+
void CommitPendingWrite(base::OnceClosure done_callback);
184+
180185
// Schedule a write if there is any lossy data pending. Unlike
181186
// CommitPendingWrite() this does not immediately sync to disk, instead it
182187
// triggers an eventual write if there is lossy data pending and if there

0 commit comments

Comments
 (0)