Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: chrome/browser/profile_resetter/automatic_profile_resetter.cc

Issue 27030002: Added collecting of data to be fed to the JTL interpreter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profile_resetter/automatic_profile_resetter.cc
diff --git a/chrome/browser/profile_resetter/automatic_profile_resetter.cc b/chrome/browser/profile_resetter/automatic_profile_resetter.cc
index c0f7d252608a04107ed2dd37500e80b534f7384b..18fea1fc8a70b6c47c9d76ca68c925346010ef39 100644
--- a/chrome/browser/profile_resetter/automatic_profile_resetter.cc
+++ b/chrome/browser/profile_resetter/automatic_profile_resetter.cc
@@ -10,9 +10,12 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/task_runner.h"
#include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h"
#include "chrome/browser/profile_resetter/jtl_interpreter.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_thread.h"
@@ -21,25 +24,20 @@
namespace {
-// Number of bits, and maximum value (exclusive) for the mask whose bits
-// indicate which of reset criteria were satisfied.
-const size_t kSatisfiedCriteriaMaskBits = 2;
-const uint32 kSatisfiedCriteriaMaskMaximumValue =
- (1 << kSatisfiedCriteriaMaskBits);
-
-// Number of bits, and maximum value (exclusive) for the mask whose bits
-// indicate if any of reset criteria were satisfied, and which of the mementos
-// were already present.
-const size_t kCombinedStatusMaskBits = 4;
-const uint32 kCombinedStatusMaskMaximumValue = (1 << kCombinedStatusMaskBits);
-
// Name constants for the field trial behind which we enable this feature.
const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset";
const char kAutomaticProfileResetStudyDryRunGroupName[] = "DryRun";
const char kAutomaticProfileResetStudyEnabledGroupName[] = "Enabled";
// Keys used in the input dictionary of the program.
-// TODO(engedy): Add these here on an as-needed basis.
+const char kUserPreferencesKey[] = "preferences";
+const char kUserPreferencesIsUserControlledKey[] = "preferences_iuc";
+const char kLocalStateKey[] = "local_state";
+const char kLocalStateIsUserControlledKey[] = "local_state_iuc";
+const char kSearchProvidersKey[] = "search_providers";
+const char kDefaultSearchProviderKey[] = "default_search_provider";
+const char kDefaultSearchProviderIsUserControlledKey[] =
+ "default_search_provider_iuc";
// Keys used in the output dictionary of the program.
const char kHadPromptedAlreadyKey[] = "had_prompted_already";
@@ -54,39 +52,7 @@ const char kMementoValueInPrefsKey[] = "memento_value_in_prefs";
const char kMementoValueInLocalStateKey[] = "memento_value_in_local_state";
const char kMementoValueInFileKey[] = "memento_value_in_file";
-COMPILE_ASSERT(
- arraysize(kSatisfiedCriteriaMaskKeys) == kSatisfiedCriteriaMaskBits,
- satisfied_criteria_mask_bits_mismatch);
-COMPILE_ASSERT(arraysize(kCombinedStatusMaskKeys) == kCombinedStatusMaskBits,
- combined_status_mask_bits_mismatch);
-
-// Implementation detail classes ---------------------------------------------
-
-class AutomaticProfileResetterDelegateImpl
- : public AutomaticProfileResetterDelegate {
- public:
- AutomaticProfileResetterDelegateImpl() {}
- virtual ~AutomaticProfileResetterDelegateImpl() {}
-
- // AutomaticProfileResetterDelegate overrides:
-
- virtual void ShowPrompt() OVERRIDE {
- // TODO(engedy): Call the UI from here once we have it.
- }
-
- virtual void ReportStatistics(uint32 satisfied_criteria_mask,
- uint32 combined_status_mask) OVERRIDE {
- UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.SatisfiedCriteriaMask",
- satisfied_criteria_mask,
- kSatisfiedCriteriaMaskMaximumValue);
- UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.CombinedStatusMask",
- combined_status_mask,
- kCombinedStatusMaskMaximumValue);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl);
-};
+// Implementation details ------------------------------------------------------
// Enumeration of the possible outcomes of showing the profile reset prompt.
enum PromptResult {
@@ -100,6 +66,32 @@ enum PromptResult {
PROMPT_RESULT_MAX
};
+// Deep-copies all preferences in |source| to a sub-tree named |value_tree_key|
+// in |target_dictionary|, with path expansion, and also creates an isomorphic
+// sub-tree under the key |is_user_controlled_tree_key| that contains only
+// Boolean values, indicating whether or not the corresponding preferences are
+// coming from the 'user' PrefStore.
+void BuildSubTreesFromPreferences(const PrefService* source,
+ base::DictionaryValue* target_dictionary,
+ const char* value_tree_key,
+ const char* is_user_controlled_tree_key) {
+ scoped_ptr<base::DictionaryValue> pref_name_to_value_map(
+ source->GetPreferenceValuesWithoutPathExpansion());
+ base::DictionaryValue* value_tree = new base::DictionaryValue;
+ base::DictionaryValue* is_user_controlled_tree = new base::DictionaryValue;
+ for (base::DictionaryValue::Iterator it(*pref_name_to_value_map);
+ !it.IsAtEnd();
+ it.Advance()) {
+ value_tree->Set(it.key(), it.value().DeepCopy());
battre 2013/10/11 15:05:33 Should this and the one in line 88 be SetWithoutPa
engedy 2013/10/11 16:42:16 Avoided the double-copy as we discussed.
+ const PrefService::Preference* pref =
+ source->FindPreference(it.key().c_str());
+ is_user_controlled_tree->Set(
+ it.key(), new base::FundamentalValue(pref->IsUserControlled()));
+ }
+ target_dictionary->Set(value_tree_key, value_tree);
+ target_dictionary->Set(is_user_controlled_tree_key, is_user_controlled_tree);
+}
+
} // namespace
// AutomaticProfileResetter::EvaluationResults -------------------------------
@@ -122,6 +114,21 @@ struct AutomaticProfileResetter::EvaluationResults {
// AutomaticProfileResetter --------------------------------------------------
+const size_t AutomaticProfileResetter::kSatisfiedCriteriaMaskBits = 2;
+const uint32 AutomaticProfileResetter::kSatisfiedCriteriaMaskMaximumValue =
+ (1 << AutomaticProfileResetter::kSatisfiedCriteriaMaskBits);
+
+const size_t AutomaticProfileResetter::kCombinedStatusMaskBits = 4;
+const uint32 AutomaticProfileResetter::kCombinedStatusMaskMaximumValue =
+ (1 << AutomaticProfileResetter::kCombinedStatusMaskBits);
+
+COMPILE_ASSERT(arraysize(kSatisfiedCriteriaMaskKeys) ==
+ ::AutomaticProfileResetter::kSatisfiedCriteriaMaskBits,
+ satisfied_criteria_mask_bits_mismatch);
+COMPILE_ASSERT(arraysize(kCombinedStatusMaskKeys) ==
+ ::AutomaticProfileResetter::kCombinedStatusMaskBits,
+ combined_status_mask_bits_mismatch);
+
AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile)
: profile_(profile),
state_(STATE_UNINITIALIZED),
@@ -130,11 +137,12 @@ AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile)
memento_in_file_(profile_),
weak_ptr_factory_(this) {
DCHECK(profile_);
+ MaybeInitialize();
}
AutomaticProfileResetter::~AutomaticProfileResetter() {}
-void AutomaticProfileResetter::Initialize() {
+void AutomaticProfileResetter::MaybeInitialize() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK_EQ(state_, STATE_UNINITIALIZED);
@@ -151,20 +159,31 @@ void AutomaticProfileResetter::Initialize() {
hash_seed_ = resources.GetRawDataResource(
IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY);
}
- delegate_.reset(new AutomaticProfileResetterDelegateImpl());
-
- state_ = STATE_READY;
-
- content::BrowserThread::PostTask(
- content::BrowserThread::UI,
- FROM_HERE,
- base::Bind(&AutomaticProfileResetter::BeginEvaluationFlow,
- weak_ptr_factory_.GetWeakPtr()));
+ delegate_.reset(new AutomaticProfileResetterDelegateImpl(profile_));
+ state_ = STATE_INITIALIZED;
} else {
state_ = STATE_DISABLED;
}
}
+void AutomaticProfileResetter::MaybeActivate() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK(state_ == STATE_INITIALIZED || state_ == STATE_DISABLED);
+
+ if (state_ == STATE_INITIALIZED) {
+ if (!program_.empty()) {
+ state_ = STATE_WAITING_ON_SERVICES;
+ delegate_->WaitOnTemplateURLService(
+ base::Bind(&AutomaticProfileResetter::OnTemplateURLServiceBecameReady,
+ weak_ptr_factory_.GetWeakPtr()));
+ delegate_->LoadTemplateURLServiceIfNeeded();
+ } else {
+ // Terminate early if there is no program included (nor set by tests).
+ state_ = STATE_DISABLED;
+ }
+ }
+}
+
bool AutomaticProfileResetter::ShouldPerformDryRun() const {
return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) ==
kAutomaticProfileResetStudyDryRunGroupName;
@@ -175,31 +194,72 @@ bool AutomaticProfileResetter::ShouldPerformLiveRun() const {
kAutomaticProfileResetStudyEnabledGroupName;
}
+void AutomaticProfileResetter::OnTemplateURLServiceBecameReady() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK_EQ(state_, STATE_WAITING_ON_SERVICES);
battre 2013/10/11 15:05:33 nit: please swap order of parameters.
engedy 2013/10/11 16:42:16 As discussed, the original order actually looked s
+
+ state_ = STATE_READY;
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&AutomaticProfileResetter::BeginEvaluationFlow,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
void AutomaticProfileResetter::BeginEvaluationFlow() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK_EQ(state_, STATE_READY);
battre 2013/10/11 15:05:33 same here.
engedy 2013/10/11 16:42:16 Same as above.
+ DCHECK(!program_.empty());
- if (!program_.empty()) {
- state_ = STATE_WORKING;
- memento_in_file_.ReadValue(
- base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow,
- weak_ptr_factory_.GetWeakPtr()));
- } else {
- // Terminate early if there is no program included (nor set by tests).
- state_ = STATE_DISABLED;
- }
+ state_ = STATE_WORKING;
+ memento_in_file_.ReadValue(
+ base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow,
+ weak_ptr_factory_.GetWeakPtr()));
}
scoped_ptr<base::DictionaryValue>
AutomaticProfileResetter::BuildEvaluatorProgramInput(
const std::string& memento_value_in_file) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- // TODO(engedy): Add any additional state here that is needed by the program.
+
scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue);
+
+ // Include memento values (or empty strings in case mementos are not there).
input->SetString(kMementoValueInPrefsKey, memento_in_prefs_.ReadValue());
input->SetString(kMementoValueInLocalStateKey,
memento_in_local_state_.ReadValue());
input->SetString(kMementoValueInFileKey, memento_value_in_file);
+
+ // Include all user (i.e. profile-specific) preferences, along with
+ // information about whether the value is coming from the 'user' PrefStore.
+ PrefService* prefs = profile_->GetPrefs();
+ DCHECK(prefs);
+ BuildSubTreesFromPreferences(prefs,
+ input.get(),
+ kUserPreferencesKey,
+ kUserPreferencesIsUserControlledKey);
+
+ // Include all local state (i.e. shared) preferences, along with information
+ // about whether the value is coming from the 'user' PrefStore.
+ PrefService* local_state = g_browser_process->local_state();
+ DCHECK(local_state);
+ BuildSubTreesFromPreferences(
+ local_state, input.get(), kLocalStateKey, kLocalStateIsUserControlledKey);
+
+ // Include all information related to search engines.
+ base::DictionaryValue* default_search_provider_details =
+ delegate_->GetDefaultSearchProviderDetails();
+ if (default_search_provider_details)
+ input->Set(kDefaultSearchProviderKey, default_search_provider_details);
+
+ base::ListValue* search_providers_details =
+ delegate_->GetPrepopulatedSearchProvidersDetails();
+ if (search_providers_details)
+ input->Set(kSearchProvidersKey, search_providers_details);
+
+ input->SetBoolean(kDefaultSearchProviderIsUserControlledKey,
+ !delegate_->IsDefaultSearchProviderManaged());
+
return input.Pass();
}

Powered by Google App Engine
This is Rietveld 408576698