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