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

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

Issue 15881006: Added 'error logs' tab to chrome://translte-internals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary files Created 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_manager.h" 5 #include "chrome/browser/translate/translate_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/tab_contents/language_state.h" 23 #include "chrome/browser/tab_contents/language_state.h"
24 #include "chrome/browser/tab_contents/tab_util.h" 24 #include "chrome/browser/tab_contents/tab_util.h"
25 #include "chrome/browser/translate/page_translated_details.h" 25 #include "chrome/browser/translate/page_translated_details.h"
26 #include "chrome/browser/translate/translate_error_details.h"
26 #include "chrome/browser/translate/translate_infobar_delegate.h" 27 #include "chrome/browser/translate/translate_infobar_delegate.h"
27 #include "chrome/browser/translate/translate_manager_metrics.h" 28 #include "chrome/browser/translate/translate_manager_metrics.h"
28 #include "chrome/browser/translate/translate_prefs.h" 29 #include "chrome/browser/translate/translate_prefs.h"
29 #include "chrome/browser/translate/translate_tab_helper.h" 30 #include "chrome/browser/translate/translate_tab_helper.h"
30 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/browser_tabstrip.h" 33 #include "chrome/browser/ui/browser_tabstrip.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
35 #include "chrome/common/chrome_notification_types.h" 36 #include "chrome/common/chrome_notification_types.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 489 Profile::FromBrowserContext(web_contents->GetBrowserContext());
489 TranslateInfoBarDelegate::Create( 490 TranslateInfoBarDelegate::Create(
490 InfoBarService::FromWebContents(web_contents), 491 InfoBarService::FromWebContents(web_contents),
491 true, 492 true,
492 TranslateInfoBarDelegate::TRANSLATION_ERROR, 493 TranslateInfoBarDelegate::TRANSLATION_ERROR,
493 TranslateErrors::NETWORK, 494 TranslateErrors::NETWORK,
494 profile->GetPrefs(), 495 profile->GetPrefs(),
495 ShortcutConfig(), 496 ShortcutConfig(),
496 request.source_lang, 497 request.source_lang,
497 request.target_lang); 498 request.target_lang);
499
500 TranslateErrorDetails error_details;
501 error_details.time = base::Time::Now();
502 error_details.url = entry->GetURL();
503 error_details.error = TranslateErrors::NETWORK;
504 NotifyTranslateError(error_details);
498 } else { 505 } else {
499 // Translate the page. 506 // Translate the page.
500 DoTranslatePage(web_contents, translate_script_, 507 DoTranslatePage(web_contents, translate_script_,
501 request.source_lang, request.target_lang); 508 request.source_lang, request.target_lang);
502 } 509 }
503 } 510 }
504 pending_requests_.clear(); 511 pending_requests_.clear();
505 } else { // if (translate_script_request_pending_.get() == source) 512 } else { // if (translate_script_request_pending_.get() == source)
506 scoped_ptr<const net::URLFetcher> delete_ptr( 513 scoped_ptr<const net::URLFetcher> delete_ptr(
507 language_list_request_pending_.release()); 514 language_list_request_pending_.release());
(...skipping 13 matching lines...) Expand all
521 528
522 void TranslateManager::RemoveObserver(Observer* obs) { 529 void TranslateManager::RemoveObserver(Observer* obs) {
523 observer_list_.RemoveObserver(obs); 530 observer_list_.RemoveObserver(obs);
524 } 531 }
525 532
526 void TranslateManager::NotifyLanguageDetection( 533 void TranslateManager::NotifyLanguageDetection(
527 const LanguageDetectionDetails& details) { 534 const LanguageDetectionDetails& details) {
528 FOR_EACH_OBSERVER(Observer, observer_list_, OnLanguageDetection(details)); 535 FOR_EACH_OBSERVER(Observer, observer_list_, OnLanguageDetection(details));
529 } 536 }
530 537
538 void TranslateManager::NotifyTranslateError(
539 const TranslateErrorDetails& details) {
540 FOR_EACH_OBSERVER(Observer, observer_list_, OnTranslateError(details));
541 }
531 542
532 TranslateManager::TranslateManager() 543 TranslateManager::TranslateManager()
533 : weak_method_factory_(this), 544 : weak_method_factory_(this),
534 translate_script_expiration_delay_(base::TimeDelta::FromDays( 545 translate_script_expiration_delay_(base::TimeDelta::FromDays(
535 kTranslateScriptExpirationDelayDays)), 546 kTranslateScriptExpirationDelayDays)),
536 max_reload_check_attempts_(kMaxTranslateLoadCheckAttempts) { 547 max_reload_check_attempts_(kMaxTranslateLoadCheckAttempts) {
537 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 548 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
538 content::NotificationService::AllSources()); 549 content::NotificationService::AllSources());
539 notification_registrar_.Add(this, 550 notification_registrar_.Add(this,
540 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 551 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 TranslateManagerMetrics::ReportUnsupportedLanguage(); 811 TranslateManagerMetrics::ReportUnsupportedLanguage();
801 details->error_type = TranslateErrors::UNSUPPORTED_LANGUAGE; 812 details->error_type = TranslateErrors::UNSUPPORTED_LANGUAGE;
802 } 813 }
803 814
804 Profile* profile = 815 Profile* profile =
805 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 816 Profile::FromBrowserContext(web_contents->GetBrowserContext());
806 PrefService* prefs = profile->GetPrefs(); 817 PrefService* prefs = profile->GetPrefs();
807 TranslateInfoBarDelegate::Create( 818 TranslateInfoBarDelegate::Create(
808 InfoBarService::FromWebContents(web_contents), true, 819 InfoBarService::FromWebContents(web_contents), true,
809 (details->error_type == TranslateErrors::NONE) ? 820 (details->error_type == TranslateErrors::NONE) ?
810 TranslateInfoBarDelegate::AFTER_TRANSLATE : 821 TranslateInfoBarDelegate::AFTER_TRANSLATE :
811 TranslateInfoBarDelegate::TRANSLATION_ERROR, 822 TranslateInfoBarDelegate::TRANSLATION_ERROR,
812 details->error_type, prefs, ShortcutConfig(), details->source_language, 823 details->error_type, prefs, ShortcutConfig(), details->source_language,
813 details->target_language); 824 details->target_language);
825
826 if (details->error_type != TranslateErrors::NONE) {
827 TranslateErrorDetails error_details;
828 error_details.time = base::Time::Now();
829 error_details.url = web_contents->GetActiveURL();
830 error_details.error = details->error_type;
831 NotifyTranslateError(error_details);
832 }
814 } 833 }
815 834
816 bool TranslateManager::IsAcceptLanguage(WebContents* web_contents, 835 bool TranslateManager::IsAcceptLanguage(WebContents* web_contents,
817 const std::string& language) { 836 const std::string& language) {
818 Profile* profile = 837 Profile* profile =
819 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 838 Profile::FromBrowserContext(web_contents->GetBrowserContext());
820 profile = profile->GetOriginalProfile(); 839 profile = profile->GetOriginalProfile();
821 PrefService* pref_service = profile->GetPrefs(); 840 PrefService* pref_service = profile->GetPrefs();
822 PrefServiceLanguagesMap::const_iterator iter = 841 PrefServiceLanguagesMap::const_iterator iter =
823 accept_languages_.find(pref_service); 842 accept_languages_.find(pref_service);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 // reason so we are more aggressive showing the shortcuts for never translate. 1014 // reason so we are more aggressive showing the shortcuts for never translate.
996 #if defined(OS_ANDROID) 1015 #if defined(OS_ANDROID)
997 config.never_translate_min_count = 1; 1016 config.never_translate_min_count = 1;
998 #else 1017 #else
999 config.never_translate_min_count = 3; 1018 config.never_translate_min_count = 3;
1000 #endif // defined(OS_ANDROID) 1019 #endif // defined(OS_ANDROID)
1001 1020
1002 config.always_translate_min_count = 3; 1021 config.always_translate_min_count = 3;
1003 return config; 1022 return config;
1004 } 1023 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698