gcapi_omaha_experiment.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/string16.h"
8#include "base/stringprintf.h"
9#include "base/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
27}  // namespace
28
29bool SetReactivationExperimentLabels(const wchar_t* brand_code,
30                                     int shell_mode) {
31  if (!brand_code) {
32    return false;
33  }
34
35  int week_number = GetCurrentRlzWeek();
36  if (week_number < 0 || week_number > 999)
37    week_number = 999;
38
39  string16 experiment_labels;
40  base::SStringPrintf(&experiment_labels,
41                      L"reacbrand=%ls_%d|%ls",
42                      brand_code,
43                      week_number,
44                      installer::BuildExperimentDateString().c_str());
45
46  return GoogleUpdateSettings::SetExperimentLabels(
47      shell_mode == GCAPI_INVOKED_UAC_ELEVATION,
48      experiment_labels);
49}
50