Commit b0eebb40 authored by thestig@chromium.org's avatar thestig@chromium.org

Revert 119841 - Implementation of GCAPI reactivation.

Also, some cleanup in gcapi_tests such that it now only runs gtest tests by default.

BUG=111453
TEST=gcapi_tests.exe

Review URL: https://chromiumcodereview.appspot.com/9288056

TBR=robertshield@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9302029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119865 0039d316-1c4b-4281-b951-d872f2087c98
parent a2054849
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
'target_name': 'gcapi_dll', 'target_name': 'gcapi_dll',
'type': 'loadable_module', 'type': 'loadable_module',
'dependencies': [ 'dependencies': [
'gcapi_lib',
'installer_util', 'installer_util',
'<(DEPTH)/base/base.gyp:base', '<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/google_update/google_update.gyp:google_update', '<(DEPTH)/google_update/google_update.gyp:google_update',
...@@ -23,7 +22,9 @@ ...@@ -23,7 +22,9 @@
'<(DEPTH)', '<(DEPTH)',
], ],
'sources': [ 'sources': [
'installer/gcapi/gcapi.cc',
'installer/gcapi/gcapi.def', 'installer/gcapi/gcapi.def',
'installer/gcapi/gcapi.h',
], ],
}, },
{ {
...@@ -40,8 +41,6 @@ ...@@ -40,8 +41,6 @@
'sources': [ 'sources': [
'installer/gcapi/gcapi.cc', 'installer/gcapi/gcapi.cc',
'installer/gcapi/gcapi.h', 'installer/gcapi/gcapi.h',
'installer/gcapi/gcapi_reactivation.cc',
'installer/gcapi/gcapi_reactivation.h',
], ],
}, },
{ {
...@@ -61,7 +60,6 @@ ...@@ -61,7 +60,6 @@
], ],
'sources': [ 'sources': [
'installer/gcapi/gcapi_last_run_test.cc', 'installer/gcapi/gcapi_last_run_test.cc',
'installer/gcapi/gcapi_reactivation_test.cc',
'installer/gcapi/gcapi_test.cc', 'installer/gcapi/gcapi_test.cc',
'installer/gcapi/gcapi_test.rc', 'installer/gcapi/gcapi_test.rc',
'installer/gcapi/resource.h', 'installer/gcapi/resource.h',
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "base/win/scoped_com_initializer.h" #include "base/win/scoped_com_initializer.h"
#include "base/win/scoped_comptr.h" #include "base/win/scoped_comptr.h"
#include "base/win/scoped_handle.h" #include "base/win/scoped_handle.h"
#include "chrome/installer/gcapi/gcapi_reactivation.h"
#include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/util_constants.h" #include "chrome/installer/util/util_constants.h"
...@@ -540,74 +539,3 @@ int __stdcall GoogleChromeDaysSinceLastRun() { ...@@ -540,74 +539,3 @@ int __stdcall GoogleChromeDaysSinceLastRun() {
return days_since_last_run; return days_since_last_run;
} }
BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code,
int previous_brand_codes_length,
const wchar_t** previous_brand_codes,
DWORD* error_code) {
DCHECK(error_code);
if (!brand_code ||
(previous_brand_codes_length > 0 && previous_brand_codes == NULL)) {
if (error_code)
*error_code = REACTIVATE_ERROR_INVALID_INPUT;
return FALSE;
}
bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE);
bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER);
if (!has_system_install && !has_user_install) {
if (error_code)
*error_code = REACTIVATE_ERROR_NOTINSTALLED;
return FALSE;
}
int days_since_last_run = GoogleChromeDaysSinceLastRun();
if (days_since_last_run > 0 &&
days_since_last_run < kReactivationMinDaysDormant) {
if (error_code)
*error_code = REACTIVATE_ERROR_NOTDORMANT;
return FALSE;
}
// Make sure we haven't previously been reactivated by this brand code
// or any of the previous brand codes from this partner.
std::vector<std::wstring> reactivation_brands;
reactivation_brands.push_back(brand_code);
if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) {
std::copy(previous_brand_codes,
previous_brand_codes + previous_brand_codes_length,
std::back_inserter(reactivation_brands));
}
if (HasBeenReactivatedByBrandCodes(reactivation_brands)) {
if (error_code)
*error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED;
return FALSE;
}
return TRUE;
}
BOOL __stdcall ReactivateChrome(wchar_t* brand_code,
int previous_brand_codes_length,
const wchar_t** previous_brand_codes,
DWORD* error_code) {
BOOL result = FALSE;
if (CanOfferReactivation(brand_code,
previous_brand_codes_length,
previous_brand_codes,
error_code)) {
if (SetReactivationBrandCode(brand_code)) {
// TODO(robertshield): Set Omaha reg key to add experiment label for
// tracking 7DA.
result = TRUE;
} else {
if (error_code)
*error_code = REACTIVATE_ERROR_REACTIVATION_FAILED;
}
}
return result;
}
...@@ -9,5 +9,3 @@ EXPORTS ...@@ -9,5 +9,3 @@ EXPORTS
LaunchGoogleChrome PRIVATE LaunchGoogleChrome PRIVATE
LaunchGoogleChromeWithDimensions @16 PRIVATE LaunchGoogleChromeWithDimensions @16 PRIVATE
GoogleChromeDaysSinceLastRun PRIVATE GoogleChromeDaysSinceLastRun PRIVATE
CanOfferReactivation PRIVATE
ReactivateChrome PRIVATE
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -17,17 +17,6 @@ extern "C" { ...@@ -17,17 +17,6 @@ extern "C" {
#define GCCC_ERROR_ALREADYOFFERED 0x10 #define GCCC_ERROR_ALREADYOFFERED 0x10
#define GCCC_ERROR_INTEGRITYLEVEL 0x20 #define GCCC_ERROR_INTEGRITYLEVEL 0x20
// Error conditions for CanReactivateChrome().
#define REACTIVATE_ERROR_NOTINSTALLED 0x01
#define REACTIVATE_ERROR_NOTDORMANT 0x02
#define REACTIVATE_ERROR_ALREADY_REACTIVATED 0x04
#define REACTIVATE_ERROR_INVALID_INPUT 0x08
#define REACTIVATE_ERROR_REACTIVATION_FAILED 0x10
// The minimum number of days an installation can be dormant before reactivation
// may be offered.
const int kReactivationMinDaysDormant = 50;
// This function returns TRUE if Google Chrome should be offered. // This function returns TRUE if Google Chrome should be offered.
// If the return is FALSE, the reasons DWORD explains why. If you don't care // If the return is FALSE, the reasons DWORD explains why. If you don't care
// for the reason, you can pass NULL for reasons. // for the reason, you can pass NULL for reasons.
...@@ -65,41 +54,11 @@ BOOL __stdcall LaunchGoogleChromeWithDimensions(int x, ...@@ -65,41 +54,11 @@ BOOL __stdcall LaunchGoogleChromeWithDimensions(int x,
// launched. // launched.
int __stdcall GoogleChromeDaysSinceLastRun(); int __stdcall GoogleChromeDaysSinceLastRun();
// Returns true if a vendor with the specified |brand_code| may offer // Funtion pointer type declarations to use with GetProcAddress.
// reactivation at this time. If the vendor has previously used other brand
// codes, they must pass them in an array of size |previous_brand_codes_length|
// as |previous_brand_codes|. Returns false if the vendor may not offer
// reactivation at this time, and places one of the REACTIVATE_ERROR_XXX values
// in |error_code| if |error_code| is non-null.
BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code,
int previous_brand_codes_length,
const wchar_t** previous_brand_codes,
DWORD* error_code);
// Attempts to reactivate Chrome for the specified |brand_code|. If the vendor
// has previously used other brand codes, they must pass them in an array of
// size |previous_brand_codes_length| as |previous_brand_codes|. Returns false
// if reactivation fails, and places one of the REACTIVATE_ERROR_XXX values
// in |error_code| if |error_code| is non-null.
BOOL __stdcall ReactivateChrome(wchar_t* brand_code,
int previous_brand_codes_length,
const wchar_t** previous_brand_codes,
DWORD* error_code);
// Function pointer type declarations to use with GetProcAddress.
typedef BOOL (__stdcall *GCCC_CompatibilityCheck)(BOOL, DWORD *); typedef BOOL (__stdcall *GCCC_CompatibilityCheck)(BOOL, DWORD *);
typedef BOOL (__stdcall *GCCC_LaunchGC)(HANDLE *); typedef BOOL (__stdcall *GCCC_LaunchGC)(HANDLE *);
typedef BOOL (__stdcall *GCCC_LaunchGCWithDimensions)(int, int, int, int); typedef BOOL (__stdcall *GCCC_LaunchGCWithDimensions)(int, int, int, int);
typedef int (__stdcall *GCCC_GoogleChromeDaysSinceLastRun)(); typedef int (__stdcall *GCCC_GoogleChromeDaysSinceLastRun)();
typedef BOOL (__stdcall *GCCC_CanOfferReactivation)(const wchar_t*,
int,
const wchar_t**,
DWORD*);
typedef BOOL (__stdcall *GCCC_ReactivateChrome)(const wchar_t*,
int,
const wchar_t**,
DWORD*);
} // extern "C" } // extern "C"
#endif // CHROME_INSTALLER_GCAPI_GCAPI_H_ #endif // CHROME_INSTALLER_GCAPI_GCAPI_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/installer/gcapi/gcapi_reactivation.h"
#include "base/time.h"
#include "base/win/registry.h"
#include "chrome/installer/util/google_update_constants.h"
using base::Time;
using base::win::RegKey;
namespace {
const wchar_t kReactivationHistoryKey[] = L"reactivation";
std::wstring GetReactivationHistoryKeyPath() {
std::wstring reactivation_path(google_update::kRegPathClientState);
reactivation_path += L"\\";
reactivation_path += google_update::kChromeUpgradeCode;
reactivation_path += L"\\";
reactivation_path += kReactivationHistoryKey;
return reactivation_path;
}
} // namespace
bool HasBeenReactivatedByBrandCodes(
const std::vector<std::wstring>& brand_codes) {
bool success = false;
RegKey reactivation_key(HKEY_CURRENT_USER,
GetReactivationHistoryKeyPath().c_str(),
KEY_QUERY_VALUE);
if (reactivation_key.Valid()) {
std::vector<std::wstring>::const_iterator brand_iter(brand_codes.begin());
for (; brand_iter != brand_codes.end(); ++brand_iter) {
if (reactivation_key.HasValue(brand_iter->c_str())) {
success = true;
break;
}
}
}
return success;
}
bool SetReactivationBrandCode(const std::wstring& brand_code) {
bool success = false;
std::wstring path(google_update::kRegPathClientState);
path += L"\\";
path += google_update::kChromeUpgradeCode;
RegKey client_state_key(HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE);
if (client_state_key.Valid()) {
success = client_state_key.WriteValue(
google_update::kRegRLZReactivationBrandField,
brand_code.c_str()) == ERROR_SUCCESS;
}
if (success) {
// Store this brand code in the reactivation history. Store it with a
// a currently un-used timestamp for future proofing.
RegKey reactivation_key(HKEY_CURRENT_USER,
GetReactivationHistoryKeyPath().c_str(),
KEY_WRITE);
if (reactivation_key.Valid()) {
int64 timestamp = Time::Now().ToInternalValue();
reactivation_key.WriteValue(brand_code.c_str(),
&timestamp,
sizeof(timestamp),
REG_QWORD);
}
}
return success;
}
\ No newline at end of file
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_INSTALLER_GCAPI_GCAPI_REACTIVATION_H_
#define CHROME_INSTALLER_GCAPI_GCAPI_REACTIVATION_H_
#pragma once
#include <windows.h>
#include <string>
#include <vector>
bool HasBeenReactivatedByBrandCodes(
const std::vector<std::wstring>& brand_codes);
bool SetReactivationBrandCode(const std::wstring& brand_code);
#endif // CHROME_INSTALLER_GCAPI_GCAPI_REACTIVATION_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/basictypes.h"
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "base/test/test_reg_util_win.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/common/guid.h"
#include "chrome/installer/gcapi/gcapi.h"
#include "chrome/installer/gcapi/gcapi_reactivation.h"
#include "chrome/installer/util/google_update_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::Time;
using base::TimeDelta;
using base::win::RegKey;
class GCAPIReactivationTest : public ::testing::Test {
protected:
void SetUp() {
// Override keys - this is undone during destruction.
std::wstring hkcu_override = base::StringPrintf(
L"hkcu_override\\%ls", ASCIIToWide(guid::GenerateGUID()));
override_manager_.OverrideRegistry(HKEY_CURRENT_USER, hkcu_override);
}
bool SetChromeInstallMarker(HKEY hive) {
// Create the client state keys in the right places.
std::wstring reg_path(google_update::kRegPathClients);
reg_path += L"\\";
reg_path += google_update::kChromeUpgradeCode;
RegKey client_state(hive,
reg_path.c_str(),
KEY_CREATE_SUB_KEY | KEY_SET_VALUE);
return (client_state.Valid() &&
client_state.WriteValue(
google_update::kRegVersionField, L"1.2.3.4") == ERROR_SUCCESS);
}
bool SetLastRunTime(HKEY hive, int64 last_run_time) {
return SetLastRunTimeString(hive, base::Int64ToString16(last_run_time));
}
bool SetLastRunTimeString(HKEY hive, const string16& last_run_time_string) {
const wchar_t* base_path =
(hive == HKEY_LOCAL_MACHINE) ?
google_update::kRegPathClientStateMedium :
google_update::kRegPathClientState;
std::wstring path(base_path);
path += L"\\";
path += google_update::kChromeUpgradeCode;
RegKey client_state(hive, path.c_str(), KEY_SET_VALUE);
return (client_state.Valid() &&
client_state.WriteValue(
google_update::kRegLastRunTimeField,
last_run_time_string.c_str()) == ERROR_SUCCESS);
}
std::wstring GetReactivationString(HKEY hive) {
const wchar_t* base_path =
(hive == HKEY_LOCAL_MACHINE) ?
google_update::kRegPathClientStateMedium :
google_update::kRegPathClientState;
std::wstring path(base_path);
path += L"\\";
path += google_update::kChromeUpgradeCode;
RegKey client_state(hive, path.c_str(), KEY_QUERY_VALUE);
if (client_state.Valid()) {
std::wstring actual_brand;
if (client_state.ReadValue(google_update::kRegRLZReactivationBrandField,
&actual_brand) == ERROR_SUCCESS) {
return actual_brand;
}
}
return L"ERROR";
}
private:
registry_util::RegistryOverrideManager override_manager_;
};
TEST_F(GCAPIReactivationTest, CheckSetReactivationBrandCode) {
EXPECT_TRUE(SetReactivationBrandCode(L"GAGA"));
EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER));
std::vector<std::wstring> check_codes;
check_codes.push_back(L"GAGA");
EXPECT_TRUE(HasBeenReactivatedByBrandCodes(check_codes));
check_codes.push_back(L"GOOGOO");
EXPECT_TRUE(HasBeenReactivatedByBrandCodes(check_codes));
check_codes.erase(check_codes.begin());
EXPECT_FALSE(HasBeenReactivatedByBrandCodes(check_codes));
}
TEST_F(GCAPIReactivationTest, CanOfferReactivation_Basic) {
const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"};
DWORD error;
// We're not installed yet. Make sure CanOfferReactivation fails.
EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(REACTIVATE_ERROR_NOTINSTALLED, error);
// Now pretend to be installed. CanOfferReactivation should pass.
EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER));
EXPECT_TRUE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
previous_brands, &error));
// Now set a recent last_run value. CanOfferReactivation should fail again.
Time hkcu_last_run = Time::NowFromSystemTime() - TimeDelta::FromDays(20);
EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
hkcu_last_run.ToInternalValue()));
EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(REACTIVATE_ERROR_NOTDORMANT, error);
// Now set a last_run value that exceeds the threshold.
hkcu_last_run = Time::NowFromSystemTime() -
TimeDelta::FromDays(kReactivationMinDaysDormant);
EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
hkcu_last_run.ToInternalValue()));
EXPECT_TRUE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
previous_brands, &error));
// Test some invalid inputs
EXPECT_FALSE(CanOfferReactivation(NULL, arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(REACTIVATE_ERROR_INVALID_INPUT, error);
EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
NULL, &error));
EXPECT_EQ(REACTIVATE_ERROR_INVALID_INPUT, error);
// One more valid one
EXPECT_TRUE(CanOfferReactivation(L"GAGA", 0, NULL, &error));
// Check that the previous brands check works:
EXPECT_TRUE(SetReactivationBrandCode(L"GOOGOO"));
EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error);
}
TEST_F(GCAPIReactivationTest, Reactivation_Flow) {
const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"};
DWORD error;
// Set us up as a candidate for reactivation.
EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER));
Time hkcu_last_run = Time::NowFromSystemTime() -
TimeDelta::FromDays(kReactivationMinDaysDormant);
EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
hkcu_last_run.ToInternalValue()));
EXPECT_TRUE(ReactivateChrome(L"GAGA", arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER));
// Make sure we can't reactivate again:
EXPECT_FALSE(ReactivateChrome(L"GAGA", arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error);
// Should still be able to reactivate under other brands:
EXPECT_TRUE(ReactivateChrome(L"MAMA", arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(L"MAMA", GetReactivationString(HKEY_CURRENT_USER));
// Validate that previous_brands are rejected:
EXPECT_FALSE(ReactivateChrome(L"PFFT", arraysize(previous_brands),
previous_brands, &error));
EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error);
EXPECT_EQ(L"MAMA", GetReactivationString(HKEY_CURRENT_USER));
}
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include <stdio.h> #include <stdio.h>
#include "base/command_line.h"
#include "chrome/installer/gcapi/gcapi.h" #include "chrome/installer/gcapi/gcapi.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -55,17 +54,11 @@ void call_dynamically() { ...@@ -55,17 +54,11 @@ void call_dynamically() {
FreeLibrary(module); FreeLibrary(module);
} }
const char kManualLaunchTests[] = "launch-chrome";
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
CommandLine::Init(argc, argv);
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS(); RUN_ALL_TESTS();
if (CommandLine::ForCurrentProcess()->HasSwitch(kManualLaunchTests)) { call_dynamically();
call_dynamically(); call_statically();
call_statically(); printf("LaunchChrome returned %d.\n", LaunchGoogleChrome());
printf("LaunchChrome returned %d.\n", LaunchGoogleChrome());
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment