Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Unified Diff: third_party/libaddressinput/chromium/cpp/src/validating_util.cc

Issue 144353002: [rac] Use stale libaddressinput data if download fails (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/cpp/src/validating_util.cc
diff --git a/third_party/libaddressinput/chromium/cpp/src/validating_util.cc b/third_party/libaddressinput/chromium/cpp/src/validating_util.cc
index 7f225c6500e3a6c9263522b4b04e2d647a03078e..a283a45bf4e263014c6a7d45fc7decb5217b7204 100644
--- a/third_party/libaddressinput/chromium/cpp/src/validating_util.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/validating_util.cc
@@ -104,21 +104,28 @@ std::string ValidatingUtil::Wrap(const std::string& data, time_t timestamp) {
}
// static
-bool ValidatingUtil::UnwrapTimestamp(std::string* data, time_t now) {
+ValidatingUtil::TimestampStatus ValidatingUtil::UnwrapTimestamp(
+ std::string* data,
+ time_t now) {
assert(data != NULL);
if (now < 0) {
- return false;
+ return TIMESTAMP_INVALID;
}
std::string timestamp_string;
if (!UnwrapHeader(
kTimestampPrefix, kTimestampPrefixLength, data, &timestamp_string)) {
- return false;
+ return TIMESTAMP_INVALID;
}
time_t timestamp = atol(timestamp_string.c_str());
if (timestamp < 0) {
- return false;
+ return TIMESTAMP_INVALID;
+ }
+
+ double age_in_seconds = difftime(now, timestamp);
+ if (age_in_seconds < 0.0) {
+ return TIMESTAMP_INVALID;
}
// One month contains:
@@ -127,8 +134,8 @@ bool ValidatingUtil::UnwrapTimestamp(std::string* data, time_t now) {
// 60 minutes per hour *
// 60 seconds per minute.
static const double kOneMonthInSeconds = 30.0 * 24.0 * 60.0 * 60.0;
- double age_in_seconds = difftime(now, timestamp);
- return !(age_in_seconds < 0.0) && age_in_seconds < kOneMonthInSeconds;
+ return age_in_seconds < kOneMonthInSeconds ? TIMESTAMP_VALID
+ : TIMESTAMP_STALE;
}
// static

Powered by Google App Engine
This is Rietveld 408576698