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..7118b7ff739a777d64ee3a5152228ff941335d6c 100644 |
--- a/third_party/libaddressinput/chromium/cpp/src/retriever.cc |
+++ b/third_party/libaddressinput/chromium/cpp/src/retriever.cc |
@@ -26,7 +26,6 @@ |
#include <string> |
#include <utility> |
-#include "lookup_key_util.h" |
#include "util/stl_util.h" |
namespace i18n { |
@@ -35,9 +34,11 @@ namespace addressinput { |
Retriever::Retriever(const std::string& validation_data_url, |
scoped_ptr<Downloader> downloader, |
scoped_ptr<Storage> storage) |
- : lookup_key_util_(validation_data_url), |
+ : validation_data_url_(validation_data_url), |
downloader_(downloader.Pass()), |
storage_(storage.Pass()) { |
+ assert(validation_data_url_.length() > 0); |
+ assert(validation_data_url_[validation_data_url_.length() - 1] == '/'); |
assert(storage_ != NULL); |
assert(downloader_ != NULL); |
} |
@@ -72,7 +73,7 @@ void Retriever::OnDataRetrievedFromStorage(bool success, |
(*retrieved)(success, key, data); |
} |
} else { |
- downloader_->Download(lookup_key_util_.GetUrlForKey(key), |
+ downloader_->Download(GetUrlForKey(key), |
BuildCallback(this, &Retriever::OnDownloaded)); |
} |
} |
@@ -80,7 +81,7 @@ void Retriever::OnDataRetrievedFromStorage(bool success, |
void Retriever::OnDownloaded(bool success, |
const std::string& url, |
const std::string& data) { |
- const std::string& key = lookup_key_util_.GetKeyForUrl(url); |
+ const std::string& key = GetKeyForUrl(url); |
if (success) { |
storage_->Put(key, data); |
} |
@@ -90,6 +91,22 @@ void Retriever::OnDownloaded(bool success, |
} |
} |
+std::string Retriever::GetUrlForKey(const std::string& key) const { |
+ return validation_data_url_ + key; |
+} |
+ |
+std::string Retriever::GetKeyForUrl(const std::string& url) const { |
+ if (url.compare(0, validation_data_url_.length(), validation_data_url_) == 0) |
+ return url.substr(validation_data_url_.length()); |
+ |
+ return std::string(); |
+} |
+ |
+bool Retriever::IsValidationDataUrl(const std::string& url) const { |
+ return |
+ url.compare(0, validation_data_url_.length(), validation_data_url_) == 0; |
+} |
+ |
scoped_ptr<Retriever::Callback> Retriever::GetCallbackForKey( |
const std::string& key) { |
std::map<std::string, Callback*>::iterator iter = |