OLD | NEW |
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/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 GURL page_url = web_contents->GetURL(); | 345 GURL page_url = web_contents->GetURL(); |
346 if (!IsTranslatableURL(page_url)) { | 346 if (!IsTranslatableURL(page_url)) { |
347 TranslateBrowserMetrics::ReportInitiationStatus( | 347 TranslateBrowserMetrics::ReportInitiationStatus( |
348 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); | 348 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); |
349 return; | 349 return; |
350 } | 350 } |
351 | 351 |
352 std::string target_lang = GetTargetLanguage(prefs); | 352 std::string target_lang = GetTargetLanguage(prefs); |
353 std::string language_code = GetLanguageCode(page_lang); | 353 std::string language_code = GetLanguageCode(page_lang); |
354 | 354 |
355 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
356 | |
357 // Don't translate similar languages (ex: en-US to en). | 355 // Don't translate similar languages (ex: en-US to en). |
358 if (language_code == target_lang) { | 356 if (language_code == target_lang) { |
359 TranslateBrowserMetrics::ReportInitiationStatus( | 357 TranslateBrowserMetrics::ReportInitiationStatus( |
360 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); | 358 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); |
361 return; | 359 return; |
362 } | 360 } |
363 | 361 |
364 // Don't translate any language the user configured as accepted languages. | |
365 // When the flag --enable-translate-settings is on, the condition is | |
366 // different. In this case, even though a language is an Accept language, | |
367 // it could be translated due to the blacklist. | |
368 if (!command_line->HasSwitch(switches::kEnableTranslateSettings) && | |
369 accept_languages_->IsAcceptLanguage(original_profile, language_code)) { | |
370 TranslateBrowserMetrics::ReportInitiationStatus( | |
371 TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); | |
372 return; | |
373 } | |
374 | |
375 // Nothing to do if either the language Chrome is in or the language of the | 362 // Nothing to do if either the language Chrome is in or the language of the |
376 // page is not supported by the translation server. | 363 // page is not supported by the translation server. |
377 if (target_lang.empty() || !IsSupportedLanguage(language_code)) { | 364 if (target_lang.empty() || !IsSupportedLanguage(language_code)) { |
378 TranslateBrowserMetrics::ReportInitiationStatus( | 365 TranslateBrowserMetrics::ReportInitiationStatus( |
379 TranslateBrowserMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED); | 366 TranslateBrowserMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED); |
380 TranslateBrowserMetrics::ReportUnsupportedLanguageAtInitiation( | 367 TranslateBrowserMetrics::ReportUnsupportedLanguageAtInitiation( |
381 language_code); | 368 language_code); |
382 return; | 369 return; |
383 } | 370 } |
384 | 371 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 // so we are more aggressive about showing the shortcut to never translate. | 712 // so we are more aggressive about showing the shortcut to never translate. |
726 #if defined(OS_ANDROID) | 713 #if defined(OS_ANDROID) |
727 config.never_translate_min_count = 1; | 714 config.never_translate_min_count = 1; |
728 #else | 715 #else |
729 config.never_translate_min_count = 3; | 716 config.never_translate_min_count = 3; |
730 #endif // defined(OS_ANDROID) | 717 #endif // defined(OS_ANDROID) |
731 | 718 |
732 config.always_translate_min_count = 3; | 719 config.always_translate_min_count = 3; |
733 return config; | 720 return config; |
734 } | 721 } |
OLD | NEW |