summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.gyp1
-rw-r--r--base/base.gypi2
-rw-r--r--base/build_time.cc25
-rw-r--r--base/build_time.h26
-rw-r--r--base/build_time_unittest.cc30
-rw-r--r--base/metrics/field_trial.cc12
-rw-r--r--base/metrics/field_trial.h3
7 files changed, 86 insertions, 13 deletions
diff --git a/base/base.gyp b/base/base.gyp
index bb6f4e0..5c7b615 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -123,6 +123,7 @@
'bind_unittest.cc',
'bind_unittest.nc',
'bits_unittest.cc',
+ 'build_time_unittest.cc',
'callback_unittest.cc',
'callback_unittest.nc',
'command_line_unittest.cc',
diff --git a/base/base.gypi b/base/base.gypi
index fe82695..f81be8a 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -56,6 +56,8 @@
'bind_internal.h',
'bind_internal_win.h',
'bits.h',
+ 'build_time.cc',
+ 'build_time.h',
'callback.h',
'callback_internal.cc',
'callback_internal.h',
diff --git a/base/build_time.cc b/base/build_time.cc
new file mode 100644
index 0000000..bb2274b
--- /dev/null
+++ b/base/build_time.cc
@@ -0,0 +1,25 @@
+// Copyright (c) 2011 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 "base/build_time.h"
+
+#include "base/logging.h"
+#include "base/time.h"
+
+namespace base {
+
+Time GetBuildTime() {
+ Time integral_build_time;
+ // The format of __DATE__ and __TIME__ is specified by the ANSI C Standard,
+ // section 6.8.8.
+ //
+ // __DATE__ is exactly "Mmm DD YYYY".
+ // __TIME__ is exactly "hh:mm:ss".
+ const char kDateTime[] = __DATE__ " " __TIME__ " PST";
+ bool result = Time::FromString(kDateTime, &integral_build_time);
+ DCHECK(result);
+ return integral_build_time;
+}
+
+} // namespace base
diff --git a/base/build_time.h b/base/build_time.h
new file mode 100644
index 0000000..6d413bc
--- /dev/null
+++ b/base/build_time.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2011 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 BASE_BUILD_TIME_
+#define BASE_BUILD_TIME_
+#pragma once
+
+#include "base/base_export.h"
+#include "base/time.h"
+
+namespace base {
+
+// GetBuildTime returns the time at which the current binary was built.
+//
+// This uses the __DATE__ and __TIME__ macros, which don't trigger a rebuild
+// when they change. However, official builds will always be rebuilt from
+// scratch.
+//
+// Also, since __TIME__ doesn't include a timezone, this value should only be
+// considered accurate to a day.
+Time BASE_EXPORT GetBuildTime();
+
+} // namespace base
+
+#endif // BASE_BUILD_TIME_
diff --git a/base/build_time_unittest.cc b/base/build_time_unittest.cc
new file mode 100644
index 0000000..399a53f
--- /dev/null
+++ b/base/build_time_unittest.cc
@@ -0,0 +1,30 @@
+// Copyright (c) 2011 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 "base/build_time.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(BuildTime, DateLooksValid) {
+ char build_date[] = __DATE__;
+
+ EXPECT_EQ(11u, strlen(build_date));
+ EXPECT_EQ(' ', build_date[3]);
+ EXPECT_EQ(' ', build_date[6]);
+}
+
+TEST(BuildTime, TimeLooksValid) {
+ char build_time[] = __TIME__;
+
+ EXPECT_EQ(8u, strlen(build_time));
+ EXPECT_EQ(':', build_time[2]);
+ EXPECT_EQ(':', build_time[5]);
+}
+
+TEST(BuildTime, DoesntCrash) {
+ // Since __DATE__ isn't updated unless one does a clobber build, we can't
+ // really test the value returned by it, except to check that it doesn't
+ // crash.
+ base::GetBuildTime();
+}
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index a18d72c..9996262 100644
--- a/base/metrics/field_trial.cc
+++ b/base/metrics/field_trial.cc
@@ -4,11 +4,12 @@
#include "base/metrics/field_trial.h"
+#include "base/build_time.h"
#include "base/logging.h"
#include "base/rand_util.h"
#include "base/sha1.h"
-#include "base/string_util.h"
#include "base/stringprintf.h"
+#include "base/string_util.h"
#include "base/utf_string_conversions.h"
namespace base {
@@ -154,15 +155,6 @@ void FieldTrial::EnableBenchmarking() {
FieldTrial::~FieldTrial() {}
// static
-Time FieldTrial::GetBuildTime() {
- Time integral_build_time;
- const char* kDateTime = __DATE__ " " __TIME__;
- bool result = Time::FromString(kDateTime, &integral_build_time);
- DCHECK(result);
- return integral_build_time;
-}
-
-// static
double FieldTrial::HashClientId(const std::string& client_id,
const std::string& trial_name) {
// SHA-1 is designed to produce a uniformly random spread in its output space,
diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h
index 0c244bb..e7a4506 100644
--- a/base/metrics/field_trial.h
+++ b/base/metrics/field_trial.h
@@ -184,9 +184,6 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// Returns the group_name. A winner need not have been chosen.
std::string group_name_internal() const { return group_name_; }
- // Get build time.
- static Time GetBuildTime();
-
// Calculates a uniformly-distributed double between [0.0, 1.0) given
// a |client_id| and a |trial_name| (the latter is used as salt to avoid
// separate one-time randomized trials from all having the same results).