summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-26 02:25:15 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-26 02:25:15 +0000
commitf3ca90933fa31ae47572933743391a41bedc9d88 (patch)
tree482fb9a0fd6c668f19a8ec0852ff12a4358c748d
parenta081ddf4494f3b5d607e3152f88c60b44f3a7005 (diff)
downloadchromium_src-f3ca90933fa31ae47572933743391a41bedc9d88.zip
chromium_src-f3ca90933fa31ae47572933743391a41bedc9d88.tar.gz
chromium_src-f3ca90933fa31ae47572933743391a41bedc9d88.tar.bz2
cros: Exclude user has synced app pins from default pin trial.
- Add helper methods to PrefServiceSyncable to figure out whether a pref is pulled from sync; - Use the helper to exclude users that has synced app pins from trial; BUG=234415 Review URL: https://chromiumcodereview.appspot.com/15911003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202332 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/default_pinned_apps_field_trial.cc32
-rw-r--r--chrome/browser/prefs/pref_model_associator.cc4
-rw-r--r--chrome/browser/prefs/pref_model_associator.h4
-rw-r--r--chrome/browser/prefs/pref_service_syncable.cc6
-rw-r--r--chrome/browser/prefs/pref_service_syncable.h4
5 files changed, 49 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/login/default_pinned_apps_field_trial.cc b/chrome/browser/chromeos/login/default_pinned_apps_field_trial.cc
index f963ac9..c75234a 100644
--- a/chrome/browser/chromeos/login/default_pinned_apps_field_trial.cc
+++ b/chrome/browser/chromeos/login/default_pinned_apps_field_trial.cc
@@ -13,10 +13,15 @@
#include "base/prefs/pref_service.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/pref_names.h"
namespace chromeos {
namespace default_pinned_apps_field_trial {
@@ -56,6 +61,12 @@ void AddUserToExperiment(const std::string& username) {
users->AppendString(username);
}
+// Removes user from the experiment user list.
+void RemoveUserFromExperiment(const std::string& username) {
+ ListPrefUpdate users(g_browser_process->local_state(), kExperimentUsers);
+ users->Remove(base::StringValue(username), NULL);
+}
+
// Gets click target type for given app id. Returns false if the app id is
// not interesting.
bool GetClickTargetForApp(const std::string& app_id,
@@ -88,6 +99,24 @@ bool GetClickTargetForApp(const std::string& app_id,
return false;
}
+// Check if the current user has default pinned apps pulled from sync. If that
+// is the case, kick the user out of the trial and returns true.
+bool ProcessIfUserHasSyncedAppPins() {
+ static bool has_synced_pref = false;
+ if (has_synced_pref)
+ return true;
+
+ Profile* user_profile = ProfileManager::GetDefaultProfile();
+ has_synced_pref = PrefServiceSyncable::FromProfile(user_profile)
+ ->IsPrefSynced(prefs::kPinnedLauncherApps);
+ if (has_synced_pref) {
+ const std::string username = UserManager::Get()->GetActiveUser()->email();
+ RemoveUserFromExperiment(username);
+ }
+
+ return has_synced_pref;
+}
+
} // namespace
void RegisterPrefs(PrefRegistrySimple* registry) {
@@ -155,6 +184,9 @@ void RecordShelfClick(ClickTarget click_target) {
if (!trial_configured)
return;
+ if (ProcessIfUserHasSyncedAppPins())
+ return;
+
UMA_HISTOGRAM_ENUMERATION("Cros.ClickOnShelf",
click_target,
CLICK_TARGET_COUNT);
diff --git a/chrome/browser/prefs/pref_model_associator.cc b/chrome/browser/prefs/pref_model_associator.cc
index d908304..d0a854a 100644
--- a/chrome/browser/prefs/pref_model_associator.cc
+++ b/chrome/browser/prefs/pref_model_associator.cc
@@ -417,6 +417,10 @@ Value* PrefModelAssociator::ReadPreferenceSpecifics(
return value.release();
}
+bool PrefModelAssociator::IsPrefSynced(const std::string& name) const {
+ return synced_preferences_.find(name) != synced_preferences_.end();
+}
+
std::set<std::string> PrefModelAssociator::registered_preferences() const {
return registered_preferences_;
}
diff --git a/chrome/browser/prefs/pref_model_associator.h b/chrome/browser/prefs/pref_model_associator.h
index 2bfe0cd..584e271 100644
--- a/chrome/browser/prefs/pref_model_associator.h
+++ b/chrome/browser/prefs/pref_model_associator.h
@@ -93,6 +93,10 @@ class PrefModelAssociator
const sync_pb::PreferenceSpecifics& specifics,
std::string* name);
+ // Returns true if the pref under the given name is pulled down from sync.
+ // Note this does not refer to SYNCABLE_PREF.
+ bool IsPrefSynced(const std::string& name) const;
+
protected:
friend class ProfileSyncServicePreferenceTest;
diff --git a/chrome/browser/prefs/pref_service_syncable.cc b/chrome/browser/prefs/pref_service_syncable.cc
index defd644..2ab7ff5 100644
--- a/chrome/browser/prefs/pref_service_syncable.cc
+++ b/chrome/browser/prefs/pref_service_syncable.cc
@@ -110,11 +110,15 @@ bool PrefServiceSyncable::IsSyncing() {
return pref_sync_associator_.models_associated();
}
-
bool PrefServiceSyncable::IsPrioritySyncing() {
return priority_pref_sync_associator_.models_associated();
}
+bool PrefServiceSyncable::IsPrefSynced(const std::string& name) const {
+ return pref_sync_associator_.IsPrefSynced(name) ||
+ priority_pref_sync_associator_.IsPrefSynced(name);
+}
+
void PrefServiceSyncable::AddObserver(PrefServiceSyncableObserver* observer) {
observer_list_.AddObserver(observer);
}
diff --git a/chrome/browser/prefs/pref_service_syncable.h b/chrome/browser/prefs/pref_service_syncable.h
index e1c7d23..4f4715e 100644
--- a/chrome/browser/prefs/pref_service_syncable.h
+++ b/chrome/browser/prefs/pref_service_syncable.h
@@ -66,6 +66,10 @@ class PrefServiceSyncable : public PrefService {
// priority preferences.
bool IsPrioritySyncing();
+ // Returns true if the pref under the given name is pulled down from sync.
+ // Note this does not refer to SYNCABLE_PREF.
+ bool IsPrefSynced(const std::string& name) const;
+
void AddObserver(PrefServiceSyncableObserver* observer);
void RemoveObserver(PrefServiceSyncableObserver* observer);