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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/src/validating_util.h

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (C) 2013 Google Inc. 1 // Copyright (C) 2013 Google Inc.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 13 matching lines...) Expand all
24 24
25 namespace i18n { 25 namespace i18n {
26 namespace addressinput { 26 namespace addressinput {
27 27
28 // Wraps data with a checksum and a timestamp. Sample usage: 28 // Wraps data with a checksum and a timestamp. Sample usage:
29 // std::string data = ... 29 // std::string data = ...
30 // std::string wrapped = ValidatingUtil::Wrap(data, time(NULL)); 30 // std::string wrapped = ValidatingUtil::Wrap(data, time(NULL));
31 // Process(wrapped); 31 // Process(wrapped);
32 // 32 //
33 // std::string unwrapped = wrapped; 33 // std::string unwrapped = wrapped;
34 // if (ValidatingUtil::UnwrapTimestamp(&unwrapped, time(NULL)) && 34 // if (ValidatingUtil::TIMESTAMP_VALID ==
35 // ValidatingUtil::UnwrapTimestamp(&unwrapped, time(NULL)) &&
35 // ValidatingUtil::UnwrapChecksum(&unwrapped)) { 36 // ValidatingUtil::UnwrapChecksum(&unwrapped)) {
36 // Process(unwrapped); 37 // Process(unwrapped);
37 // } 38 // }
38 class ValidatingUtil { 39 class ValidatingUtil {
39 public: 40 public:
41 // Result of parsing and validating a timestamp.
42 enum TimestampStatus {
43 // The timestamp is present, formatted correctly, valid, and recent.
44 TIMESTAMP_VALID,
45
46 // The timestamp is either missing, incorrectly formatted, or invalid.
47 TIMESTAMP_INVALID,
48
49 // The timestamp is present, formatted correctly, and valid, but stale.
50 TIMESTAMP_STALE
51 };
52
40 // Returns |data| with attached checksum and given |timestamp|. 53 // Returns |data| with attached checksum and given |timestamp|.
41 static std::string Wrap(const std::string& data, time_t timestamp); 54 static std::string Wrap(const std::string& data, time_t timestamp);
42 55
43 // Strips out the timestamp from |data|. Returns |true| if the timestamp is 56 // Strips out the timestamp from |data| and validates it with respect to
44 // present, formatted correctly, valid, and recent with respect to |now|. 57 // |now|.
45 static bool UnwrapTimestamp(std::string* data, time_t now); 58 static TimestampStatus UnwrapTimestamp(std::string* data, time_t now);
Evan Stade 2014/01/22 01:42:12 I think that UnwrapTimestamp and UnwrapChecksum sh
please use gerrit instead 2014/01/22 23:57:41 Refactored into: std::string Wrapper::Wrap(const
Evan Stade 2014/01/23 00:07:23 why is double a better way of representing time th
please use gerrit instead 2014/01/23 00:09:00 The difference between two time_t objects is alway
46 59
47 // Strips out the checksum from |data|. Returns |true| if the checksum is 60 // Strips out and validates the checksum from |data|. Returns |true| if the
48 // present, formatted correctly, and valid for this data. 61 // checksum is present, formatted correctly, and valid for this data.
49 static bool UnwrapChecksum(std::string* data); 62 static bool UnwrapChecksum(std::string* data);
50 }; 63 };
51 64
52 } // namespace addressinput 65 } // namespace addressinput
53 } // namespace i18n 66 } // namespace i18n
54 67
55 #endif // I18N_ADDRESSINPUT_VALIDATING_UTIL_H_ 68 #endif // I18N_ADDRESSINPUT_VALIDATING_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698