diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-12 18:07:18 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-12 18:07:18 +0000 |
commit | fd59f820f28a384de8f880237979e7fe28854040 (patch) | |
tree | 73ac1a76e39be8e8788bf533d63c52c64b3c250a | |
parent | a6e02d0b9b0a1e89c990ac937c8ac81bd9bd9946 (diff) | |
download | chromium_src-fd59f820f28a384de8f880237979e7fe28854040.zip chromium_src-fd59f820f28a384de8f880237979e7fe28854040.tar.gz chromium_src-fd59f820f28a384de8f880237979e7fe28854040.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85152 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 | 4 |
4 files changed, 79 insertions, 46 deletions
diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc index 55f3d8c..aa15181 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 702eabb..e0947d1 100644 --- a/chrome/installer/util/google_update_settings.cc +++ b/chrome/installer/util/google_update_settings.cc @@ -48,12 +48,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) { @@ -313,6 +334,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); +} + std::wstring GoogleUpdateSettings::GetChromeChannel(bool system_install) { std::wstring channel; GetChromeChannelInternal(system_install, false, &channel); diff --git a/chrome/installer/util/google_update_settings.h b/chrome/installer/util/google_update_settings.h index f5ee53d..f677a2b 100644 --- a/chrome/installer/util/google_update_settings.h +++ b/chrome/installer/util/google_update_settings.h @@ -86,6 +86,10 @@ 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); + // Returns only the channel name: "" (stable), "dev", "beta", "canary", or // "unknown" if unknown. This value will not be modified by "-m" for a // multi-install. |