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

Side by Side Diff: components/translate/core/browser/translate_ui_delegate.cc

Issue 1977143002: fix the incorrect logging of Translate.{NeverTranslateLang,NeverTranslateSite,AlwaysTranslateLang} … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/translate/core/browser/translate_ui_delegate.h" 5 #include "components/translate/core/browser/translate_ui_delegate.h"
6 6
7 #include "base/i18n/string_compare.h" 7 #include "base/i18n/string_compare.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "components/translate/core/browser/language_state.h" 9 #include "components/translate/core/browser/language_state.h"
10 #include "components/translate/core/browser/translate_client.h" 10 #include "components/translate/core/browser/translate_client.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // translate that page the user can invoke the translate bubble from 259 // translate that page the user can invoke the translate bubble from
260 // the omnibar icon. 260 // the omnibar icon.
261 if (!base::FeatureList::IsEnabled(kTranslateUI2016Q2) && 261 if (!base::FeatureList::IsEnabled(kTranslateUI2016Q2) &&
262 translate_manager_) { 262 translate_manager_) {
263 translate_manager_->GetLanguageState().SetTranslateEnabled(false); 263 translate_manager_->GetLanguageState().SetTranslateEnabled(false);
264 } 264 }
265 } else { 265 } else {
266 prefs_->UnblockLanguage(GetOriginalLanguageCode()); 266 prefs_->UnblockLanguage(GetOriginalLanguageCode());
267 } 267 }
268 268
269 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateLang, true); 269 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateLang, value);
270 } 270 }
271 271
272 bool TranslateUIDelegate::IsSiteBlacklisted() { 272 bool TranslateUIDelegate::IsSiteBlacklisted() {
273 std::string host = GetPageHost(); 273 std::string host = GetPageHost();
274 return !host.empty() && prefs_->IsSiteBlacklisted(host); 274 return !host.empty() && prefs_->IsSiteBlacklisted(host);
275 } 275 }
276 276
277 void TranslateUIDelegate::SetSiteBlacklist(bool value) { 277 void TranslateUIDelegate::SetSiteBlacklist(bool value) {
278 std::string host = GetPageHost(); 278 std::string host = GetPageHost();
279 if (host.empty()) 279 if (host.empty())
280 return; 280 return;
281 281
282 if (value) { 282 if (value) {
283 prefs_->BlacklistSite(host); 283 prefs_->BlacklistSite(host);
284 // In the new UI, we will keep showing the translate omnibar icon 284 // In the new UI, we will keep showing the translate omnibar icon
285 // even if the site is blocked so in case the user just wants to 285 // even if the site is blocked so in case the user just wants to
286 // translate that page the user can invoke the translate bubble from 286 // translate that page the user can invoke the translate bubble from
287 // the omnibar icon. 287 // the omnibar icon.
288 if (!base::FeatureList::IsEnabled(kTranslateUI2016Q2) && 288 if (!base::FeatureList::IsEnabled(kTranslateUI2016Q2) &&
289 translate_manager_) { 289 translate_manager_) {
290 translate_manager_->GetLanguageState().SetTranslateEnabled(false); 290 translate_manager_->GetLanguageState().SetTranslateEnabled(false);
291 } 291 }
292 } else { 292 } else {
293 prefs_->RemoveSiteFromBlacklist(host); 293 prefs_->RemoveSiteFromBlacklist(host);
294 } 294 }
295 295
296 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateSite, true); 296 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateSite, value);
297 } 297 }
298 298
299 bool TranslateUIDelegate::ShouldAlwaysTranslate() { 299 bool TranslateUIDelegate::ShouldAlwaysTranslate() {
300 return prefs_->IsLanguagePairWhitelisted(GetOriginalLanguageCode(), 300 return prefs_->IsLanguagePairWhitelisted(GetOriginalLanguageCode(),
301 GetTargetLanguageCode()); 301 GetTargetLanguageCode());
302 } 302 }
303 303
304 bool TranslateUIDelegate::ShouldAlwaysTranslateBeCheckedByDefault() { 304 bool TranslateUIDelegate::ShouldAlwaysTranslateBeCheckedByDefault() {
305 // After 2 clicks on Translate for the same language. 305 // After 2 clicks on Translate for the same language.
306 // We check for == 2 instead of >= 2 because if the user translates with the 306 // We check for == 2 instead of >= 2 because if the user translates with the
307 // "Always do this?" on, then the next time the bubble won't show up. 307 // "Always do this?" on, then the next time the bubble won't show up.
308 // The only chance the bubble will show up is after the user manually unchecks 308 // The only chance the bubble will show up is after the user manually unchecks
309 // "Always do this?". In that case, since it is after user explictly unchecks, 309 // "Always do this?". In that case, since it is after user explictly unchecks,
310 // we should show as it as unchecked so we only check == 2 instead of >= 2. 310 // we should show as it as unchecked so we only check == 2 instead of >= 2.
311 return ShouldAlwaysTranslate() || 311 return ShouldAlwaysTranslate() ||
312 prefs_->GetTranslationAcceptedCount(GetOriginalLanguageCode()) == 2; 312 prefs_->GetTranslationAcceptedCount(GetOriginalLanguageCode()) == 2;
313 } 313 }
314 314
315 void TranslateUIDelegate::SetAlwaysTranslate(bool value) { 315 void TranslateUIDelegate::SetAlwaysTranslate(bool value) {
316 const std::string& original_lang = GetOriginalLanguageCode(); 316 const std::string& original_lang = GetOriginalLanguageCode();
317 const std::string& target_lang = GetTargetLanguageCode(); 317 const std::string& target_lang = GetTargetLanguageCode();
318 if (value) 318 if (value)
319 prefs_->WhitelistLanguagePair(original_lang, target_lang); 319 prefs_->WhitelistLanguagePair(original_lang, target_lang);
320 else 320 else
321 prefs_->RemoveLanguagePairFromWhitelist(original_lang, target_lang); 321 prefs_->RemoveLanguagePairFromWhitelist(original_lang, target_lang);
322 322
323 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, true); 323 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, value);
324 } 324 }
325 325
326 std::string TranslateUIDelegate::GetPageHost() { 326 std::string TranslateUIDelegate::GetPageHost() {
327 if (!translate_driver_->HasCurrentPage()) 327 if (!translate_driver_->HasCurrentPage())
328 return std::string(); 328 return std::string();
329 return translate_driver_->GetLastCommittedURL().HostNoBrackets(); 329 return translate_driver_->GetLastCommittedURL().HostNoBrackets();
330 } 330 }
331 331
332 } // namespace translate 332 } // namespace translate
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698