summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-20 23:14:03 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-20 23:14:03 +0000
commit1870f1b472aadfe78b1b9db0166ec4ab1a4f8e4a (patch)
tree0c296b77295408a57a323619d3ffa264c555cf3d /chrome/installer
parentc065fa073f614eafdc3af5a69374ef9510ca3259 (diff)
downloadchromium_src-1870f1b472aadfe78b1b9db0166ec4ab1a4f8e4a.zip
chromium_src-1870f1b472aadfe78b1b9db0166ec4ab1a4f8e4a.tar.gz
chromium_src-1870f1b472aadfe78b1b9db0166ec4ab1a4f8e4a.tar.bz2
Adds a way to record the last run time in the GoogleUpdateSettings class
- to be used as a way to know how long ago chrome was started - windows only - enabled unit tests for GoogleUpdateSettings for windows. BUG=none TEST=unit test included Review URL: http://codereview.chromium.org/554017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/util/google_update_constants.cc1
-rw-r--r--chrome/installer/util/google_update_constants.h4
-rw-r--r--chrome/installer/util/google_update_settings.cc33
-rw-r--r--chrome/installer/util/google_update_settings.h15
4 files changed, 53 insertions, 0 deletions
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);