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

Unified Diff: components/translate/content/browser/data_file_browser_cld_data_provider.cc

Issue 461633002: Refactor language detection logic to allow non-static CLD data sources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge error in chrome/browser/BUILD.gn Created 6 years, 2 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
Index: components/translate/content/browser/data_file_browser_cld_data_provider.cc
diff --git a/components/translate/content/browser/data_file_browser_cld_data_provider.cc b/components/translate/content/browser/data_file_browser_cld_data_provider.cc
index 70648e97e3040a09be916a040b2d980b42ba06d7..452f210ec31aa0a9a5f2e0c7e89ad4e0e71e99c3 100644
--- a/components/translate/content/browser/data_file_browser_cld_data_provider.cc
+++ b/components/translate/content/browser/data_file_browser_cld_data_provider.cc
@@ -2,17 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "data_file_browser_cld_data_provider.h"
+#include "components/translate/content/browser/data_file_browser_cld_data_provider.h"
#include "base/basictypes.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/path_service.h"
+#include "base/process/process_handle.h"
#include "base/synchronization/lock.h"
#include "base/task_runner.h"
+#include "components/translate/content/common/cld_data_source.h"
#include "components/translate/content/common/data_file_cld_data_provider_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
@@ -27,8 +30,8 @@ namespace {
// We also track the offset at which the data starts, and its length.
base::FilePath g_cached_filepath; // guarded by g_file_lock_
base::File* g_cached_file = NULL; // guarded by g_file_lock_
-uint64 g_cached_data_offset = -1; // guarded by g_file_lock_
-uint64 g_cached_data_length = -1; // guarded by g_file_lock_
+uint64 g_cached_data_offset = 0; // guarded by g_file_lock_
+uint64 g_cached_data_length = 0; // guarded by g_file_lock_
// Guards g_cached_filepath
base::LazyInstance<base::Lock> g_file_lock_;
@@ -36,14 +39,6 @@ base::LazyInstance<base::Lock> g_file_lock_;
namespace translate {
-// Implementation of the static factory method from BrowserCldDataProvider,
-// hooking up this specific implementation for all of Chromium.
-BrowserCldDataProvider* CreateBrowserCldDataProviderFor(
- content::WebContents* web_contents) {
- VLOG(1) << "Creating DataFileBrowserCldDataProvider";
- return new DataFileBrowserCldDataProvider(web_contents);
-}
-
void SetCldDataFilePath(const base::FilePath& path) {
VLOG(1) << "Setting CLD data file path to: " << path.value();
base::AutoLock lock(g_file_lock_.Get());
@@ -52,12 +47,15 @@ void SetCldDataFilePath(const base::FilePath& path) {
g_cached_filepath = path;
// For sanity, clean these other values up just in case.
g_cached_file = NULL;
- g_cached_data_length = -1;
- g_cached_data_offset = -1;
+ g_cached_data_length = 0;
+ g_cached_data_offset = 0;
}
base::FilePath GetCldDataFilePath() {
base::AutoLock lock(g_file_lock_.Get());
+ if (g_cached_filepath.empty()) {
+ g_cached_filepath = translate::CldDataSource::Get()->GetCldDataFilePath();
+ }
return g_cached_filepath;
}
@@ -159,7 +157,7 @@ void DataFileBrowserCldDataProvider::SendCldDataResponseInternal(
}
// Data available, respond to the request.
- const int render_process_handle = render_process_host->GetHandle();
+ base::ProcessHandle render_process_handle = render_process_host->GetHandle();
IPC::PlatformFileForTransit ipc_platform_file =
IPC::GetFileHandleForProcess(handle->GetPlatformFile(),
render_process_handle, false);

Powered by Google App Engine
This is Rietveld 408576698