Commit 97a5a923 authored by rvargas@chromium.org's avatar rvargas@chromium.org

Remove base::kInvalidPlatformFileValue from Chrome

BUG=322664

Review URL: https://codereview.chromium.org/320513002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275542 0039d316-1c4b-4281-b951-d872f2087c98
parent f8964ab9
...@@ -7,10 +7,18 @@ ...@@ -7,10 +7,18 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
namespace {
#if defined(OS_WIN)
const base::PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
#elif defined(OS_POSIX)
const base::PlatformFile kInvalidPlatformFileValue = -1;
#endif
} // namespace
namespace extensions { namespace extensions {
SerialIoHandler::SerialIoHandler() SerialIoHandler::SerialIoHandler()
: file_(base::kInvalidPlatformFileValue), : file_(kInvalidPlatformFileValue),
pending_read_buffer_len_(0), pending_read_buffer_len_(0),
pending_write_buffer_len_(0) { pending_write_buffer_len_(0) {
} }
...@@ -23,7 +31,7 @@ void SerialIoHandler::Initialize(base::PlatformFile file, ...@@ -23,7 +31,7 @@ void SerialIoHandler::Initialize(base::PlatformFile file,
const ReadCompleteCallback& read_callback, const ReadCompleteCallback& read_callback,
const WriteCompleteCallback& write_callback) { const WriteCompleteCallback& write_callback) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_EQ(file_, base::kInvalidPlatformFileValue); DCHECK_EQ(file_, kInvalidPlatformFileValue);
file_ = file; file_ = file;
read_complete_ = read_callback; read_complete_ = read_callback;
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
namespace {
const base::PlatformFile kInvalidPlatformFileValue = -1;
} // namespace
namespace extensions { namespace extensions {
// static // static
...@@ -16,7 +20,7 @@ scoped_refptr<SerialIoHandler> SerialIoHandler::Create() { ...@@ -16,7 +20,7 @@ scoped_refptr<SerialIoHandler> SerialIoHandler::Create() {
void SerialIoHandlerPosix::ReadImpl() { void SerialIoHandlerPosix::ReadImpl() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(pending_read_buffer()); DCHECK(pending_read_buffer());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
EnsureWatchingReads(); EnsureWatchingReads();
} }
...@@ -24,7 +28,7 @@ void SerialIoHandlerPosix::ReadImpl() { ...@@ -24,7 +28,7 @@ void SerialIoHandlerPosix::ReadImpl() {
void SerialIoHandlerPosix::WriteImpl() { void SerialIoHandlerPosix::WriteImpl() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(pending_write_buffer()); DCHECK(pending_write_buffer());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
EnsureWatchingWrites(); EnsureWatchingWrites();
} }
...@@ -98,7 +102,7 @@ void SerialIoHandlerPosix::OnFileCanWriteWithoutBlocking(int fd) { ...@@ -98,7 +102,7 @@ void SerialIoHandlerPosix::OnFileCanWriteWithoutBlocking(int fd) {
void SerialIoHandlerPosix::EnsureWatchingReads() { void SerialIoHandlerPosix::EnsureWatchingReads() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
if (!is_watching_reads_) { if (!is_watching_reads_) {
is_watching_reads_ = base::MessageLoopForIO::current()->WatchFileDescriptor( is_watching_reads_ = base::MessageLoopForIO::current()->WatchFileDescriptor(
file(), true, base::MessageLoopForIO::WATCH_READ, file(), true, base::MessageLoopForIO::WATCH_READ,
...@@ -108,7 +112,7 @@ void SerialIoHandlerPosix::EnsureWatchingReads() { ...@@ -108,7 +112,7 @@ void SerialIoHandlerPosix::EnsureWatchingReads() {
void SerialIoHandlerPosix::EnsureWatchingWrites() { void SerialIoHandlerPosix::EnsureWatchingWrites() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
if (!is_watching_writes_) { if (!is_watching_writes_) {
is_watching_writes_ = is_watching_writes_ =
base::MessageLoopForIO::current()->WatchFileDescriptor( base::MessageLoopForIO::current()->WatchFileDescriptor(
......
...@@ -2,11 +2,15 @@ ...@@ -2,11 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <windows.h>
#include "chrome/browser/extensions/api/serial/serial_io_handler_win.h" #include "chrome/browser/extensions/api/serial/serial_io_handler_win.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include <windows.h> namespace {
const base::PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
} // namespace
namespace extensions { namespace extensions {
...@@ -38,7 +42,7 @@ void SerialIoHandlerWin::InitializeImpl() { ...@@ -38,7 +42,7 @@ void SerialIoHandlerWin::InitializeImpl() {
void SerialIoHandlerWin::ReadImpl() { void SerialIoHandlerWin::ReadImpl() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(pending_read_buffer()); DCHECK(pending_read_buffer());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
DWORD errors; DWORD errors;
COMSTAT status; COMSTAT status;
...@@ -60,7 +64,7 @@ void SerialIoHandlerWin::ReadImpl() { ...@@ -60,7 +64,7 @@ void SerialIoHandlerWin::ReadImpl() {
void SerialIoHandlerWin::WriteImpl() { void SerialIoHandlerWin::WriteImpl() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(pending_write_buffer()); DCHECK(pending_write_buffer());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
BOOL ok = ::WriteFile(file(), BOOL ok = ::WriteFile(file(),
pending_write_buffer()->data(), pending_write_buffer()->data(),
...@@ -73,13 +77,13 @@ void SerialIoHandlerWin::WriteImpl() { ...@@ -73,13 +77,13 @@ void SerialIoHandlerWin::WriteImpl() {
void SerialIoHandlerWin::CancelReadImpl() { void SerialIoHandlerWin::CancelReadImpl() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
::CancelIo(file()); ::CancelIo(file());
} }
void SerialIoHandlerWin::CancelWriteImpl() { void SerialIoHandlerWin::CancelWriteImpl() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_NE(file(), base::kInvalidPlatformFileValue); DCHECK_NE(file(), kInvalidPlatformFileValue);
::CancelIo(file()); ::CancelIo(file());
} }
......
...@@ -138,12 +138,11 @@ void SpellcheckHunspellDictionary::RetryDownloadDictionary( ...@@ -138,12 +138,11 @@ void SpellcheckHunspellDictionary::RetryDownloadDictionary(
} }
bool SpellcheckHunspellDictionary::IsReady() const { bool SpellcheckHunspellDictionary::IsReady() const {
return GetDictionaryFile() != return GetDictionaryFile().IsValid() || IsUsingPlatformChecker();
base::kInvalidPlatformFileValue || IsUsingPlatformChecker();
} }
base::PlatformFile SpellcheckHunspellDictionary::GetDictionaryFile() const { const base::File& SpellcheckHunspellDictionary::GetDictionaryFile() const {
return dictionary_file_.file.GetPlatformFile(); return dictionary_file_.file;
} }
const std::string& SpellcheckHunspellDictionary::GetLanguage() const { const std::string& SpellcheckHunspellDictionary::GetLanguage() const {
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/move.h" #include "base/move.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/platform_file.h"
#include "chrome/browser/spellchecker/spellcheck_dictionary.h" #include "chrome/browser/spellchecker/spellcheck_dictionary.h"
#include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_fetcher_delegate.h"
...@@ -61,8 +60,7 @@ class SpellcheckHunspellDictionary ...@@ -61,8 +60,7 @@ class SpellcheckHunspellDictionary
// Returns true if the dictionary is ready to use. // Returns true if the dictionary is ready to use.
virtual bool IsReady() const; virtual bool IsReady() const;
// TODO(rlp): Return by value. const base::File& GetDictionaryFile() const;
base::PlatformFile GetDictionaryFile() const;
const std::string& GetLanguage() const; const std::string& GetLanguage() const;
bool IsUsingPlatformChecker() const; bool IsUsingPlatformChecker() const;
......
...@@ -165,10 +165,10 @@ void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) { ...@@ -165,10 +165,10 @@ void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) {
PrefService* prefs = user_prefs::UserPrefs::Get(context); PrefService* prefs = user_prefs::UserPrefs::Get(context);
IPC::PlatformFileForTransit file = IPC::InvalidPlatformFileForTransit(); IPC::PlatformFileForTransit file = IPC::InvalidPlatformFileForTransit();
if (hunspell_dictionary_->GetDictionaryFile() != if (hunspell_dictionary_->GetDictionaryFile().IsValid()) {
base::kInvalidPlatformFileValue) {
file = IPC::GetFileHandleForProcess( file = IPC::GetFileHandleForProcess(
hunspell_dictionary_->GetDictionaryFile(), process->GetHandle(), false); hunspell_dictionary_->GetDictionaryFile().GetPlatformFile(),
process->GetHandle(), false);
} }
process->Send(new SpellCheckMsg_Init( process->Send(new SpellCheckMsg_Init(
......
...@@ -626,7 +626,8 @@ void TranslateHelper::OnCLDDataAvailable( ...@@ -626,7 +626,8 @@ void TranslateHelper::OnCLDDataAvailable(
const IPC::PlatformFileForTransit ipc_file_handle, const IPC::PlatformFileForTransit ipc_file_handle,
const uint64 data_offset, const uint64 data_offset,
const uint64 data_length) { const uint64 data_length) {
LoadCLDDData(ipc_file_handle, data_offset, data_length); LoadCLDDData(IPC::PlatformFileForTransitToFile(ipc_file_handle), data_offset,
data_length);
if (deferred_page_capture_ && CLD2::isDataLoaded()) { if (deferred_page_capture_ && CLD2::isDataLoaded()) {
deferred_page_capture_ = false; // Don't do this a second time. deferred_page_capture_ = false; // Don't do this a second time.
PageCaptured(deferred_page_id_, deferred_contents_); PageCaptured(deferred_page_id_, deferred_contents_);
...@@ -636,7 +637,7 @@ void TranslateHelper::OnCLDDataAvailable( ...@@ -636,7 +637,7 @@ void TranslateHelper::OnCLDDataAvailable(
} }
void TranslateHelper::LoadCLDDData( void TranslateHelper::LoadCLDDData(
const IPC::PlatformFileForTransit ipc_file_handle, base::File file,
const uint64 data_offset, const uint64 data_offset,
const uint64 data_length) { const uint64 data_length) {
// Terminate immediately if told to stop polling. // Terminate immediately if told to stop polling.
...@@ -647,18 +648,14 @@ void TranslateHelper::LoadCLDDData( ...@@ -647,18 +648,14 @@ void TranslateHelper::LoadCLDDData(
if (CLD2::isDataLoaded()) if (CLD2::isDataLoaded())
return; return;
// Grab the file handle if (!file.IsValid()) {
base::PlatformFile platform_file =
IPC::PlatformFileForTransitToPlatformFile(ipc_file_handle);
if (platform_file == base::kInvalidPlatformFileValue) {
LOG(ERROR) << "Can't find the CLD data file."; LOG(ERROR) << "Can't find the CLD data file.";
return; return;
} }
base::File basic_file(platform_file);
// mmap the file // mmap the file
s_cld_mmap_.Get().value = new base::MemoryMappedFile(); s_cld_mmap_.Get().value = new base::MemoryMappedFile();
bool initialized = s_cld_mmap_.Get().value->Initialize(basic_file.Pass()); bool initialized = s_cld_mmap_.Get().value->Initialize(file.Pass());
if (!initialized) { if (!initialized) {
LOG(ERROR) << "mmap initialization failed"; LOG(ERROR) << "mmap initialization failed";
delete s_cld_mmap_.Get().value; delete s_cld_mmap_.Get().value;
......
...@@ -7,18 +7,16 @@ ...@@ -7,18 +7,16 @@
#include <string> #include <string>
#if defined(CLD2_DYNAMIC_MODE)
#include "base/files/memory_mapped_file.h"
#endif
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#if defined(CLD2_DYNAMIC_MODE)
#include "base/lazy_instance.h"
#endif
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/translate/core/common/translate_errors.h" #include "components/translate/core/common/translate_errors.h"
#include "content/public/renderer/render_view_observer.h" #include "content/public/renderer/render_view_observer.h"
#if defined(CLD2_DYNAMIC_MODE) #if defined(CLD2_DYNAMIC_MODE)
#include "base/files/file.h"
#include "base/files/memory_mapped_file.h"
#include "base/lazy_instance.h"
#include "ipc/ipc_platform_file.h" #include "ipc/ipc_platform_file.h"
#include "url/gurl.h" #include "url/gurl.h"
#endif #endif
...@@ -195,7 +193,7 @@ class TranslateHelper : public content::RenderViewObserver { ...@@ -195,7 +193,7 @@ class TranslateHelper : public content::RenderViewObserver {
const uint64 data_length); const uint64 data_length);
// After receiving data in OnCLDDataAvailable, loads the data into CLD2. // After receiving data in OnCLDDataAvailable, loads the data into CLD2.
void LoadCLDDData(const IPC::PlatformFileForTransit ipc_file_handle, void LoadCLDDData(base::File file,
const uint64 data_offset, const uint64 data_offset,
const uint64 data_length); const uint64 data_length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment