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

Unified Diff: third_party/libaddressinput/chromium/cpp/src/wrapper.h

Issue 144353002: [rac] Use stale libaddressinput data if download fails (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. 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/wrapper.h
diff --git a/third_party/libaddressinput/chromium/cpp/src/wrapper.h b/third_party/libaddressinput/chromium/cpp/src/wrapper.h
new file mode 100644
index 0000000000000000000000000000000000000000..10d02bc5e28b3bf316541ef7b686971634dbfdd7
--- /dev/null
+++ b/third_party/libaddressinput/chromium/cpp/src/wrapper.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2014 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// An object to wrap data with a checksum and a timestamp. These fields are used
+// to verify that the data is not stale or corrupted.
+
+#ifndef I18N_ADDRESSINPUT_WRAPPER_H_
+#define I18N_ADDRESSINPUT_WRAPPER_H_
+
+#include <string>
+
+namespace i18n {
+namespace addressinput {
+
+// Wraps data with a checksum and a timestamp. Sample usage:
+// std::string data = ...
+// std::string wrapped = Wrapper::Wrap(data);
+// Process(wrapped);
+//
+// std::string unwrapped = wrapped;
+// double age_in_seconds = 0.0;
+// if (Wrapper::Unwrap(&unwrapped, &age_in_seconds) &&
+// IsRecent(age_in_seconds)) {
+// Process(unwrapped);
+// }
+class Wrapper {
Evan Stade 2014/01/23 00:07:23 Wrapper is far too generic a name to be useful. Yo
please use gerrit instead 2014/01/23 01:03:14 Done.
+ public:
+ // Returns |data| with attached checksum and current timestamp.
+ static std::string Wrap(const std::string& data);
+
+ // Strips out the timestamp and checksum from |data|. Validates the checksum.
+ // Compares the parsed timestamp with current time and saves the difference
+ // into |age_in_seconds|.
+ //
+ // The parameters should not be NULL. Does not take ownership of its
+ // parameters.
+ //
+ // Returns |true| if |data| is correctly formatted and has the correct
+ // checksum.
+ static bool Unwrap(std::string* data, double* age_in_seconds);
+};
+
+} // namespace addressinput
+} // namespace i18n
+
+#endif // I18N_ADDRESSINPUT_WRAPPER_H_

Powered by Google App Engine
This is Rietveld 408576698