diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 01:01:17 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 01:01:17 +0000 |
commit | 1deb29602c85e556e65f105ad11202d13516627a (patch) | |
tree | dcffa3364e3d05367d59a7e4d617043becd99f27 | |
parent | 68ff316af705178725f10e4a80d0d111d6e43da5 (diff) | |
download | chromium_src-1deb29602c85e556e65f105ad11202d13516627a.zip chromium_src-1deb29602c85e556e65f105ad11202d13516627a.tar.gz chromium_src-1deb29602c85e556e65f105ad11202d13516627a.tar.bz2 |
Merge 85152 - Change the writting to the 'did run' registry to better account actives
Now we not just call it from chrome.exe (chrome/app) but it
is also called periodically from chrome.dll itself
BUG=82180
TEST=see bug
Review URL: http://codereview.chromium.org/7005008
TBR=cpu@chromium.org
Review URL: http://codereview.chromium.org/7015035
git-svn-id: svn://svn.chromium.org/chrome/branches/742/src@85232 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/client_util.cc | 47 | ||||
-rw-r--r-- | chrome/browser/browser_main_win.cc | 40 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings.cc | 34 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings.h | 5 |
4 files changed, 80 insertions, 46 deletions
diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc index 63040c7..e60ec1c 100644 --- a/chrome/app/client_util.cc +++ b/chrome/app/client_util.cc @@ -23,6 +23,7 @@ #include "chrome/installer/util/channel_info.h" #include "chrome/installer/util/install_util.h" #include "chrome/installer/util/google_update_constants.h" +#include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/util_constants.h" #include "content/common/result_codes.h" @@ -141,56 +142,16 @@ HMODULE LoadChromeWithDirectory(std::wstring* dir) { LOAD_WITH_ALTERED_SEARCH_PATH); } -// Set did_run "dr" to |value| in Google Update's client state key for the -// product associated with |dist|, creating the client state key if necessary. -bool SetDidRunState(BrowserDistribution* dist, const wchar_t* value) { - DCHECK(dist); - DCHECK(value); - bool wrote_dr = false; - std::wstring product_key_path(dist->GetStateKey()); - base::win::RegKey reg_key; - if (reg_key.Create(HKEY_CURRENT_USER, product_key_path.c_str(), - KEY_SET_VALUE) == ERROR_SUCCESS) { - if (reg_key.WriteValue(google_update::kRegDidRunField, - value) == ERROR_SUCCESS) { - wrote_dr = true; - } - } - return wrote_dr; -} - - void RecordDidRun(const std::wstring& dll_path) { - static const wchar_t kSet[] = L"1"; - BrowserDistribution* product_dist = BrowserDistribution::GetDistribution(); - SetDidRunState(product_dist, kSet); - - // If this is a multi-install, also write the did_run value under the - // multi key. bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str()); - if (InstallUtil::IsMultiInstall(product_dist, system_level)) { - BrowserDistribution* multi_dist = - BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BINARIES); - SetDidRunState(multi_dist, kSet); - } + GoogleUpdateSettings::UpdateDidRunState(true, system_level); } void ClearDidRun(const std::wstring& dll_path) { - static const wchar_t kCleared[] = L"0"; - BrowserDistribution* product_dist = BrowserDistribution::GetDistribution(); - SetDidRunState(product_dist, kCleared); - - // If this is a multi-install, also clear the did_run value under the - // multi key. bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str()); - if (InstallUtil::IsMultiInstall(product_dist, system_level)) { - BrowserDistribution* multi_dist = - BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BINARIES); - SetDidRunState(multi_dist, kCleared); - } + GoogleUpdateSettings::UpdateDidRunState(false, system_level); } + } //============================================================================= diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc index ef1ceba..6ecea52 100644 --- a/chrome/browser/browser_main_win.cc +++ b/chrome/browser/browser_main_win.cc @@ -16,6 +16,7 @@ #include "base/memory/scoped_native_library.h" #include "base/memory/scoped_ptr.h" #include "base/path_service.h" +#include "base/time.h" #include "base/utf_string_conversions.h" #include "base/win/windows_version.h" #include "base/win/wrapped_window_proc.h" @@ -29,6 +30,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/env_vars.h" #include "chrome/installer/util/browser_distribution.h" +#include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/helper.h" #include "chrome/installer/util/install_util.h" #include "chrome/installer/util/shell_util.h" @@ -61,6 +63,37 @@ void InitializeWindowProcExceptions() { DCHECK(!exception_filter); } +// BrowserUsageUpdater -------------------------------------------------------- +// This class' job is to update the registry 'dr' value every 24 hours +// that way google update can accurately track browser usage without +// undercounting users that do not close chrome for long periods of time. +class BrowserUsageUpdater : public Task { + public: + virtual ~BrowserUsageUpdater() {} + + virtual void Run() OVERRIDE { + if (UpdateUsageRegKey()) + Track(); + } + + static void Track() { + BrowserThread::PostDelayedTask( + BrowserThread::FILE, + FROM_HERE, new BrowserUsageUpdater, + base::TimeDelta::FromHours(24).InMillisecondsRoundedUp()); + } + + private: + bool UpdateUsageRegKey() { + FilePath module_dir; + if (!PathService::Get(base::DIR_MODULE, &module_dir)) + return false; + bool system_level = + !InstallUtil::IsPerUserInstall(module_dir.value().c_str()); + return GoogleUpdateSettings::UpdateDidRunState(true, system_level); + } +}; + } // namespace void DidEndMainMessageLoop() { @@ -301,6 +334,13 @@ class BrowserMainPartsWin : public BrowserMainParts { } } + virtual void PostMainMessageLoopStart() OVERRIDE { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + NewRunnableFunction(&BrowserUsageUpdater::Track), + base::TimeDelta::FromSeconds(30).InMillisecondsRoundedUp()); + } + private: virtual void InitializeSSL() { // Use NSS for SSL by default. diff --git a/chrome/installer/util/google_update_settings.cc b/chrome/installer/util/google_update_settings.cc index 49d80ec..a2fc5ab 100644 --- a/chrome/installer/util/google_update_settings.cc +++ b/chrome/installer/util/google_update_settings.cc @@ -47,12 +47,33 @@ bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { return true; } +bool WriteGoogleUpdateStrKeyInternal(BrowserDistribution* dist, + const wchar_t* const name, + const std::wstring& value) { + DCHECK(dist); + std::wstring reg_path(dist->GetStateKey()); + RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE); + return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); +} + bool WriteGoogleUpdateStrKey(const wchar_t* const name, const std::wstring& value) { BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - std::wstring reg_path = dist->GetStateKey(); - RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); - return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); + return WriteGoogleUpdateStrKeyInternal(dist, name, value); +} + +bool WriteGoogleUpdateStrKeyMultiInstall(const wchar_t* const name, + const std::wstring& value, + bool system_level) { + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); + bool result = WriteGoogleUpdateStrKeyInternal(dist, name, value); + if (!InstallUtil::IsMultiInstall(dist, system_level)) + return result; + // It is a multi-install distro. Must write the reg value again. + BrowserDistribution* multi_dist = + BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_BINARIES); + return WriteGoogleUpdateStrKeyInternal(multi_dist, name, value) && result; } bool ClearGoogleUpdateStrKey(const wchar_t* const name) { @@ -220,6 +241,13 @@ bool GoogleUpdateSettings::ClearReferral() { return ClearGoogleUpdateStrKey(google_update::kRegReferralField); } +bool GoogleUpdateSettings::UpdateDidRunState(bool did_run, + bool system_level) { + return WriteGoogleUpdateStrKeyMultiInstall(google_update::kRegDidRunField, + did_run ? L"1" : L"0", + system_level); +} + bool GoogleUpdateSettings::GetChromeChannel(bool system_install, std::wstring* channel) { BrowserDistribution* dist = BrowserDistribution::GetDistribution(); diff --git a/chrome/installer/util/google_update_settings.h b/chrome/installer/util/google_update_settings.h index 002a532..6085d4d 100644 --- a/chrome/installer/util/google_update_settings.h +++ b/chrome/installer/util/google_update_settings.h @@ -86,6 +86,11 @@ class GoogleUpdateSettings { // true if this operation succeeded. static bool ClearReferral(); + // Set did_run "dr" in the client state value. This is used to measure + // active users. Returns false if writting to the registry failed. + static bool UpdateDidRunState(bool did_run, bool system_level); + + // Return a human readable modifier for the version string, e.g. // the channel (dev, beta, stable). Returns true if this operation succeeded, // on success, channel contains one of "", "unknown", "dev" or "beta" (unless |