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

Unified Diff: chrome/browser/translate/translate_manager.cc

Issue 7246010: Fixed a few valgrind tests by not assuming the UrlFetcher arrives with the same URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
« no previous file with comments | « chrome/browser/translate/translate_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/translate/translate_manager.cc
===================================================================
--- chrome/browser/translate/translate_manager.cc (revision 90030)
+++ chrome/browser/translate/translate_manager.cc (working copy)
@@ -349,27 +349,19 @@
int response_code,
const net::ResponseCookies& cookies,
const std::string& data) {
- scoped_ptr<const URLFetcher> delete_ptr(source);
- DCHECK(translate_script_request_pending_ || language_list_request_pending_);
- // We quickly recognize that we are handling a translate script request
- // if we don't have a language_list_request_pending_. Otherwise we do the
- // more expensive check of confirming we got the kTranslateScriptURL in the
- // rare case where we would have both requests pending at the same time.
- bool translate_script_request = !language_list_request_pending_ ||
- url == GURL(kTranslateScriptURL);
- // Here we make sure that if we didn't get the translate_script_request,
- // we actually got a language_list_request.
- DCHECK(translate_script_request || url == GURL(kLanguageListFetchURL));
- if (translate_script_request)
- translate_script_request_pending_ = false;
- else
- language_list_request_pending_ = false;
+ if (translate_script_request_pending_.get() != source &&
+ language_list_request_pending_.get() != source) {
+ // Looks like crash on Mac is possibly caused with callback entering here
cbentzel 2011/06/24 19:56:08 Should you add a CHECK here so we can see failures
+ // with unknown fetcher when network is refreshed.
+ scoped_ptr<const URLFetcher> delete_ptr(source);
+ return;
+ }
- bool error =
- (status.status() != net::URLRequestStatus::SUCCESS ||
- response_code != 200);
-
- if (translate_script_request) {
+ bool error = (status.status() != net::URLRequestStatus::SUCCESS ||
+ response_code != 200);
+ if (translate_script_request_pending_.get() == source) {
+ scoped_ptr<const URLFetcher> delete_ptr(
+ translate_script_request_pending_.release());
if (!error) {
base::StringPiece str = ResourceBundle::GetSharedInstance().
GetRawDataResource(IDR_TRANSLATE_JS);
@@ -412,7 +404,9 @@
}
}
pending_requests_.clear();
- } else { // if (translate_script_request)
+ } else { // if (translate_script_request_pending_.get() == source)
+ scoped_ptr<const URLFetcher> delete_ptr(
+ language_list_request_pending_.release());
if (!error)
SetSupportedLanguages(data);
else
@@ -427,9 +421,7 @@
TranslateManager::TranslateManager()
: ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- translate_script_expiration_delay_(kTranslateScriptExpirationDelayMS),
- translate_script_request_pending_(false),
- language_list_request_pending_(false) {
+ translate_script_expiration_delay_(kTranslateScriptExpirationDelayMS) {
notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
NotificationService::AllSources());
notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
@@ -705,7 +697,7 @@
void TranslateManager::FetchLanguageListFromTranslateServer(
PrefService* prefs) {
- if (language_list_request_pending_)
+ if (language_list_request_pending_.get() != NULL)
return;
// We don't want to do this when translate is disabled.
@@ -716,24 +708,30 @@
return;
}
- language_list_request_pending_ = true;
- URLFetcher* fetcher = URLFetcher::Create(1, GURL(kLanguageListFetchURL),
- URLFetcher::GET, this);
- fetcher->set_request_context(Profile::GetDefaultRequestContext());
- fetcher->set_max_retries(kMaxRetryLanguageListFetch);
- fetcher->Start();
+ language_list_request_pending_.reset(URLFetcher::Create(
+ 1, GURL(kLanguageListFetchURL), URLFetcher::GET, this));
+ language_list_request_pending_->set_request_context(
+ Profile::GetDefaultRequestContext());
+ language_list_request_pending_->set_max_retries(kMaxRetryLanguageListFetch);
+ language_list_request_pending_->Start();
}
+void TranslateManager::CleanupPendingUlrFetcher() {
+ language_list_request_pending_.reset();
+ translate_script_request_pending_.reset();
+}
+
void TranslateManager::RequestTranslateScript() {
- if (translate_script_request_pending_)
+ if (translate_script_request_pending_.get() != NULL)
return;
- translate_script_request_pending_ = true;
- URLFetcher* fetcher = URLFetcher::Create(0, GURL(kTranslateScriptURL),
- URLFetcher::GET, this);
- fetcher->set_request_context(Profile::GetDefaultRequestContext());
- fetcher->set_extra_request_headers(kTranslateScriptHeader);
- fetcher->Start();
+ translate_script_request_pending_.reset(URLFetcher::Create(
+ 0, GURL(kTranslateScriptURL), URLFetcher::GET, this));
+ translate_script_request_pending_->set_request_context(
+ Profile::GetDefaultRequestContext());
+ translate_script_request_pending_->set_extra_request_headers(
+ kTranslateScriptHeader);
+ translate_script_request_pending_->Start();
}
void TranslateManager::ShowInfoBar(TabContents* tab,
« no previous file with comments | « chrome/browser/translate/translate_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698