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

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

Issue 137443009: libaddressinput - merge LookupKeyUtil into Retriever (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/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 =

Powered by Google App Engine
This is Rietveld 408576698