summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/time.cc9
-rw-r--r--base/time.h6
-rw-r--r--chrome/browser/extensions/extension_cookies_api.cc5
-rw-r--r--chrome/browser/extensions/extension_history_api.cc7
4 files changed, 24 insertions, 3 deletions
diff --git a/base/time.cc b/base/time.cc
index 383f939..766f599 100644
--- a/base/time.cc
+++ b/base/time.cc
@@ -66,6 +66,8 @@ time_t Time::ToTimeT() const {
// static
Time Time::FromDoubleT(double dt) {
+ if (dt == 0)
+ return Time(); // Preserve 0 so we can tell it doesn't exist.
return Time(static_cast<int64>((dt *
static_cast<double>(kMicrosecondsPerSecond)) +
kTimeTToMicrosecondsOffset));
@@ -78,6 +80,13 @@ double Time::ToDoubleT() const {
static_cast<double>(kMicrosecondsPerSecond));
}
+// static
+Time Time::UnixEpoch() {
+ Time time;
+ time.us_ = kTimeTToMicrosecondsOffset;
+ return time;
+}
+
Time Time::LocalMidnight() const {
Exploded exploded;
LocalExplode(&exploded);
diff --git a/base/time.h b/base/time.h
index 0f5eb5d..0ed7957 100644
--- a/base/time.h
+++ b/base/time.h
@@ -230,6 +230,9 @@ class Time {
return us_ == 0;
}
+ // Returns the time for epoch in Unix-like system (Jan 1, 1970).
+ static Time UnixEpoch();
+
// Returns the current time. Watch out, the system might adjust its clock
// in which case time will actually go backwards. We don't guarantee that
// times are increasing, or that two calls to Now() won't be the same.
@@ -249,6 +252,9 @@ class Time {
// Converts time to/from a double which is the number of seconds since epoch
// (Jan 1, 1970). Webkit uses this format to represent time.
+ // Because WebKit initializes double time value to 0 to indicate "not
+ // initialized", we map it to empty Time object that also means "not
+ // initialized".
static Time FromDoubleT(double dt);
double ToDoubleT() const;
diff --git a/chrome/browser/extensions/extension_cookies_api.cc b/chrome/browser/extensions/extension_cookies_api.cc
index 5a2d456..e22213d 100644
--- a/chrome/browser/extensions/extension_cookies_api.cc
+++ b/chrome/browser/extensions/extension_cookies_api.cc
@@ -306,7 +306,10 @@ bool SetCookieFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(
expiration_date_value->GetAsReal(&expiration_date));
}
- expiration_time_ = base::Time::FromDoubleT(expiration_date);
+ // Time::FromDoubleT converts double time 0 to empty Time object. So we need
+ // to do special handling here.
+ expiration_time_ = (expiration_date == 0) ?
+ base::Time::UnixEpoch() : base::Time::FromDoubleT(expiration_date);
}
URLRequestContextGetter* store_context = NULL;
diff --git a/chrome/browser/extensions/extension_history_api.cc b/chrome/browser/extensions/extension_history_api.cc
index 515e918b..fac0e1f 100644
--- a/chrome/browser/extensions/extension_history_api.cc
+++ b/chrome/browser/extensions/extension_history_api.cc
@@ -180,7 +180,10 @@ bool HistoryFunction::GetTimeFromValue(Value* value, base::Time* time) {
// The history service has seconds resolution, while javascript Date() has
// milliseconds resolution.
double seconds_from_epoch = ms_from_epoch / 1000.0;
- *time = base::Time::FromDoubleT(seconds_from_epoch);
+ // Time::FromDoubleT converts double time 0 to empty Time object. So we need
+ // to do special handling here.
+ *time = (seconds_from_epoch == 0) ?
+ base::Time::UnixEpoch() : base::Time::FromDoubleT(seconds_from_epoch);
return true;
}
@@ -368,7 +371,7 @@ bool DeleteAllHistoryFunction::RunAsyncImpl() {
HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->ExpireHistoryBetween(
restrict_urls,
- base::Time::FromDoubleT(0), // From the beginning of the epoch.
+ base::Time::UnixEpoch(), // From the beginning of the epoch.
base::Time::Now(), // To the current time.
&cancelable_consumer_,
NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete));