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

Side by Side Diff: chrome/browser/translate/translate_tab_helper.cc

Issue 285293004: Allow browser tests to run with dynamic CLD data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cld_uma
Patch Set: Created 6 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/translate/translate_tab_helper.h" 5 #include "chrome/browser/translate/translate_tab_helper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 if (s_cached_file_) { 434 if (s_cached_file_) {
435 // Idempotence: Racing another request on the blocking pool, abort. 435 // Idempotence: Racing another request on the blocking pool, abort.
436 } else { 436 } else {
437 // Else, this request has taken care of it all. Cache all info. 437 // Else, this request has taken care of it all. Cache all info.
438 s_cached_file_ = file.release(); 438 s_cached_file_ = file.release();
439 s_cached_data_offset_ = data_offset; 439 s_cached_data_offset_ = data_offset;
440 s_cached_data_length_ = data_length; 440 s_cached_data_length_ = data_length;
441 } 441 }
442 } 442 }
443 } 443 }
444
445 // DO NOT USE IN PRODUCTION, LEAKS FILE HANDLES!
446 void TranslateTabHelper::ClearCLDDataForTest() {
447 base::AutoLock lock(s_file_lock_.Get());
448 if (s_cached_file_) {
449 s_cached_file_ = NULL; // Leaks any open handle, no way to avoid safely.
450 s_cached_data_offset_ = 0;
451 s_cached_data_length_ = 0;
452 }
453 }
444 #endif // defined(CLD2_DYNAMIC_MODE) 454 #endif // defined(CLD2_DYNAMIC_MODE)
445 455
446 void TranslateTabHelper::InitiateTranslation(const std::string& page_lang, 456 void TranslateTabHelper::InitiateTranslation(const std::string& page_lang,
447 int attempt) { 457 int attempt) {
448 if (translate_driver_.GetLanguageState().translation_pending()) 458 if (translate_driver_.GetLanguageState().translation_pending())
449 return; 459 return;
450 460
451 // During a reload we need web content to be available before the 461 // During a reload we need web content to be available before the
452 // translate script is executed. Otherwise we will run the translate script on 462 // translate script is executed. Otherwise we will run the translate script on
453 // an empty DOM which will fail. Therefore we wait a bit to see if the page 463 // an empty DOM which will fail. Therefore we wait a bit to see if the page
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (GetLanguageState().InTranslateNavigation()) 547 if (GetLanguageState().InTranslateNavigation())
538 return; 548 return;
539 } 549 }
540 550
541 TranslateBubbleFactory::Show( 551 TranslateBubbleFactory::Show(
542 browser->window(), web_contents(), step, error_type); 552 browser->window(), web_contents(), step, error_type);
543 #else 553 #else
544 NOTREACHED(); 554 NOTREACHED();
545 #endif 555 #endif
546 } 556 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698