OLD | NEW |
---|---|
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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 } | 215 } |
216 | 216 |
217 void TranslateUIDelegate::RevertTranslation() { | 217 void TranslateUIDelegate::RevertTranslation() { |
218 if (translate_manager_) { | 218 if (translate_manager_) { |
219 translate_manager_->RevertTranslation(); | 219 translate_manager_->RevertTranslation(); |
220 UMA_HISTOGRAM_BOOLEAN(kRevertTranslation, true); | 220 UMA_HISTOGRAM_BOOLEAN(kRevertTranslation, true); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 void TranslateUIDelegate::TranslationDeclined(bool explicitly_closed) { | 224 void TranslateUIDelegate::TranslationDeclined(bool explicitly_closed) { |
225 if (!translate_driver_->IsOffTheRecord()) { | 225 if (explicitly_closed) { |
groby-ooo-7-16
2016/01/28 21:17:28
Overall, I'd prefer it if you'd just add && explic
ftang
2016/01/28 22:37:21
Done.
ftang
2016/01/28 22:37:21
Acknowledged.
| |
226 const std::string& language = GetOriginalLanguageCode(); | 226 if (!translate_driver_->IsOffTheRecord()) { |
227 prefs_->ResetTranslationAcceptedCount(language); | 227 const std::string& language = GetOriginalLanguageCode(); |
228 prefs_->IncrementTranslationDeniedCount(language); | 228 prefs_->ResetTranslationAcceptedCount(language); |
229 prefs_->UpdateLastDeniedTime(language); | 229 prefs_->IncrementTranslationDeniedCount(language); |
230 prefs_->UpdateLastDeniedTime(language); | |
231 } | |
232 | |
233 // Remember that the user declined the translation so as to prevent showing | |
234 // a translate UI for that page again. (TranslateManager initiates | |
235 // translations when getting a LANGUAGE_DETERMINED from the page, which | |
236 // happens when a load stops. That could happen multiple times, including | |
237 // after the user already declined the translation.) | |
238 if (explicitly_closed && translate_manager_) { | |
groby-ooo-7-16
2016/01/28 21:17:28
If you keep this structure, no need to check |expl
ftang
2016/01/28 22:37:21
Done.
| |
239 translate_manager_->GetLanguageState().set_translation_declined(true); | |
240 UMA_HISTOGRAM_BOOLEAN(kDeclineTranslate, true); | |
241 } | |
242 } else { | |
243 UMA_HISTOGRAM_BOOLEAN(kDeclineTranslateDismissUI, true); | |
230 } | 244 } |
231 | |
232 // Remember that the user declined the translation so as to prevent showing a | |
233 // translate UI for that page again. (TranslateManager initiates translations | |
234 // when getting a LANGUAGE_DETERMINED from the page, which happens when a load | |
235 // stops. That could happen multiple times, including after the user already | |
236 // declined the translation.) | |
237 if (translate_manager_) { | |
238 translate_manager_->GetLanguageState().set_translation_declined(true); | |
239 UMA_HISTOGRAM_BOOLEAN(kDeclineTranslate, true); | |
240 } | |
241 | |
242 if (!explicitly_closed) | |
243 UMA_HISTOGRAM_BOOLEAN(kDeclineTranslateDismissUI, true); | |
244 } | 245 } |
245 | 246 |
246 bool TranslateUIDelegate::IsLanguageBlocked() { | 247 bool TranslateUIDelegate::IsLanguageBlocked() { |
247 return prefs_->IsBlockedLanguage(GetOriginalLanguageCode()); | 248 return prefs_->IsBlockedLanguage(GetOriginalLanguageCode()); |
248 } | 249 } |
249 | 250 |
250 void TranslateUIDelegate::SetLanguageBlocked(bool value) { | 251 void TranslateUIDelegate::SetLanguageBlocked(bool value) { |
251 if (value) { | 252 if (value) { |
252 prefs_->BlockLanguage(GetOriginalLanguageCode()); | 253 prefs_->BlockLanguage(GetOriginalLanguageCode()); |
253 if (translate_manager_) { | 254 if (translate_manager_) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, true); | 299 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, true); |
299 } | 300 } |
300 | 301 |
301 std::string TranslateUIDelegate::GetPageHost() { | 302 std::string TranslateUIDelegate::GetPageHost() { |
302 if (!translate_driver_->HasCurrentPage()) | 303 if (!translate_driver_->HasCurrentPage()) |
303 return std::string(); | 304 return std::string(); |
304 return translate_driver_->GetLastCommittedURL().HostNoBrackets(); | 305 return translate_driver_->GetLastCommittedURL().HostNoBrackets(); |
305 } | 306 } |
306 | 307 |
307 } // namespace translate | 308 } // namespace translate |
OLD | NEW |