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

Side by Side Diff: chrome/renderer/translate/translate_helper.h

Issue 387903003: Add metrics for tracking UX impact of non-static CLD data providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/translate/translate_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ 5 #ifndef CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_
6 #define CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ 6 #define CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
(...skipping 10 matching lines...) Expand all
21 class WebDocument; 21 class WebDocument;
22 class WebFrame; 22 class WebFrame;
23 } 23 }
24 24
25 namespace content { 25 namespace content {
26 class RendererCldDataProvider; 26 class RendererCldDataProvider;
27 } 27 }
28 28
29 // This class deals with page translation. 29 // This class deals with page translation.
30 // There is one TranslateHelper per RenderView. 30 // There is one TranslateHelper per RenderView.
31 31 //
32 // This class provides metrics that allow tracking the user experience impact
33 // of non-static CldDataProvider implementations. For background on the data
34 // providers, please refer to the following documentation:
35 // http://www.chromium.org/developers/how-tos/compact-language-detector-cld-data -source-configuration
36 //
37 // Available metrics (from the LanguageDetectionTiming enum):
38 // 1. ON_TIME
39 // Recorded if PageCaptured(...) is invoked after CLD is available. This is
40 // the ideal case, indicating that CLD is available before it is needed.
41 // 2. DEFERRED
42 // Recorded if PageCaptured(...) is invoked before CLD is available.
43 // Sub-optimal case indicating that CLD wasn't available when it was needed,
44 // so the request for detection has been deferred until CLD is available or
45 // until the user navigates to a different page.
46 // 3. RESUMED
47 // Recorded if CLD becomes available after a language detection request was
48 // deferred, but before the user navigated to a different page. Language
49 // detection is ultimately completed, it just didn't happen on time.
50 //
51 // Note that there is NOT a metric that records the number of times that
52 // language detection had to be aborted because CLD never became available in
53 // time. This is because there is no reasonable way to cover all the cases
54 // under which this could occur, particularly the destruction of the renderer
55 // for which this object was created. However, this value can be synthetically
56 // derived, using the logic below.
57 //
58 // Every page load that triggers language detection will result in the
59 // recording of exactly one of the first two events: ON_TIME or DEFERRED. If
60 // CLD is available in time to satisfy the request, the third event (RESUMED)
61 // will be recorded; thus, the number of times when language detection
62 // ultimately fails because CLD isn't ever available is implied as the number of
63 // times that detection is deferred minus the number of times that language
64 // detection is late:
65 //
66 // count(FAILED) ~= count(DEFERRED) - count(RESUMED)
67 //
68 // Note that this is not 100% accurate: some renderer process are so short-lived
69 // that language detection wouldn't have been relevant anyway, and so a failure
70 // to detect the language in a timely manner might be completely innocuous. The
71 // overall problem with language detection is that it isn't possible to know
72 // whether it was required or not until after it has been performed!
73 //
74 // We use histograms for recording these metrics. On Android, the renderer can
75 // be killed without the chance to clean up or transmit these histograms,
76 // leading to dropped metrics. To work around this, this method forces an IPC
77 // message to be sent to the browser process immediately.
32 class TranslateHelper : public content::RenderViewObserver { 78 class TranslateHelper : public content::RenderViewObserver {
33 public: 79 public:
34 explicit TranslateHelper(content::RenderView* render_view); 80 explicit TranslateHelper(content::RenderView* render_view);
35 virtual ~TranslateHelper(); 81 virtual ~TranslateHelper();
36 82
37 // Informs us that the page's text has been extracted. 83 // Informs us that the page's text has been extracted.
38 void PageCaptured(const base::string16& contents); 84 void PageCaptured(const base::string16& contents);
39 85
40 // Lets the translation system know that we are preparing to navigate to 86 // Lets the translation system know that we are preparing to navigate to
41 // the specified URL. If there is anything that can or should be done before 87 // the specified URL. If there is anything that can or should be done before
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, 152 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest,
107 CLDDisagreeWithWrongLanguageCode); 153 CLDDisagreeWithWrongLanguageCode);
108 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, 154 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest,
109 InvalidLanguageMetaTagProviding); 155 InvalidLanguageMetaTagProviding);
110 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, LanguageCodeTypoCorrection); 156 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, LanguageCodeTypoCorrection);
111 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, LanguageCodeSynonyms); 157 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, LanguageCodeSynonyms);
112 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, ResetInvalidLanguageCode); 158 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, ResetInvalidLanguageCode);
113 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, SimilarLanguageCode); 159 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, SimilarLanguageCode);
114 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, WellKnownWrongConfiguration); 160 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, WellKnownWrongConfiguration);
115 161
162 enum LanguageDetectionTiming {
163 ON_TIME, // Language detection was performed as soon as it was requested
164 DEFERRED, // Language detection couldn't be performed when it was requested
165 RESUMED, // A deferred language detection attempt was completed later
166 LANGUAGE_DETECTION_TIMING_MAX_VALUE // bounding value for this enum
Alexei Svitkine (slow) 2014/07/17 14:39:03 Nit: Use full sentences - capitalized and terminat
167 };
168
116 // Converts language code to the one used in server supporting list. 169 // Converts language code to the one used in server supporting list.
117 static void ConvertLanguageCodeSynonym(std::string* code); 170 static void ConvertLanguageCodeSynonym(std::string* code);
118 171
119 // Returns whether the page associated with |document| is a candidate for 172 // Returns whether the page associated with |document| is a candidate for
120 // translation. Some pages can explictly specify (via a meta-tag) that they 173 // translation. Some pages can explictly specify (via a meta-tag) that they
121 // should not be translated. 174 // should not be translated.
122 static bool IsTranslationAllowed(blink::WebDocument* document); 175 static bool IsTranslationAllowed(blink::WebDocument* document);
123 176
124 // RenderViewObserver implementation. 177 // RenderViewObserver implementation.
125 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 178 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 void DeferPageCaptured(const int page_id, const base::string16& contents); 213 void DeferPageCaptured(const int page_id, const base::string16& contents);
161 214
162 // Start polling for CLD data. 215 // Start polling for CLD data.
163 // Polling will automatically halt as soon as the renderer obtains a 216 // Polling will automatically halt as soon as the renderer obtains a
164 // reference to the data file. 217 // reference to the data file.
165 void SendCldDataRequest(const int delay_millis, const int next_delay_millis); 218 void SendCldDataRequest(const int delay_millis, const int next_delay_millis);
166 219
167 // Callback triggered when CLD data becomes available. 220 // Callback triggered when CLD data becomes available.
168 void OnCldDataAvailable(); 221 void OnCldDataAvailable();
169 222
223 // Record the timing of language detection, immediately sending an IPC-based
224 // histogram delta update to the browser process in case the hosting renderer
225 // process terminates before the metrics would otherwise be transferred.
226 void RecordLanguageDetectionTiming(LanguageDetectionTiming);
Alexei Svitkine (slow) 2014/07/17 14:39:03 Since this is Chromium code (and not blink), pleas
227
170 // An ever-increasing sequence number of the current page, used to match up 228 // An ever-increasing sequence number of the current page, used to match up
171 // translation requests with responses. 229 // translation requests with responses.
172 int page_seq_no_; 230 int page_seq_no_;
173 231
174 // The states associated with the current translation. 232 // The states associated with the current translation.
175 bool translation_pending_; 233 bool translation_pending_;
176 std::string source_lang_; 234 std::string source_lang_;
177 std::string target_lang_; 235 std::string target_lang_;
178 236
179 // Time when a page langauge is determined. This is used to know a duration 237 // Time when a page langauge is determined. This is used to know a duration
(...skipping 21 matching lines...) Expand all
201 int deferred_page_seq_no_; 259 int deferred_page_seq_no_;
202 260
203 // The contents of the page most recently reported to PageCaptured if 261 // The contents of the page most recently reported to PageCaptured if
204 // deferred_page_capture_ is true. 262 // deferred_page_capture_ is true.
205 base::string16 deferred_contents_; 263 base::string16 deferred_contents_;
206 264
207 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); 265 DISALLOW_COPY_AND_ASSIGN(TranslateHelper);
208 }; 266 };
209 267
210 #endif // CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ 268 #endif // CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/translate/translate_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698