Skip to content

Commit

Permalink
Allow hash migration for unloaded profiles.
Browse files Browse the repository at this point in the history
This augments the current capacity to seed unloaded profiles to also be able to go through the migration path from the old hashes to the new ones for profiles that have yet to migrate.

This introduces a PrefHashStore version which will begin at 2 (0 being the absence of hashes and 1 being the presence of the old hashes).

[email protected], [email protected]
TBR=sky (chrome_browser_main.cc -- see comment crosswalk-project#22)

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251700 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
[email protected] committed Feb 17, 2014
1 parent e4c5f97 commit 269e05a
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 150 deletions.
15 changes: 1 addition & 14 deletions chrome/browser/chrome_browser_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,17 +508,6 @@ class LoadCompleteListener : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(LoadCompleteListener);
};

void InitializeAllPrefHashStores() {
ProfileInfoCache& profile_info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t n_profiles = profile_info_cache.GetNumberOfProfiles();
for (size_t i = 0; i < n_profiles; ++i) {
base::FilePath profile_path =
profile_info_cache.GetPathOfProfileAtIndex(i);
chrome_prefs::InitializePrefHashStoreIfRequired(profile_path);
}
}

} // namespace

namespace chrome_browser {
Expand Down Expand Up @@ -1588,9 +1577,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {

PostBrowserStart();

// Initialize preference hash stores for profiles that haven't been loaded
// recently.
InitializeAllPrefHashStores();
chrome_prefs::SchedulePrefHashStoresUpdateCheck(profile_->GetPath());

if (parameters().ui_task) {
// We end the startup timer here if we have parameters to run, because we
Expand Down
113 changes: 84 additions & 29 deletions chrome/browser/prefs/chrome_pref_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/prefs/pref_service_syncable_factory.h"
#include "chrome/browser/profiles/file_path_verifier_win.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/profile_error_dialog.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -67,6 +69,10 @@ using content::BrowserThread;

namespace {

// The delay in seconds before actual work kicks in after calling
// SchedulePrefHashStoresUpdateCheck can be set to 0 for tests.
int g_pref_hash_store_update_check_delay_seconds = 55;

// These preferences must be kept in sync with the TrackedPreference enum in
// tools/metrics/histograms/histograms.xml. To add a new preference, append it
// to the array and add a corresponding value to the histogram enum. Each
Expand Down Expand Up @@ -156,7 +162,6 @@ enum SettingsEnforcementGroup {
// Only enforce settings on profile loads; still allow seeding of unloaded
// profiles.
GROUP_ENFORCE_ON_LOAD,
// TOOD(gab): Block unloaded profile seeding in this mode.
GROUP_ENFORCE_ALWAYS
};

Expand Down Expand Up @@ -373,9 +378,11 @@ class InitializeHashStoreObserver : public PrefStore::Observer {
public:
// Creates an observer that will initialize |pref_hash_store| with the
// contents of |pref_store| when the latter is fully loaded.
InitializeHashStoreObserver(const scoped_refptr<PrefStore>& pref_store,
scoped_ptr<PrefHashStore> pref_hash_store)
: pref_store_(pref_store), pref_hash_store_(pref_hash_store.Pass()) {}
InitializeHashStoreObserver(
const scoped_refptr<PrefStore>& pref_store,
scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl)
: pref_store_(pref_store),
pref_hash_store_impl_(pref_hash_store_impl.Pass()) {}

virtual ~InitializeHashStoreObserver();

Expand All @@ -385,7 +392,7 @@ class InitializeHashStoreObserver : public PrefStore::Observer {

private:
scoped_refptr<PrefStore> pref_store_;
scoped_ptr<PrefHashStore> pref_hash_store_;
scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl_;

DISALLOW_COPY_AND_ASSIGN(InitializeHashStoreObserver);
};
Expand All @@ -395,18 +402,70 @@ InitializeHashStoreObserver::~InitializeHashStoreObserver() {}
void InitializeHashStoreObserver::OnPrefValueChanged(const std::string& key) {}

void InitializeHashStoreObserver::OnInitializationCompleted(bool succeeded) {
// If we successfully loaded the preferences _and_ the PrefHashStore hasn't
// been initialized by someone else in the meantime initialize it now.
if (succeeded & !pref_hash_store_->IsInitialized()) {
CreatePrefHashFilter(
pref_hash_store_.Pass())->Initialize(*pref_store_);
UMA_HISTOGRAM_BOOLEAN(
"Settings.TrackedPreferencesInitializedForUnloadedProfile", true);
// If we successfully loaded the preferences _and_ the PrefHashStoreImpl
// hasn't been initialized by someone else in the meantime, initialize it now.
const PrefHashStoreImpl::StoreVersion pre_update_version =
pref_hash_store_impl_->GetCurrentVersion();
if (succeeded && pre_update_version < PrefHashStoreImpl::VERSION_LATEST) {
CreatePrefHashFilter(pref_hash_store_impl_.PassAs<PrefHashStore>())->
Initialize(*pref_store_);
UMA_HISTOGRAM_ENUMERATION(
"Settings.TrackedPreferencesAlternateStoreVersionUpdatedFrom",
pre_update_version,
PrefHashStoreImpl::VERSION_LATEST + 1);
}
pref_store_->RemoveObserver(this);
delete this;
}

// Initializes/updates the PrefHashStore for the profile preferences file under
// |profile_path| without actually loading that profile. Also reports the
// version of that PrefHashStore via UMA, whether it proceeds with initializing
// it or not.
void UpdatePrefHashStoreIfRequired(
const base::FilePath& profile_path) {
scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl(
GetPrefHashStoreImpl(profile_path));

const PrefHashStoreImpl::StoreVersion current_version =
pref_hash_store_impl->GetCurrentVersion();
UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferencesAlternateStoreVersion",
current_version,
PrefHashStoreImpl::VERSION_LATEST + 1);

// Update the pref hash store if it's not at the latest version and the
// SettingsEnforcement group allows seeding of unloaded profiles.
if (current_version != PrefHashStoreImpl::VERSION_LATEST &&
GetSettingsEnforcementGroup() < GROUP_ENFORCE_ALWAYS) {
const base::FilePath pref_file(
GetPrefFilePathFromProfilePath(profile_path));
scoped_refptr<JsonPrefStore> pref_store(
new JsonPrefStore(pref_file,
JsonPrefStore::GetTaskRunnerForFile(
pref_file, BrowserThread::GetBlockingPool()),
scoped_ptr<PrefFilter>()));
pref_store->AddObserver(
new InitializeHashStoreObserver(pref_store,
pref_hash_store_impl.Pass()));
pref_store->ReadPrefsAsync(NULL);
}
}

// Initialize/update preference hash stores for all profiles but the one whose
// path matches |ignored_profile_path|.
void UpdateAllPrefHashStoresIfRequired(
const base::FilePath& ignored_profile_path) {
const ProfileInfoCache& profile_info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
const size_t n_profiles = profile_info_cache.GetNumberOfProfiles();
for (size_t i = 0; i < n_profiles; ++i) {
const base::FilePath profile_path =
profile_info_cache.GetPathOfProfileAtIndex(i);
if (profile_path != ignored_profile_path)
UpdatePrefHashStoreIfRequired(profile_path);
}
}

} // namespace

namespace chrome_prefs {
Expand Down Expand Up @@ -471,23 +530,19 @@ void SchedulePrefsFilePathVerification(const base::FilePath& profile_path) {
#endif
}

void InitializePrefHashStoreIfRequired(
const base::FilePath& profile_path) {
scoped_ptr<PrefHashStoreImpl> pref_hash_store(
GetPrefHashStoreImpl(profile_path));
if (pref_hash_store && !pref_hash_store->IsInitialized()) {
const base::FilePath pref_file(
GetPrefFilePathFromProfilePath(profile_path));
scoped_refptr<JsonPrefStore> pref_store(
new JsonPrefStore(pref_file,
JsonPrefStore::GetTaskRunnerForFile(
pref_file, BrowserThread::GetBlockingPool()),
scoped_ptr<PrefFilter>()));
pref_store->AddObserver(
new InitializeHashStoreObserver(
pref_store, pref_hash_store.PassAs<PrefHashStore>()));
pref_store->ReadPrefsAsync(NULL);
}
void EnableZeroDelayPrefHashStoreUpdateForTesting() {
g_pref_hash_store_update_check_delay_seconds = 0;
}

void SchedulePrefHashStoresUpdateCheck(
const base::FilePath& initial_profile_path) {
BrowserThread::PostDelayedTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&UpdateAllPrefHashStoresIfRequired,
initial_profile_path),
base::TimeDelta::FromSeconds(
g_pref_hash_store_update_check_delay_seconds));
}

void ResetPrefHashStore(const base::FilePath& profile_path) {
Expand Down
12 changes: 8 additions & 4 deletions chrome/browser/prefs/chrome_pref_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ scoped_ptr<PrefServiceSyncable> CreateProfilePrefs(
// |profile_path|.
void SchedulePrefsFilePathVerification(const base::FilePath& profile_path);

// Initializes the PrefHashStore for the profile preferences file under
// |profile_path| without actually loading that profile.
void InitializePrefHashStoreIfRequired(
const base::FilePath& profile_path);
// Call before calling SchedulePrefHashStoresUpdateCheck to cause it to run with
// zero delay. For testing only.
void EnableZeroDelayPrefHashStoreUpdateForTesting();

// Shedules an update check for all PrefHashStores, stores whose version doesn't
// match the latest version will then be updated.
void SchedulePrefHashStoresUpdateCheck(
const base::FilePath& initial_profile_path);

// Resets the contents of the preference hash store for the profile at
// |profile_path|.
Expand Down
Loading

0 comments on commit 269e05a

Please sign in to comment.