gcapi_omaha_experiment.cc revision 3551c9c881056c480085172ff9840cab31610854
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/installer/gcapi/gcapi_omaha_experiment.h" 6 7#include "base/strings/string16.h" 8#include "base/strings/stringprintf.h" 9#include "base/time/time.h" 10#include "chrome/installer/gcapi/gcapi.h" 11#include "chrome/installer/util/google_update_experiment_util.h" 12#include "chrome/installer/util/google_update_settings.h" 13 14using base::Time; 15using base::TimeDelta; 16 17namespace { 18 19// Returns the number of weeks since 2/3/2003. 20int GetCurrentRlzWeek() { 21 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; 22 Time f = Time::FromUTCExploded(february_third_2003_exploded); 23 TimeDelta delta = Time::Now() - f; 24 return delta.InDays() / 7; 25} 26 27bool SetLabel(const wchar_t* brand_code, const wchar_t* label, int shell_mode) { 28 if (!brand_code) { 29 return false; 30 } 31 32 int week_number = GetCurrentRlzWeek(); 33 if (week_number < 0 || week_number > 999) 34 week_number = 999; 35 36 string16 experiment_labels; 37 base::SStringPrintf(&experiment_labels, 38 L"%ls=%ls_%d|%ls", 39 label, 40 brand_code, 41 week_number, 42 installer::BuildExperimentDateString().c_str()); 43 44 return GoogleUpdateSettings::SetExperimentLabels( 45 shell_mode == GCAPI_INVOKED_UAC_ELEVATION, 46 experiment_labels); 47} 48 49} // namespace 50 51bool SetReactivationExperimentLabels(const wchar_t* brand_code, 52 int shell_mode) { 53 return SetLabel(brand_code, L"reacbrand", shell_mode); 54} 55 56bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { 57 return SetLabel(brand_code, L"relaunchbrand", shell_mode); 58} 59