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

Unified Diff: chrome/browser/translate/translate_tab_helper.h

Issue 187393005: Make it possible to read CLD data from a file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final rebase Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/common.gypi ('k') | chrome/browser/translate/translate_tab_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/translate/translate_tab_helper.h
diff --git a/chrome/browser/translate/translate_tab_helper.h b/chrome/browser/translate/translate_tab_helper.h
index 146ecfd952a1e723e1f23ec6fa757823d91b9fa4..ae237544d9eca3a8b1f2e67b2bd03bcf6b49ae32 100644
--- a/chrome/browser/translate/translate_tab_helper.h
+++ b/chrome/browser/translate/translate_tab_helper.h
@@ -7,7 +7,17 @@
#include <string>
+#if defined(CLD2_DYNAMIC_MODE)
+#include "base/basictypes.h"
+#include "base/lazy_instance.h"
+#endif
#include "base/memory/scoped_ptr.h"
+#if defined(CLD2_DYNAMIC_MODE)
+#include "base/memory/weak_ptr.h"
+#include "base/platform_file.h"
+#include "base/synchronization/lock.h"
+#include "base/task_runner.h"
+#endif
#include "chrome/browser/ui/translate/translate_bubble_model.h"
#include "components/translate/content/browser/content_translate_driver.h"
#include "components/translate/core/browser/translate_client.h"
@@ -101,6 +111,45 @@ class TranslateTabHelper
const std::string& translated_lang,
TranslateErrors::Type error_type);
+#if defined(CLD2_DYNAMIC_MODE)
+ // Called when we receive ChromeViewHostMsg_NeedCLDData from a renderer.
+ // If we have already cached the data, responds immediately; else, enqueues
+ // a HandleCLDDataRequest on the blocking pool to cache the data.
+ // Acquires and releases s_file_lock_ in a non-blocking manner; queries
+ // handled while the file is being cached will gracefully and immediately
+ // fail.
+ // It is up to the originator of the message to poll again later if required;
+ // no "negative response" will be generated.
+ void OnCLDDataRequested();
+
+ // Invoked on the blocking pool in order to cache the data. When successful,
+ // immediately responds to the request that initiated OnCLDDataRequested.
+ // Holds s_file_lock_ while the file is being cached.
+ static void HandleCLDDataRequest();
+
+ // If the CLD data is ready, send it to the renderer. Briefly checks the lock.
+ void MaybeSendCLDDataAvailable();
+
+ // Sends the renderer a response containing the data file handle. No locking.
+ void SendCLDDataAvailable(const base::PlatformFile handle,
+ const uint64 data_offset,
+ const uint64 data_length);
+
+ // Necessary for binding the callback to HandleCLDDataRequest on the blocking
+ // pool.
+ base::WeakPtrFactory<TranslateTabHelper> weak_pointer_factory_;
+
+ // The data file, cached as long as the process stays alive.
+ // We also track the offset at which the data starts, and its length.
+ static base::PlatformFile s_cached_platform_file_; // guarded by file_lock_
+ static uint64 s_cached_data_offset_; // guarded by file_lock_
+ static uint64 s_cached_data_length_; // guarded by file_lock_
+
+ // Guards s_cached_platform_file_
+ static base::LazyInstance<base::Lock> s_file_lock_;
+
+#endif
+
// Shows the translate bubble.
void ShowBubble(TranslateStep step, TranslateErrors::Type error_type);
« no previous file with comments | « build/common.gypi ('k') | chrome/browser/translate/translate_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698