diff options
author | macourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-17 13:52:43 +0000 |
---|---|---|
committer | macourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-17 13:52:43 +0000 |
commit | 640fbcb08c75b455374db799f3fd4ae277d685a5 (patch) | |
tree | 47a0b71a682e8ee5118afc15b58ef5f07800c739 /chrome/installer/gcapi | |
parent | def2730480a49c306729a5e932cc12d292157fe1 (diff) | |
download | chromium_src-640fbcb08c75b455374db799f3fd4ae277d685a5.zip chromium_src-640fbcb08c75b455374db799f3fd4ae277d685a5.tar.gz chromium_src-640fbcb08c75b455374db799f3fd4ae277d685a5.tar.bz2 |
Adds SetRelaunchOffered.
BUG=266955
R=robertshield@chromium.org
Review URL: https://chromiumcodereview.appspot.com/23011027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218172 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/gcapi')
-rw-r--r-- | chrome/installer/gcapi/gcapi.cc | 73 | ||||
-rw-r--r-- | chrome/installer/gcapi/gcapi.def | 1 | ||||
-rw-r--r-- | chrome/installer/gcapi/gcapi.h | 23 | ||||
-rw-r--r-- | chrome/installer/gcapi/gcapi_omaha_experiment.cc | 19 | ||||
-rw-r--r-- | chrome/installer/gcapi/gcapi_omaha_experiment.h | 11 |
5 files changed, 107 insertions, 20 deletions
diff --git a/chrome/installer/gcapi/gcapi.cc b/chrome/installer/gcapi/gcapi.cc index f7c8794..c5bf760 100644 --- a/chrome/installer/gcapi/gcapi.cc +++ b/chrome/installer/gcapi/gcapi.cc @@ -76,6 +76,9 @@ const wchar_t kC1FSentKey[] = L"Software\\Google\\Common\\Rlz\\StatefulEvents\\C"; const wchar_t kC1FKey[] = L"C1F"; +const wchar_t kRelaunchBrandcodeValue[] = L"RelaunchBrandcode"; +const wchar_t kRelaunchAllowedAfterValue[] = L"RelaunchAllowedAfter"; + // Prefix used to match the window class for Chrome windows. const wchar_t kChromeWindowClassPrefix[] = L"Chrome_WidgetWin_"; @@ -130,6 +133,22 @@ bool GetCompanyName(const wchar_t* filename, wchar_t* buffer, DWORD out_len) { return true; } +// Offsets the current date by |months|. |months| must be between 0 and 12. +// The returned date is in the YYYYMMDD format. +DWORD FormatDateOffsetByMonths(int months) { + DCHECK(months >= 0 && months <= 12); + + SYSTEMTIME now; + GetLocalTime(&now); + now.wMonth += months; + if (now.wMonth > 12) { + now.wMonth -= 12; + now.wYear += 1; + } + + return now.wYear * 10000 + now.wMonth * 100 + now.wDay; +} + // Return true if we can re-offer Chrome; false, otherwise. // Each partner can only offer Chrome once every six months. bool CanReOfferChrome(BOOL set_flag) { @@ -151,9 +170,7 @@ bool CanReOfferChrome(BOOL set_flag) { 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &key, &disposition) == ERROR_SUCCESS) { // Get today's date, and format it as YYYYMMDD numeric value. - SYSTEMTIME now; - GetLocalTime(&now); - DWORD today = now.wYear * 10000 + now.wMonth * 100 + now.wDay; + DWORD today = FormatDateOffsetByMonths(0); // Cannot re-offer, if the timer already exists and is not expired yet. DWORD value_type = REG_DWORD; @@ -172,13 +189,7 @@ bool CanReOfferChrome(BOOL set_flag) { if (set_flag) { // Set expiration date for offer as six months from today, // represented as a YYYYMMDD numeric value. - SYSTEMTIME timer = now; - timer.wMonth = timer.wMonth + 6; - if (timer.wMonth > 12) { - timer.wMonth = timer.wMonth - 12; - timer.wYear = timer.wYear + 1; - } - DWORD value = timer.wYear * 10000 + timer.wMonth * 100 + timer.wDay; + DWORD value = FormatDateOffsetByMonths(6); ::RegSetValueEx(key, company, 0, REG_DWORD, (LPBYTE)&value, sizeof(DWORD)); } @@ -733,9 +744,45 @@ BOOL __stdcall CanOfferRelaunch(const wchar_t** partner_brandcode_list, } // e) a minimum period (6 months) must have passed since the previous - // relaunch offer; - // TODO(macourteau): add this check once |SetRelaunchOffered| has been - // implemented. Return RELAUNCH_ERROR_ALREADY_RELAUNCHED on error. + // relaunch offer for the current user; + RegKey key; + DWORD min_relaunch_date; + if (key.Open(HKEY_CURRENT_USER, kChromeRegClientStateKey, + KEY_QUERY_VALUE) == ERROR_SUCCESS && + key.ReadValueDW(kRelaunchAllowedAfterValue, + &min_relaunch_date) == ERROR_SUCCESS && + FormatDateOffsetByMonths(0) < min_relaunch_date) { + if (error_code) + *error_code = RELAUNCH_ERROR_ALREADY_RELAUNCHED; + return FALSE; + } + + return TRUE; +} + +BOOL __stdcall SetRelaunchOffered(const wchar_t** partner_brandcode_list, + int partner_brandcode_list_length, + const wchar_t* relaunch_brandcode, + int shell_mode, + DWORD* error_code) { + if (!CanOfferRelaunch(partner_brandcode_list, partner_brandcode_list_length, + shell_mode, error_code)) + return FALSE; + + // Store the relaunched brand code and the minimum date for relaunch (6 months + // from now), and set the Omaha experiment label. + RegKey key; + if (key.Create(HKEY_CURRENT_USER, kChromeRegClientStateKey, + KEY_SET_VALUE) != ERROR_SUCCESS || + key.WriteValue(kRelaunchBrandcodeValue, + relaunch_brandcode) != ERROR_SUCCESS || + key.WriteValue(kRelaunchAllowedAfterValue, + FormatDateOffsetByMonths(6)) != ERROR_SUCCESS || + !SetRelaunchExperimentLabels(relaunch_brandcode, shell_mode)) { + if (error_code) + *error_code = RELAUNCH_ERROR_RELAUNCH_FAILED; + return FALSE; + } return TRUE; } diff --git a/chrome/installer/gcapi/gcapi.def b/chrome/installer/gcapi/gcapi.def index f26c826..2270c86 100644 --- a/chrome/installer/gcapi/gcapi.def +++ b/chrome/installer/gcapi/gcapi.def @@ -9,3 +9,4 @@ EXPORTS CanOfferReactivation ReactivateChrome CanOfferRelaunch + SetRelaunchOffered diff --git a/chrome/installer/gcapi/gcapi.h b/chrome/installer/gcapi/gcapi.h index 8a9486b..a35293e 100644 --- a/chrome/installer/gcapi/gcapi.h +++ b/chrome/installer/gcapi/gcapi.h @@ -29,6 +29,7 @@ #define RELAUNCH_ERROR_NOTDORMANT (1 << 3) #define RELAUNCH_ERROR_ALREADY_RELAUNCHED (1 << 4) #define RELAUNCH_ERROR_INVALID_INPUT (1 << 5) +#define RELAUNCH_ERROR_RELAUNCH_FAILED (1 << 6) // Flags to indicate how GCAPI is invoked #define GCAPI_INVOKED_STANDARD_SHELL (1 << 0) @@ -117,7 +118,7 @@ BOOL __stdcall ReactivateChrome(wchar_t* brand_code, DWORD* error_code); // Returns true if a vendor may offer relaunch at this time. Returns false if -// the vendor may not offer reactivation at this time, and places one of the +// the vendor may not offer relaunching at this time, and places one of the // RELAUNCH_ERROR_XXX values in |error_code| if |error_code| is non-null. The // installed brandcode must be in |partner_brandcode_list|. |shell_mode| should // be set to one of GCAPI_INVOKED_STANDARD_SHELL or GCAPI_INVOKED_UAC_ELEVATION @@ -128,6 +129,21 @@ BOOL __stdcall CanOfferRelaunch(const wchar_t** partner_brandcode_list, int shell_mode, DWORD* error_code); +// Returns true if a vendor may relaunch at this time (and stores that a +// relaunch was offered). Returns false if the vendor may not relaunch +// at this time, and places one of the RELAUNCH_ERROR_XXX values in |error_code| +// if |error_code| is non-null. As for |CanOfferRelaunch|, the installed +// brandcode must be in |partner_brandcode_list|. |shell_mode| should be set to +// one of GCAPI_INVOKED_STANDARD_SHELL or GCAPI_INVOKED_UAC_ELEVATION depending +// on whether this method is invoked from an elevated or non-elevated process. +// The |relaunch_brandcode| will be stored as the brandcode that was used for +// offering this relaunch. +BOOL __stdcall SetRelaunchOffered(const wchar_t** partner_brandcode_list, + int partner_brandcode_list_length, + const wchar_t* relaunch_brandcode, + int shell_mode, + DWORD* error_code); + // Function pointer type declarations to use with GetProcAddress. typedef BOOL (__stdcall *GCCC_CompatibilityCheck)(BOOL, int, DWORD *); typedef BOOL (__stdcall *GCCC_LaunchGC)(); @@ -144,6 +160,11 @@ typedef BOOL (__stdcall *GCCC_CanOfferRelaunch)(const wchar_t**, int, int, DWORD*); +typedef BOOL (__stdcall *GCCC_SetRelaunchOffered)(const wchar_t**, + int, + const wchar_t*, + int, + DWORD*); #ifdef __cplusplus } // extern "C" diff --git a/chrome/installer/gcapi/gcapi_omaha_experiment.cc b/chrome/installer/gcapi/gcapi_omaha_experiment.cc index 5314922..ac5899f 100644 --- a/chrome/installer/gcapi/gcapi_omaha_experiment.cc +++ b/chrome/installer/gcapi/gcapi_omaha_experiment.cc @@ -24,10 +24,7 @@ int GetCurrentRlzWeek() { return delta.InDays() / 7; } -} // namespace - -bool SetReactivationExperimentLabels(const wchar_t* brand_code, - int shell_mode) { +bool SetLabel(const wchar_t* brand_code, const wchar_t* label, int shell_mode) { if (!brand_code) { return false; } @@ -38,7 +35,8 @@ bool SetReactivationExperimentLabels(const wchar_t* brand_code, string16 experiment_labels; base::SStringPrintf(&experiment_labels, - L"reacbrand=%ls_%d|%ls", + L"%ls=%ls_%d|%ls", + label, brand_code, week_number, installer::BuildExperimentDateString().c_str()); @@ -47,3 +45,14 @@ bool SetReactivationExperimentLabels(const wchar_t* brand_code, shell_mode == GCAPI_INVOKED_UAC_ELEVATION, experiment_labels); } + +} // namespace + +bool SetReactivationExperimentLabels(const wchar_t* brand_code, + int shell_mode) { + return SetLabel(brand_code, L"reacbrand", shell_mode); +} + +bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { + return SetLabel(brand_code, L"relaunchbrand", shell_mode); +} diff --git a/chrome/installer/gcapi/gcapi_omaha_experiment.h b/chrome/installer/gcapi/gcapi_omaha_experiment.h index 4d4be8a..babe41e 100644 --- a/chrome/installer/gcapi/gcapi_omaha_experiment.h +++ b/chrome/installer/gcapi/gcapi_omaha_experiment.h @@ -9,7 +9,16 @@ // binaries registry keys for |brand_code|. This experiment label will have a // expiration date of now plus one year. If |shell_mode| is set to // GCAPI_INVOKED_UAC_ELEVATION, the value will be written to HKLM, otherwise -// HKCU. +// HKCU. A user cannot have both a reactivation label and a relaunch label set +// at the same time (they are mutually exclusive). bool SetReactivationExperimentLabels(const wchar_t* brand_code, int shell_mode); +// Writes a relaunch brand code experiment label in the Chrome product and +// binaries registry keys for |brand_code|. This experiment label will have a +// expiration date of now plus one year. If |shell_mode| is set to +// GCAPI_INVOKED_UAC_ELEVATION, the value will be written to HKLM, otherwise +// HKCU. A user cannot have both a reactivation label and a relaunch label set +// at the same time (they are mutually exclusive). +bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode); + #endif // CHROME_INSTALLER_GCAPI_GCAPI_OMAHA_EXPERIMENT_H_ |