 Chromium Code Reviews
 Chromium Code Reviews Issue 187393005:
  Make it possible to read CLD data from a file  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 187393005:
  Make it possible to read CLD data from a file  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: chrome/renderer/translate/translate_helper.h | 
| diff --git a/chrome/renderer/translate/translate_helper.h b/chrome/renderer/translate/translate_helper.h | 
| index 88dd518cf69ab98019089428ef253b0121894002..85a55e4410d15d8f433bb47141910d238a0b1ccc 100644 | 
| --- a/chrome/renderer/translate/translate_helper.h | 
| +++ b/chrome/renderer/translate/translate_helper.h | 
| @@ -7,11 +7,14 @@ | 
| #include <string> | 
| +#include "base/files/memory_mapped_file.h" | 
| #include "base/gtest_prod_util.h" | 
| #include "base/memory/weak_ptr.h" | 
| #include "base/time/time.h" | 
| #include "components/translate/core/common/translate_errors.h" | 
| #include "content/public/renderer/render_view_observer.h" | 
| +#include "ipc/ipc_platform_file.h" | 
| +#include "url/gurl.h" | 
| namespace blink { | 
| class WebDocument; | 
| @@ -29,6 +32,11 @@ class TranslateHelper : public content::RenderViewObserver { | 
| // Informs us that the page's text has been extracted. | 
| void PageCaptured(int page_id, const base::string16& contents); | 
| + // Lets the translation system know that we are preparing to navigate to | 
| + // the specified URL. If there is anything that can or should be done before | 
| + // this URL loads, this is the time to prepare for it. | 
| + void PrepareForUrl(const GURL& url); | 
| + | 
| protected: | 
| // The following methods are protected so they can be overridden in | 
| // unit-tests. | 
| @@ -148,6 +156,60 @@ class TranslateHelper : public content::RenderViewObserver { | 
| // Method factory used to make calls to TranslatePageImpl. | 
| base::WeakPtrFactory<TranslateHelper> weak_method_factory_; | 
| +#if defined(CLD2_DYNAMIC_MODE) | 
| + // Do not ask for CLD data any more. | 
| + void CancelCLD2DataFilePolling(); | 
| + | 
| + // Whether or not polling for CLD2 data has started. | 
| + bool cld2_data_file_polling_started_; | 
| + | 
| + // Whether or not CancelCLD2DataFilePolling has been called. | 
| + bool cld2_data_file_polling_canceled_; | 
| + | 
| + // Whether or not a PageCaptured event arrived prior to CLD data becoming | 
| + // available. If true, deferred_page_id_ contains the most recent page ID | 
| + // and deferred_contents_ contains the most recent contents. | 
| + bool deferred_page_capture_; | 
| + | 
| + // The ID of the page most recently reported to PageCaptured if | 
| + // deferred_page_capture_ is true. | 
| + int deferred_page_id_; | 
| + | 
| + // The contents of the page most recently reported to PageCaptured if | 
| + // deferred_page_capture_ is true. | 
| + base::string16 deferred_contents_; | 
| + | 
| + // The mmap. The mmap dstructor will unmap the memory segment and close the | 
| 
palmer
2014/03/24 19:01:47
Nit: typo "destructor".
 
Andrew Hayden (chromium.org)
2014/03/26 15:34:11
Done.
 | 
| + // file handle; it must be held throughought the lifetime of the process. | 
| 
bulach
2014/03/25 09:29:26
I think valgrind and friends will complain about t
 
Andrew Hayden (chromium.org)
2014/03/26 15:34:11
So.... LazyInstance:Leaky of a pointer? I'll talk
 | 
| + static base::MemoryMappedFile* s_cld2_data_file_mmap_; | 
| 
bulach
2014/03/25 09:29:26
nit: also, please move the fields (164-184) after
 
Andrew Hayden (chromium.org)
2014/03/26 15:34:11
Done.
 | 
| + | 
| + // Invoked when PageCaptured is called prior to obtaining CLD data. This | 
| + // method stores the page ID into deferred_page_id_ and COPIES the contents | 
| + // of the page, then sets deferred_page_capture_ to true. When CLD data is | 
| + // eventually received (in OnCLDDataAvailable), any deferred request will be | 
| + // "resurrected" and allowed to proceed automatically, assuming that the | 
| + // page ID has not changed. | 
| + void DeferPageCaptured(const int page_id, const base::string16& contents); | 
| + | 
| + // Immediately send an IPC request to the browser process to get the CLD | 
| + // data file. In most cases, the file will already exist and we will only | 
| + // poll once; but since the file might need to be downloaded first, poll | 
| + // indefinitely until a ChromeViewMsg_CLDDataAvailable message is received | 
| + // from the browser process. | 
| + // Polling will automatically halt as soon as the renderer obtains a | 
| + // reference to the data file. | 
| + void SendCLD2DataFileRequest(int delay_millis, int next_delay_millis); | 
| + | 
| + // Invoked when a ChromeViewMsg_CLDDataAvailable message is received from | 
| + // the browser process, providing a file handle for the CLD data file. If a | 
| + // PageCaptured request was previously deferred with DeferPageCaptured and | 
| + // the page ID has not yet changed, the PageCaptured is reinvoked to | 
| + // "resurrect" the language detection pathway. | 
| + void OnCLDDataAvailable(IPC::PlatformFileForTransit ipc_file_handle); | 
| + | 
| + // After receiving data in OnCLDDataAvailable, loads the data into CLD2. | 
| + void LoadCLDDData(IPC::PlatformFileForTransit ipc_file_handle); | 
| +#endif | 
| 
palmer
2014/03/24 19:01:47
Nit: Should be a blank line after this.
 
Andrew Hayden (chromium.org)
2014/03/26 15:34:11
Done.
 | 
| DISALLOW_COPY_AND_ASSIGN(TranslateHelper); | 
| }; |