summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorcaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 06:46:36 +0000
committercaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 06:46:36 +0000
commit1bee6ed9584ae4b728ba58b46c60c6f3fef9f372 (patch)
tree69a9a115840deb87a8bd1bc1c945e77e167d9980 /chrome
parent0361b94c5041bd426dfaabce29d780129650a80e (diff)
downloadchromium_src-1bee6ed9584ae4b728ba58b46c60c6f3fef9f372.zip
chromium_src-1bee6ed9584ae4b728ba58b46c60c6f3fef9f372.tar.gz
chromium_src-1bee6ed9584ae4b728ba58b46c60c6f3fef9f372.tar.bz2
Chrome CreatedByVersionOrLater feature: Service to determine which version of Chrome a profile was created by.
BUG= TEST= browser_tests --gtest_filter=ProfileBrowserTest.* Review URL: http://codereview.chromium.org/9314017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/prefs/browser_prefs.cc2
-rw-r--r--chrome/browser/profiles/chrome_version_service.cc43
-rw-r--r--chrome/browser/profiles/chrome_version_service.h35
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc5
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h1
-rw-r--r--chrome/browser/profiles/profile.h4
-rw-r--r--chrome/browser/profiles/profile_browsertest.cc21
-rw-r--r--chrome/browser/profiles/profile_impl.cc14
-rw-r--r--chrome/browser/profiles/profile_impl.h2
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/common/pref_names.cc5
-rw-r--r--chrome/common/pref_names.h1
-rw-r--r--chrome/test/base/testing_profile.cc4
-rw-r--r--chrome/test/base/testing_profile.h1
14 files changed, 136 insertions, 4 deletions
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 521474f..535730b 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -40,6 +40,7 @@
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/printing/print_job_manager.h"
+#include "chrome/browser/profiles/chrome_version_service.h"
#include "chrome/browser/profiles/gaia_info_update_service.h"
#include "chrome/browser/profiles/profile_impl.h"
#include "chrome/browser/profiles/profile_info_cache.h"
@@ -176,6 +177,7 @@ void RegisterUserPrefs(PrefService* user_prefs) {
BookmarkModel::RegisterUserPrefs(user_prefs);
Browser::RegisterUserPrefs(user_prefs);
BrowserInit::RegisterUserPrefs(user_prefs);
+ ChromeVersionService::RegisterUserPrefs(user_prefs);
chrome_browser_net::HttpServerPropertiesManager::RegisterPrefs(user_prefs);
chrome_browser_net::Predictor::RegisterUserPrefs(user_prefs);
DevToolsWindow::RegisterUserPrefs(user_prefs);
diff --git a/chrome/browser/profiles/chrome_version_service.cc b/chrome/browser/profiles/chrome_version_service.cc
new file mode 100644
index 0000000..59e27c3
--- /dev/null
+++ b/chrome/browser/profiles/chrome_version_service.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/profiles/chrome_version_service.h"
+
+#include "base/version.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/common/chrome_version_info.h"
+#include "chrome/common/pref_names.h"
+
+// static
+void ChromeVersionService::RegisterUserPrefs(PrefService* prefs) {
+ prefs->RegisterStringPref(prefs::kProfileCreatedByVersion, "1.0.0.0",
+ PrefService::UNSYNCABLE_PREF);
+}
+
+// static
+void ChromeVersionService::SetVersion(PrefService* prefs,
+ const std::string& version) {
+ prefs->SetString(prefs::kProfileCreatedByVersion, version);
+}
+
+// static
+std::string ChromeVersionService::GetVersion(PrefService* prefs) {
+ return prefs->GetString(prefs::kProfileCreatedByVersion);
+}
+
+// static
+void ChromeVersionService::OnProfileLoaded(PrefService* prefs,
+ bool is_new_profile) {
+ // Obtain the Chrome version info.
+ chrome::VersionInfo version_info;
+
+ // If this is a new profile set version to current version, otherwise
+ // (pre-existing profile), leave pref at default value (1.0.0.0) to
+ // avoid any first-run behavior.
+ std::string version = version_info.Version();
+ if (prefs->FindPreference(prefs::kProfileCreatedByVersion)->
+ IsDefaultValue() && is_new_profile) {
+ SetVersion(prefs, version);
+ }
+}
diff --git a/chrome/browser/profiles/chrome_version_service.h b/chrome/browser/profiles/chrome_version_service.h
new file mode 100644
index 0000000..e5ac7b6
--- /dev/null
+++ b/chrome/browser/profiles/chrome_version_service.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PROFILES_CHROME_VERSION_SERVICE_H_
+#define CHROME_BROWSER_PROFILES_CHROME_VERSION_SERVICE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+
+class PrefService;
+
+// This service manages a pref which is used to determine the version of
+// Chrome by which the profile was created.
+class ChromeVersionService {
+ public:
+ // Register the user pref we use.
+ static void RegisterUserPrefs(PrefService* prefs);
+
+ // Sets the version string in the pref for the current profile.
+ static void SetVersion(PrefService* prefs, const std::string& version);
+
+ // Returns the version of Chrome which created the profile.
+ static std::string GetVersion(PrefService* prefs);
+
+ // Handles setting the profile.created_by_version Pref
+ static void OnProfileLoaded(PrefService* prefs, bool is_new_profile);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ChromeVersionService);
+};
+
+#endif // CHROME_BROWSER_PROFILES_CHROME_VERSION_SERVICE_H_
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 96abf40..e8ad129 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -432,6 +432,11 @@ void OffTheRecordProfileImpl::set_last_selected_directory(
last_selected_directory_ = path;
}
+bool OffTheRecordProfileImpl::WasCreatedByVersionOrLater(
+ const std::string& version) {
+ return profile_->WasCreatedByVersionOrLater(version);
+}
+
#if defined(OS_CHROMEOS)
void OffTheRecordProfileImpl::SetupChromeOSEnterpriseExtensionObserver() {
profile_->SetupChromeOSEnterpriseExtensionObserver();
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index 25c4ba7..c194482 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -80,6 +80,7 @@ class OffTheRecordProfileImpl : public Profile,
virtual void InitRegisteredProtocolHandlers() OVERRIDE;
virtual FilePath last_selected_directory() OVERRIDE;
virtual void set_last_selected_directory(const FilePath& path) OVERRIDE;
+ virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
#if defined(OS_CHROMEOS)
virtual void SetupChromeOSEnterpriseExtensionObserver() OVERRIDE;
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 9005672..50f0cc1 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -450,6 +450,10 @@ class Profile : public content::BrowserContext {
// Returns the home page for this profile.
virtual GURL GetHomePage() = 0;
+ // Returns whether or not the profile was created by a version of Chrome
+ // more recent (or equal to) the one specified.
+ virtual bool WasCreatedByVersionOrLater(const std::string& version) = 0;
+
std::string GetDebugName();
// Returns whether it is a guest session.
diff --git a/chrome/browser/profiles/profile_browsertest.cc b/chrome/browser/profiles/profile_browsertest.cc
index 1bf937f..c99bd5f 100644
--- a/chrome/browser/profiles/profile_browsertest.cc
+++ b/chrome/browser/profiles/profile_browsertest.cc
@@ -6,8 +6,11 @@
#include "base/platform_file.h"
#include "base/scoped_temp_dir.h"
+#include "base/version.h"
+#include "chrome/browser/profiles/chrome_version_service.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -31,6 +34,20 @@ void CreatePrefsFileInDirectory(const FilePath& directory_path) {
ASSERT_TRUE(file_util::WriteFile(pref_path, data.c_str(), data.size()));
}
+void CheckChromeVersion(Profile *profile, bool is_new) {
+ std::string created_by_version;
+ if (is_new) {
+ chrome::VersionInfo version_info;
+ created_by_version = version_info.Version();
+ } else {
+ created_by_version = "1.0.0.0";
+ }
+ std::string pref_version =
+ ChromeVersionService::GetVersion(profile->GetPrefs());
+ // Assert that created_by_version pref gets set to current version.
+ EXPECT_EQ(created_by_version, pref_version);
+}
+
} // namespace
typedef InProcessBrowserTest ProfileBrowserTest;
@@ -47,6 +64,7 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileSynchronous) {
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
ASSERT_TRUE(profile.get());
+ CheckChromeVersion(profile.get(), true);
}
// Test OnProfileCreate is called with is_new_profile set to false when
@@ -62,6 +80,7 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileSynchronous) {
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
ASSERT_TRUE(profile.get());
+ CheckChromeVersion(profile.get(), false);
}
// Test OnProfileCreate is called with is_new_profile set to true when
@@ -82,6 +101,7 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileAsynchronous) {
chrome::NOTIFICATION_PROFILE_CREATED,
content::Source<Profile>(profile.get()));
observer.Wait();
+ CheckChromeVersion(profile.get(), true);
}
// Test OnProfileCreate is called with is_new_profile set to false when
@@ -102,4 +122,5 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileAsynchronous) {
chrome::NOTIFICATION_PROFILE_CREATED,
content::Source<Profile>(profile.get()));
observer.Wait();
+ CheckChromeVersion(profile.get(), false);
}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 499999c..e5f7b0b 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -15,6 +15,7 @@
#include "base/string_tokenizer.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "base/version.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/network_action_predictor.h"
#include "chrome/browser/autofill/personal_data_manager.h"
@@ -63,6 +64,7 @@
#include "chrome/browser/prefs/pref_value_store.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
+#include "chrome/browser/profiles/chrome_version_service.h"
#include "chrome/browser/profiles/gaia_info_update_service.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/profiles/profile_info_cache.h"
@@ -86,6 +88,7 @@
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/extension_permission_set.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/common/pref_names.h"
@@ -766,13 +769,16 @@ void ProfileImpl::OnPrefsLoaded(bool success) {
bool is_new_profile = prefs_->GetInitializationStatus() ==
PrefService::INITIALIZATION_STATUS_CREATED_NEW_PROFILE;
- if (is_new_profile) {
- // TODO(caitkp): Set chrome version here.
- }
-
+ ChromeVersionService::OnProfileLoaded(prefs_.get(), is_new_profile);
DoFinalInit(is_new_profile);
}
+bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) {
+ Version profile_version(ChromeVersionService::GetVersion(prefs_.get()));
+ Version arg_version(version);
+ return (profile_version.CompareTo(arg_version) >= 0);
+}
+
PrefService* ProfileImpl::GetPrefs() {
DCHECK(prefs_.get()); // Should explicitly be initialized.
return prefs_.get();
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index 4936866..74c2256 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -123,6 +123,7 @@ class ProfileImpl : public Profile,
virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
virtual void ClearNetworkingHistorySince(base::Time time) OVERRIDE;
virtual GURL GetHomePage() OVERRIDE;
+ virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
#if defined(OS_CHROMEOS)
virtual void ChangeAppLocale(const std::string& locale,
@@ -250,6 +251,7 @@ class ProfileImpl : public Profile,
bool created_web_data_service_;
bool created_password_store_;
bool clear_local_state_on_exit_;
+
// Whether or not the last session exited cleanly. This is set only once.
bool last_session_exited_cleanly_;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 086db4f..3e9d37b 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1769,6 +1769,8 @@
'browser/profiles/avatar_menu_model.cc',
'browser/profiles/avatar_menu_model.h',
'browser/profiles/avatar_menu_model_observer.h',
+ 'browser/profiles/chrome_version_service.cc',
+ 'browser/profiles/chrome_version_service.h',
'browser/profiles/gaia_info_update_service.cc',
'browser/profiles/gaia_info_update_service.h',
'browser/profiles/off_the_record_profile_impl.cc',
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index fe24bb1..c5668a8 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -955,6 +955,11 @@ const char kProfilesLastActive[] = "profile.last_active_profiles";
// directories.
const char kProfilesNumCreated[] = "profile.profiles_created";
+// String containing the version of Chrome that the profile was created by.
+// If profile was created before this feature was added, this pref will default
+// to "1.0.0.0".
+const char kProfileCreatedByVersion[] = "profile.created_by_version";
+
// A map of profile data directory to cached information. This cache can be
// used to display information about profiles without actually having to load
// them.
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 409ba5c..afb38d3 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -363,6 +363,7 @@ extern const char kProfileLastUsed[];
extern const char kProfilesLastActive[];
extern const char kProfilesNumCreated[];
extern const char kProfileInfoCache[];
+extern const char kProfileCreatedByVersion[];
extern const char kProfileMetrics[];
extern const char kProfilePrefix[];
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 77d6827..e522876 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -765,3 +765,7 @@ void TestingProfile::DestroyWebDataService() {
web_data_service_->Shutdown();
}
+
+bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
+ return true;
+}
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index abef630..87275ee 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -247,6 +247,7 @@ class TestingProfile : public Profile {
virtual FilePath last_selected_directory() OVERRIDE;
virtual void set_last_selected_directory(const FilePath& path) OVERRIDE;
+ virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
#if defined(OS_CHROMEOS)
virtual void SetupChromeOSEnterpriseExtensionObserver() OVERRIDE {
}