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

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

Issue 137563004: libaddressinput: Add fallback data for US address validation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git cl try 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/retriever.cc
diff --git a/third_party/libaddressinput/chromium/cpp/src/retriever.cc b/third_party/libaddressinput/chromium/cpp/src/retriever.cc
index 7dd788107efec20b5b6541b144972e9810af6689..407d1809268982b0397dd48f8f562789aa3868db 100644
--- a/third_party/libaddressinput/chromium/cpp/src/retriever.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/retriever.cc
@@ -26,6 +26,7 @@
#include <string>
#include <utility>
+#include "fallback_data_store.h"
#include "lookup_key_util.h"
#include "util/stl_util.h"
@@ -63,13 +64,13 @@ void Retriever::Retrieve(const std::string& key,
void Retriever::OnDataRetrievedFromStorage(bool success,
const std::string& key,
- const std::string& data) {
+ const std::string& stored_data) {
// TODO(rouslan): Add validation for data integrity and freshness. If a
// download fails, then it's OK to use stale data.
if (success) {
scoped_ptr<Callback> retrieved = GetCallbackForKey(key);
if (retrieved != NULL) {
- (*retrieved)(success, key, data);
+ (*retrieved)(success, key, stored_data);
}
} else {
downloader_->Download(lookup_key_util_.GetUrlForKey(key),
@@ -79,14 +80,19 @@ void Retriever::OnDataRetrievedFromStorage(bool success,
void Retriever::OnDownloaded(bool success,
const std::string& url,
- const std::string& data) {
+ const std::string& downloaded_data) {
+ std::string response;
const std::string& key = lookup_key_util_.GetKeyForUrl(url);
if (success) {
- storage_->Put(key, data);
+ storage_->Put(key, downloaded_data);
+ response = downloaded_data;
+ } else {
+ success = FallbackDataStore::Get(key, &response);
}
+
scoped_ptr<Callback> retrieved = GetCallbackForKey(key);
if (retrieved != NULL) {
- (*retrieved)(success, key, success ? data : std::string());
+ (*retrieved)(success, key, response);
}
}

Powered by Google App Engine
This is Rietveld 408576698