Chromium Code Reviews| Index: chrome/renderer/translate/translate_helper.cc |
| diff --git a/chrome/renderer/translate/translate_helper.cc b/chrome/renderer/translate/translate_helper.cc |
| index cffcfc55d92e040870ff44f43a00362d74e1cde9..587a38194082f0f1d11e0deb58f162110675fba9 100644 |
| --- a/chrome/renderer/translate/translate_helper.cc |
| +++ b/chrome/renderer/translate/translate_helper.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/compiler_specific.h" |
| #include "base/logging.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/metrics/user_metrics_action.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -17,6 +18,7 @@ |
| #include "components/translate/core/common/translate_metrics.h" |
| #include "components/translate/core/common/translate_util.h" |
| #include "components/translate/core/language_detection/language_detection_util.h" |
| +#include "content/public/renderer/render_thread.h" |
| #include "content/public/renderer/render_view.h" |
| #include "extensions/common/constants.h" |
| #include "extensions/renderer/extension_groups.h" |
| @@ -45,6 +47,48 @@ using blink::WebString; |
| using blink::WebVector; |
| using blink::WebView; |
| +// Note on metrics: |
| +// |
| +// This class provides metrics that allow tracking the user experience impact |
| +// of non-static CldDataProvider implementations. For background on the data |
| +// providers, please refer to the following documentation: |
| +// http://www.chromium.org/developers/how-tos/compact-language-detector-cld-data-source-configuration |
| +// |
| +// Available metrics: |
| +// 1. Translate.LanguageDetectionOnTime |
| +// Recorded if PageCaptured(...) is invoked after CLD is available. |
| +// This is the ideal case, indicating that CLD is available before it is |
| +// needed. |
| +// 2. Translate.LanguageDetectionDeferred |
| +// Recorded if PageCaptured(...) is invoked before CLD is available. |
| +// Sub-optimal case indicating that CLD wasn't available when it was |
| +// needed, so the request for detection has been deferred until CLD is |
| +// available or until the user navigates to a different page. |
| +// 3. Translate.LanguageDetectionLate |
| +// Recorded if CLD becomes available after a language detection request |
| +// was deferred as above in (2), but before the user navigated to a |
| +// different page. Language detection is ultimately completed, it just |
| +// didn't happen on time. |
| +// |
| +// Note that there is NOT a metric that records the number of times that |
| +// language detection had to be aborted because CLD never became available in |
| +// time. This is because there is no reasonable way to cover all the cases |
| +// under which this could occur, particularly the destruction of the renderer |
| +// for which this object was created. However, this value can be synthetically |
| +// derived, using the logic below. |
| +// |
| +// Every page load that triggers language detection will result in the |
| +// recording of exactly one of the first two metrics in the list above: |
| +// Translate.LanguageDetectionOnTime or Translate.LanguageDetectionDeferred. |
| +// If CLD is available in time to satisfy the request, the third metric |
| +// (Translate.LanguageDetectionLate) will be recorded; thus, the number of |
| +// times when language detection ultimately fails because CLD isn't ever |
| +// available is implied as the number of times that detection is deferred minus |
| +// the number of times that language detection is late. Note that this, too, |
| +// is not necessarily 100% relevant: some renderer process are so short-lived |
| +// that language detection wouldn't have been relevant anywaysm and so a failure |
|
Andrew Hayden (chromium.org)
2014/07/14 14:24:13
"anywaysm" -> "anyways,"
simonb1
2014/07/14 16:23:48
"anyways" -> "anyway" :-)
http://www.dailywritingt
|
| +// to detect the language in a timely manner might be completely innocuous. |
| + |
| namespace { |
| // The delay in milliseconds that we'll wait before checking to see if the |
| @@ -88,7 +132,6 @@ TranslateHelper::TranslateHelper(content::RenderView* render_view) |
| TranslateHelper::~TranslateHelper() { |
| CancelPendingTranslation(); |
| - CancelCldDataPolling(); |
| } |
| void TranslateHelper::PrepareForUrl(const GURL& url) { |
| @@ -140,17 +183,28 @@ void TranslateHelper::PageCapturedImpl(int page_seq_no, |
| if (!main_frame || page_seq_no_ != page_seq_no) |
| return; |
| - // TODO(andrewhayden): UMA insertion point here: Track if data is available. |
| - // TODO(andrewhayden): Retry insertion point here, retry till data available. |
| if (!cld_data_provider_->IsCldDataAvailable()) { |
| // We're in dynamic mode and CLD data isn't loaded. Retry when CLD data |
| // is loaded, if ever. |
| deferred_page_capture_ = true; |
| deferred_page_seq_no_ = page_seq_no; |
| deferred_contents_ = contents; |
| + content::RenderThread::Get()->RecordAction( |
| + base::UserMetricsAction("Translate.LanguageDetectionDeferred")); |
| return; |
| } |
| + if (deferred_page_seq_no_ == -1) { |
| + // CLD data was available before language detection was requested. |
| + content::RenderThread::Get()->RecordAction( |
| + base::UserMetricsAction("Translate.LanguageDetectionOnTime")); |
| + } else { |
| + // This is a request that was triggered because CLD data is now available |
| + // and was previously deferred. |
| + content::RenderThread::Get()->RecordAction( |
| + base::UserMetricsAction("Translate.LanguageDetectionLate")); |
| + } |
| + |
| WebDocument document = main_frame->document(); |
| std::string content_language = document.contentLanguage().utf8(); |
| WebElement html_element = document.documentElement(); |