diff options
-rw-r--r-- | chrome/browser/google_update_settings_unittest.cc (renamed from chrome/browser/google_update_settings_posix_unittest.cc) | 16 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 2 | ||||
-rw-r--r-- | chrome/installer/util/google_update_constants.cc | 1 | ||||
-rw-r--r-- | chrome/installer/util/google_update_constants.h | 4 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings.cc | 33 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings.h | 15 |
6 files changed, 68 insertions, 3 deletions
diff --git a/chrome/browser/google_update_settings_posix_unittest.cc b/chrome/browser/google_update_settings_unittest.cc index 35f956a..8dc56bb 100644 --- a/chrome/browser/google_update_settings_posix_unittest.cc +++ b/chrome/browser/google_update_settings_unittest.cc @@ -12,12 +12,24 @@ class GoogleUpdateTest : public PlatformTest { TEST_F(GoogleUpdateTest, StatsConstent) { // Stats are off by default. EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent()); - // Stats reporting is ON. EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(true)); EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsent()); - // Stats reporting is OFF. EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(false)); EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent()); } + +#if defined(OS_WIN) + +TEST_F(GoogleUpdateTest, LastRunTime) { + // Querying the value that does not exists should fail. + EXPECT_TRUE(GoogleUpdateSettings::RemoveLastRunTime()); + EXPECT_EQ(-1, GoogleUpdateSettings::GetLastRunTime()); + // Setting and querying the last update time in fast sequence + // should give 0 days. + EXPECT_TRUE(GoogleUpdateSettings::SetLastRunTime()); + EXPECT_EQ(0, GoogleUpdateSettings::GetLastRunTime()); +} + +#endif // defined(OS_WIN) diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index bfa48df..178d5f9 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -689,7 +689,7 @@ 'browser/find_backend_unittest.cc', 'browser/global_keyboard_shortcuts_mac_unittest.mm', 'browser/google_url_tracker_unittest.cc', - 'browser/google_update_settings_posix_unittest.cc', + 'browser/google_update_settings_unittest.cc', 'browser/gtk/bookmark_bar_gtk_unittest.cc', 'browser/gtk/bookmark_editor_gtk_unittest.cc', 'browser/gtk/gtk_expanded_container_unittest.cc', diff --git a/chrome/installer/util/google_update_constants.cc b/chrome/installer/util/google_update_constants.cc index 90d6592..5455aff 100644 --- a/chrome/installer/util/google_update_constants.cc +++ b/chrome/installer/util/google_update_constants.cc @@ -30,4 +30,5 @@ const wchar_t kRegVersionField[] = L"pv"; const wchar_t kRegReferralField[] = L"referral"; const wchar_t kRegEULAAceptedField[] = L"eulaaccepted"; const wchar_t kEnvProductVersionKey[] = L"CHROME_VERSION"; +const wchar_t kRegLastRunTimeField[] = L"lastrun"; } // namespace installer diff --git a/chrome/installer/util/google_update_constants.h b/chrome/installer/util/google_update_constants.h index 6d40d7a..45d3996 100644 --- a/chrome/installer/util/google_update_constants.h +++ b/chrome/installer/util/google_update_constants.h @@ -41,6 +41,10 @@ extern const wchar_t kRegReferralField[]; extern const wchar_t kRegEULAAceptedField[]; extern const wchar_t kEnvProductVersionKey[]; + +// last time that chrome ran in the Time internal format. +extern const wchar_t kRegLastRunTimeField[]; + } // namespace google_update #endif // CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_CONSTANTS_H_ diff --git a/chrome/installer/util/google_update_settings.cc b/chrome/installer/util/google_update_settings.cc index 3d3688b..a5298e5 100644 --- a/chrome/installer/util/google_update_settings.cc +++ b/chrome/installer/util/google_update_settings.cc @@ -5,6 +5,8 @@ #include "chrome/installer/util/google_update_settings.h" #include "base/registry.h" +#include "base/string_util.h" +#include "base/time.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_constants.h" @@ -39,6 +41,15 @@ bool ClearGoogleUpdateStrKey(const wchar_t* const name) { return key.WriteValue(name, L""); } +bool RemoveGoogleUpdateStrKey(const wchar_t* const name) { + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); + std::wstring reg_path = dist->GetStateKey(); + RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); + if (!key.ValueExists(name)) + return true; + return key.DeleteValue(name); +} + } // namespace. bool GoogleUpdateSettings::GetCollectStatsConsent() { @@ -82,6 +93,28 @@ bool GoogleUpdateSettings::SetEULAConsent(bool consented) { return key.WriteValue(google_update::kRegEULAAceptedField, consented? 1 : 0); } +int GoogleUpdateSettings::GetLastRunTime() { + std::wstring time_s; + if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s)) + return -1; + int64 time_i; + if (!StringToInt64(time_s, &time_i)) + return -1; + base::TimeDelta td = + base::Time::NowFromSystemTime() - base::Time::FromInternalValue(time_i); + return td.InDays(); +} + +bool GoogleUpdateSettings::SetLastRunTime() { + int64 time = base::Time::NowFromSystemTime().ToInternalValue(); + return WriteGoogleUpdateStrKey(google_update::kRegLastRunTimeField, + Int64ToWString(time)); +} + +bool GoogleUpdateSettings::RemoveLastRunTime() { + return RemoveGoogleUpdateStrKey(google_update::kRegLastRunTimeField); +} + bool GoogleUpdateSettings::GetBrowser(std::wstring* browser) { return ReadGoogleUpdateStrKey(google_update::kRegBrowserField, browser); } diff --git a/chrome/installer/util/google_update_settings.h b/chrome/installer/util/google_update_settings.h index bdc1292..06adb44 100644 --- a/chrome/installer/util/google_update_settings.h +++ b/chrome/installer/util/google_update_settings.h @@ -34,6 +34,21 @@ class GoogleUpdateSettings { // Returns false if the setting could not be recorded. static bool SetEULAConsent(bool consented); + // Returns the last time chrome was run in days. It uses a recorded value + // set by SetLastRunTime(). Returns -1 if the value was not found or if + // the value is corrupted. + static int GetLastRunTime(); + + // Stores the time that this function was last called using an encoded + // form of the system local time. Retrieve the time using GetLastRunTime(). + // Returns false if the value could not be stored. + static bool SetLastRunTime(); + + // Removes the storage used by SetLastRunTime() and SetLastRunTime(). Returns + // false if the operation failed. Returns true if the storage was freed or + // if it never existed in the first place. + static bool RemoveLastRunTime(); + // Returns in |browser| the browser used to download chrome as recorded // Google Update. Returns false if the information is not available. static bool GetBrowser(std::wstring* browser); |