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

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

Issue 109323011: [rac] Download all rules for a country code in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address data 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 c1ad5306fe49dbe6ed8023ace14a0faf1713ecfa..87d6d793455e7b67571d0c6fdf23651ef1306116 100644
--- a/third_party/libaddressinput/chromium/cpp/src/retriever.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/retriever.cc
@@ -48,8 +48,15 @@ Retriever::~Retriever() {
void Retriever::Retrieve(const std::string& key,
scoped_ptr<Callback> retrieved) {
- assert(requests_.find(key) == requests_.end());
- requests_.insert(std::make_pair(key, retrieved.release()));
+ std::map<std::string, Callback*>::iterator request_it =
+ requests_.find(key);
+ if (request_it != requests_.end()) {
+ // Abandon a previous request.
+ delete request_it->second;
+ requests_.erase(request_it);
+ }
+
+ requests_[key] = retrieved.release();
storage_->Get(key,
BuildCallback(this, &Retriever::OnDataRetrievedFromStorage));
}
@@ -59,7 +66,9 @@ void Retriever::OnDataRetrievedFromStorage(bool success,
const std::string& data) {
if (success) {
scoped_ptr<Callback> retrieved = GetCallbackForKey(key);
- (*retrieved)(success, key, data);
+ if (retrieved != NULL) {
+ (*retrieved)(success, key, data);
+ }
} else {
downloader_->Download(lookup_key_util_.GetUrlForKey(key),
BuildCallback(this, &Retriever::OnDownloaded));
@@ -74,14 +83,19 @@ void Retriever::OnDownloaded(bool success,
storage_->Put(key, data);
}
scoped_ptr<Callback> retrieved = GetCallbackForKey(key);
- (*retrieved)(success, key, success ? data : std::string());
+ if (retrieved != NULL) {
+ (*retrieved)(success, key, success ? data : std::string());
+ }
}
scoped_ptr<Retriever::Callback> Retriever::GetCallbackForKey(
const std::string& key) {
std::map<std::string, Callback*>::iterator iter =
requests_.find(key);
- assert(iter != requests_.end());
+ if (iter == requests_.end()) {
+ // An abandonened request.
+ return scoped_ptr<Callback>();
+ }
scoped_ptr<Callback> callback(iter->second);
requests_.erase(iter);
return callback.Pass();

Powered by Google App Engine
This is Rietveld 408576698