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

Side by Side Diff: components/translate/content/renderer/translate_helper.h

Issue 564793003: Move TranslateHelper to the translate component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@translateBrowserIPC
Patch Set: rebase AGAIN Created 6 years, 3 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
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 COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_
6 #define CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ 6 #define COMPONENTS_TRANSLATE_CONTENT_RENDERER_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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/translate/content/renderer/renderer_cld_data_provider.h" 15 #include "components/translate/content/renderer/renderer_cld_data_provider.h"
16 #include "components/translate/core/common/translate_errors.h" 16 #include "components/translate/core/common/translate_errors.h"
17 #include "content/public/renderer/render_view_observer.h" 17 #include "content/public/renderer/render_view_observer.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace blink { 20 namespace blink {
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 namespace translate {
30
29 // This class deals with page translation. 31 // This class deals with page translation.
30 // There is one TranslateHelper per RenderView. 32 // There is one TranslateHelper per RenderView.
31 // 33 //
32 // This class provides metrics that allow tracking the user experience impact 34 // This class provides metrics that allow tracking the user experience impact
33 // of non-static CldDataProvider implementations. For background on the data 35 // of non-static CldDataProvider implementations. For background on the data
34 // providers, please refer to the following documentation: 36 // providers, please refer to the following documentation:
35 // http://www.chromium.org/developers/how-tos/compact-language-detector-cld-data -source-configuration 37 // http://www.chromium.org/developers/how-tos/compact-language-detector-cld-data -source-configuration
36 // 38 //
37 // Available metrics (from the LanguageDetectionTiming enum): 39 // Available metrics (from the LanguageDetectionTiming enum):
38 // 1. ON_TIME 40 // 1. ON_TIME
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // to detect the language in a timely manner might be completely innocuous. The 72 // 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 73 // 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! 74 // whether it was required or not until after it has been performed!
73 // 75 //
74 // We use histograms for recording these metrics. On Android, the renderer can 76 // 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, 77 // 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 78 // leading to dropped metrics. To work around this, this method forces an IPC
77 // message to be sent to the browser process immediately. 79 // message to be sent to the browser process immediately.
78 class TranslateHelper : public content::RenderViewObserver { 80 class TranslateHelper : public content::RenderViewObserver {
79 public: 81 public:
80 explicit TranslateHelper(content::RenderView* render_view); 82 explicit TranslateHelper(content::RenderView* render_view,
83 int world_id,
84 int extension_group,
85 const std::string& extension_scheme);
81 virtual ~TranslateHelper(); 86 virtual ~TranslateHelper();
82 87
83 // Informs us that the page's text has been extracted. 88 // Informs us that the page's text has been extracted.
84 void PageCaptured(const base::string16& contents); 89 void PageCaptured(const base::string16& contents);
85 90
86 // Lets the translation system know that we are preparing to navigate to 91 // Lets the translation system know that we are preparing to navigate to
87 // the specified URL. If there is anything that can or should be done before 92 // the specified URL. If there is anything that can or should be done before
88 // this URL loads, this is the time to prepare for it. 93 // this URL loads, this is the time to prepare for it.
89 void PrepareForUrl(const GURL& url); 94 void PrepareForUrl(const GURL& url);
90 95
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // notifies the browser accordingly. If the translation has not terminated, 193 // notifies the browser accordingly. If the translation has not terminated,
189 // posts a task to check again later. 194 // posts a task to check again later.
190 void CheckTranslateStatus(int page_seq_no); 195 void CheckTranslateStatus(int page_seq_no);
191 196
192 // Called by TranslatePage to do the actual translation. |count| is used to 197 // Called by TranslatePage to do the actual translation. |count| is used to
193 // limit the number of retries. 198 // limit the number of retries.
194 void TranslatePageImpl(int page_seq_no, int count); 199 void TranslatePageImpl(int page_seq_no, int count);
195 200
196 // Sends a message to the browser to notify it that the translation failed 201 // Sends a message to the browser to notify it that the translation failed
197 // with |error|. 202 // with |error|.
198 void NotifyBrowserTranslationFailed(translate::TranslateErrors::Type error); 203 void NotifyBrowserTranslationFailed(TranslateErrors::Type error);
199 204
200 // Convenience method to access the main frame. Can return NULL, typically 205 // Convenience method to access the main frame. Can return NULL, typically
201 // if the page is being closed. 206 // if the page is being closed.
202 blink::WebFrame* GetMainFrame(); 207 blink::WebFrame* GetMainFrame();
203 208
204 // Do not ask for CLD data any more. 209 // Do not ask for CLD data any more.
205 void CancelCldDataPolling(); 210 void CancelCldDataPolling();
206 211
207 // Invoked when PageCaptured is called prior to obtaining CLD data. This 212 // Invoked when PageCaptured is called prior to obtaining CLD data. This
208 // method stores the page ID into deferred_page_id_ and COPIES the contents 213 // method stores the page ID into deferred_page_id_ and COPIES the contents
(...skipping 23 matching lines...) Expand all
232 // The states associated with the current translation. 237 // The states associated with the current translation.
233 bool translation_pending_; 238 bool translation_pending_;
234 std::string source_lang_; 239 std::string source_lang_;
235 std::string target_lang_; 240 std::string target_lang_;
236 241
237 // Time when a page langauge is determined. This is used to know a duration 242 // Time when a page langauge is determined. This is used to know a duration
238 // time from showing infobar to requesting translation. 243 // time from showing infobar to requesting translation.
239 base::TimeTicks language_determined_time_; 244 base::TimeTicks language_determined_time_;
240 245
241 // Provides CLD data for this process. 246 // Provides CLD data for this process.
242 scoped_ptr<translate::RendererCldDataProvider> cld_data_provider_; 247 scoped_ptr<RendererCldDataProvider> cld_data_provider_;
243 248
244 // Whether or not polling for CLD2 data has started. 249 // Whether or not polling for CLD2 data has started.
245 bool cld_data_polling_started_; 250 bool cld_data_polling_started_;
246 251
247 // Whether or not CancelCldDataPolling has been called. 252 // Whether or not CancelCldDataPolling has been called.
248 bool cld_data_polling_canceled_; 253 bool cld_data_polling_canceled_;
249 254
250 // Whether or not a PageCaptured event arrived prior to CLD data becoming 255 // Whether or not a PageCaptured event arrived prior to CLD data becoming
251 // available. If true, deferred_contents_ contains the most recent contents. 256 // available. If true, deferred_contents_ contains the most recent contents.
252 bool deferred_page_capture_; 257 bool deferred_page_capture_;
253 258
254 // The ID of the page most recently reported to PageCaptured if 259 // The ID of the page most recently reported to PageCaptured if
255 // deferred_page_capture_ is true. 260 // deferred_page_capture_ is true.
256 int deferred_page_seq_no_; 261 int deferred_page_seq_no_;
257 262
263 // The world ID to use for script execution.
264 int world_id_;
265
266 // The extension group.
267 int extension_group_;
268
269 // The URL scheme for translate extensions.
270 std::string extension_scheme_;
271
258 // The contents of the page most recently reported to PageCaptured if 272 // The contents of the page most recently reported to PageCaptured if
259 // deferred_page_capture_ is true. 273 // deferred_page_capture_ is true.
260 base::string16 deferred_contents_; 274 base::string16 deferred_contents_;
261 275
262 // Method factory used to make calls to TranslatePageImpl. 276 // Method factory used to make calls to TranslatePageImpl.
263 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; 277 base::WeakPtrFactory<TranslateHelper> weak_method_factory_;
264 278
265 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); 279 DISALLOW_COPY_AND_ASSIGN(TranslateHelper);
266 }; 280 };
267 281
268 #endif // CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ 282 } // namespace translate
283
284 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_
OLDNEW
« no previous file with comments | « components/translate/content/renderer/DEPS ('k') | components/translate/content/renderer/translate_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698