Commit 7744e736 authored by rvargas@chromium.org's avatar rvargas@chromium.org

Remove PlatformFile from components/nacl

BUG=322664

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274783 0039d316-1c4b-4281-b951-d872f2087c98
parent 7e20df51
......@@ -132,14 +132,16 @@ void NaClHostMessageFilter::OnNaClCreateTemporaryFile(
void NaClHostMessageFilter::AsyncReturnTemporaryFile(
int pp_instance,
base::PlatformFile fd,
const base::File& file,
bool is_hit) {
Send(new NaClViewMsg_NexeTempFileReply(
pp_instance,
is_hit,
IPC::PlatformFileForTransit fd = IPC::InvalidPlatformFileForTransit();
if (file.IsValid()) {
// Don't close our copy of the handle, because PnaclHost will use it
// when the translation finishes.
IPC::GetFileHandleForProcess(fd, PeerHandle(), false)));
fd = IPC::GetFileHandleForProcess(file.GetPlatformFile(), PeerHandle(),
false);
}
Send(new NaClViewMsg_NexeTempFileReply(pp_instance, is_hit, fd));
}
void NaClHostMessageFilter::OnNaClGetNumProcessors(int* num_processors) {
......
......@@ -65,7 +65,7 @@ class NaClHostMessageFilter : public content::BrowserMessageFilter {
void SyncReturnTemporaryFile(IPC::Message* reply_msg,
base::File file);
void AsyncReturnTemporaryFile(int pp_instance,
base::PlatformFile fd,
const base::File& file,
bool is_hit);
void OnNaClDebugEnabledForURL(const GURL& nmf_url, bool* should_debug);
......
This diff is collapsed.
......@@ -32,7 +32,7 @@ class PnaclTranslationCache;
class PnaclHost {
public:
typedef base::Callback<void(base::File)> TempFileCallback;
typedef base::Callback<void(base::PlatformFile, bool is_hit)> NexeFdCallback;
typedef base::Callback<void(const base::File&, bool is_hit)> NexeFdCallback;
static PnaclHost* GetInstance();
......@@ -102,6 +102,7 @@ class PnaclHost {
// so that the BrowsingDataRemover can clear it even if no translation has
// ever been started.
friend struct DefaultSingletonTraits<PnaclHost>;
friend class FileProxy;
friend class pnacl::PnaclHostTest;
friend class pnacl::PnaclHostTestDisk;
enum CacheState {
......@@ -115,7 +116,7 @@ class PnaclHost {
~PendingTranslation();
base::ProcessHandle process_handle;
int render_view_id;
base::PlatformFile nexe_fd;
base::File* nexe_fd;
bool got_nexe_fd;
bool got_cache_reply;
bool got_cache_hit;
......@@ -149,16 +150,16 @@ class PnaclHost {
// GetNexeFd miss path
void ReturnMiss(const PendingTranslationMap::iterator& entry);
static scoped_refptr<net::DrainableIOBuffer> CopyFileToBuffer(
base::PlatformFile fd);
scoped_ptr<base::File> file);
void StoreTranslatedNexe(TranslationID id,
scoped_refptr<net::DrainableIOBuffer>);
void OnTranslatedNexeStored(const TranslationID& id, int net_error);
void RequeryMatchingTranslations(const std::string& key);
// GetNexeFd hit path
static int CopyBufferToFile(base::PlatformFile fd,
scoped_refptr<net::DrainableIOBuffer> buffer);
void OnBufferCopiedToTempFile(const TranslationID& id, int file_error);
void OnBufferCopiedToTempFile(const TranslationID& id,
scoped_ptr<base::File> file,
int file_error);
void OnEntriesDoomed(const base::Closure& callback, int net_error);
......
......@@ -67,24 +67,26 @@ class PnaclHostTest : public testing::Test {
// CallbackExpectMiss checks that the fd is valid and a miss is reported,
// and also writes some data into the file, which is read back by
// CallbackExpectHit
void CallbackExpectMiss(base::PlatformFile fd, bool is_hit) {
void CallbackExpectMiss(const base::File& file, bool is_hit) {
EXPECT_FALSE(is_hit);
ASSERT_FALSE(fd == base::kInvalidPlatformFileValue);
base::PlatformFileInfo info;
EXPECT_TRUE(base::GetPlatformFileInfo(fd, &info));
ASSERT_TRUE(file.IsValid());
base::File::Info info;
base::File* mutable_file = const_cast<base::File*>(&file);
EXPECT_TRUE(mutable_file->GetInfo(&info));
EXPECT_FALSE(info.is_directory);
EXPECT_EQ(0LL, info.size);
char str[16];
memset(str, 0x0, 16);
snprintf(str, 16, "testdata%d", ++write_callback_count_);
EXPECT_EQ(16, base::WritePlatformFile(fd, 0, str, 16));
EXPECT_EQ(16, mutable_file->Write(0, str, 16));
temp_callback_count_++;
}
void CallbackExpectHit(base::PlatformFile fd, bool is_hit) {
void CallbackExpectHit(const base::File& file, bool is_hit) {
EXPECT_TRUE(is_hit);
ASSERT_FALSE(fd == base::kInvalidPlatformFileValue);
base::PlatformFileInfo info;
EXPECT_TRUE(base::GetPlatformFileInfo(fd, &info));
ASSERT_TRUE(file.IsValid());
base::File::Info info;
base::File* mutable_file = const_cast<base::File*>(&file);
EXPECT_TRUE(mutable_file->GetInfo(&info));
EXPECT_FALSE(info.is_directory);
EXPECT_EQ(16LL, info.size);
char data[16];
......@@ -92,7 +94,7 @@ class PnaclHostTest : public testing::Test {
char str[16];
memset(str, 0x0, 16);
snprintf(str, 16, "testdata%d", write_callback_count_);
EXPECT_EQ(16, base::ReadPlatformFile(fd, 0, data, 16));
EXPECT_EQ(16, mutable_file->Read(0, data, 16));
EXPECT_STREQ(str, data);
temp_callback_count_++;
}
......
......@@ -5,7 +5,6 @@
#include "components/nacl/renderer/file_downloader.h"
#include "base/callback.h"
#include "base/platform_file.h"
#include "components/nacl/renderer/nexe_load_manager.h"
#include "net/base/net_errors.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
......@@ -15,11 +14,11 @@
namespace nacl {
FileDownloader::FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader,
base::PlatformFile file,
base::File file,
StatusCallback status_cb,
ProgressCallback progress_cb)
: url_loader_(url_loader.Pass()),
file_(file),
file_(file.Pass()),
status_cb_(status_cb),
progress_cb_(progress_cb),
http_status_code_(-1),
......@@ -55,8 +54,7 @@ void FileDownloader::didReceiveData(
int data_length,
int encoded_data_length) {
if (status_ == SUCCESS) {
if (base::WritePlatformFile(file_, total_bytes_received_, data,
data_length) == -1) {
if (file_.Write(total_bytes_received_, data, data_length) == -1) {
status_ = FAILED;
return;
}
......@@ -73,10 +71,10 @@ void FileDownloader::didFinishLoading(
if (status_ == SUCCESS) {
// Seek back to the beginning of the file that was just written so it's
// easy for consumers to use.
if (base::SeekPlatformFile(file_, base::PLATFORM_FILE_FROM_BEGIN, 0) != 0)
if (file_.Seek(base::File::FROM_BEGIN, 0) != 0)
status_ = FAILED;
}
status_cb_.Run(status_, http_status_code_);
status_cb_.Run(status_, file_.Pass(), http_status_code_);
delete this;
}
......
......@@ -28,14 +28,14 @@ class FileDownloader : public blink::WebURLLoaderClient {
};
// Provides the FileDownloader status and the HTTP status code.
typedef base::Callback<void(Status, int)> StatusCallback;
typedef base::Callback<void(Status, base::File, int)> StatusCallback;
// Provides the bytes received so far, and the total bytes expected to be
// received.
typedef base::Callback<void(int64_t, int64_t)> ProgressCallback;
FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader,
base::PlatformFile file,
base::File file,
StatusCallback status_cb,
ProgressCallback progress_cb);
......@@ -58,7 +58,7 @@ class FileDownloader : public blink::WebURLLoaderClient {
const blink::WebURLError& error);
scoped_ptr<blink::WebURLLoader> url_loader_;
base::PlatformFile file_;
base::File file_;
StatusCallback status_cb_;
ProgressCallback progress_cb_;
int http_status_code_;
......
......@@ -107,7 +107,7 @@ NexeLoadManager::~NexeLoadManager() {
}
void NexeLoadManager::NexeFileDidOpen(int32_t pp_error,
base::PlatformFile file,
const base::File& file,
int32_t http_status,
int64_t nexe_bytes_read,
const std::string& url,
......@@ -120,7 +120,7 @@ void NexeLoadManager::NexeFileDidOpen(int32_t pp_error,
"NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp",
http_status);
if (pp_error != PP_OK || file == base::kInvalidPlatformFileValue) {
if (pp_error != PP_OK || !file.IsValid()) {
if (pp_error == PP_ERROR_ABORTED) {
ReportLoadAbort();
} else if (pp_error == PP_ERROR_NOACCESS) {
......
......@@ -8,10 +8,10 @@
#include <map>
#include <string>
#include "base/files/file.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "base/time/time.h"
#include "ppapi/c/private/ppb_nacl_private.h"
#include "url/gurl.h"
......@@ -33,7 +33,7 @@ class NexeLoadManager {
~NexeLoadManager();
void NexeFileDidOpen(int32_t pp_error,
base::PlatformFile file,
const base::File& file,
int32_t http_status,
int64_t nexe_bytes_read,
const std::string& url,
......
......@@ -129,14 +129,14 @@ void PnaclTranslationResourceHost::OnNexeTempFileReply(
bool is_hit,
IPC::PlatformFileForTransit file) {
DCHECK(io_message_loop_->BelongsToCurrentThread());
base::File base_file = IPC::PlatformFileForTransitToFile(file);
CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance);
int32_t status = PP_ERROR_FAILED;
// Handle the expected successful case first.
if (it != pending_cache_requests_.end() &&
!(file == IPC::InvalidPlatformFileForTransit()) &&
if (it != pending_cache_requests_.end() && base_file.IsValid() &&
TrackedCallback::IsPending(it->second.callback)) {
*it->second.is_hit = PP_FromBool(is_hit);
*it->second.file_handle = IPC::PlatformFileForTransitToPlatformFile(file);
*it->second.file_handle = base_file.TakePlatformFile();
status = PP_OK;
}
if (it == pending_cache_requests_.end()) {
......@@ -147,10 +147,8 @@ void PnaclTranslationResourceHost::OnNexeTempFileReply(
base::Bind(&TrackedCallback::Run, it->second.callback, status));
pending_cache_requests_.erase(it);
}
if (file == IPC::InvalidPlatformFileForTransit()) {
if (!base_file.IsValid()) {
DLOG(ERROR) << "Got invalid platformfilefortransit";
} else if (status != PP_OK) {
base::ClosePlatformFile(IPC::PlatformFileForTransitToPlatformFile(file));
}
}
......
......@@ -553,14 +553,12 @@ PP_FileHandle GetReadonlyPnaclFd(const char* url) {
if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD(
std::string(filename),
&out_fd))) {
return base::kInvalidPlatformFileValue;
return PP_kInvalidFileHandle;
}
if (out_fd == IPC::InvalidPlatformFileForTransit()) {
return base::kInvalidPlatformFileValue;
return PP_kInvalidFileHandle;
}
base::PlatformFile handle =
IPC::PlatformFileForTransitToPlatformFile(out_fd);
return handle;
return IPC::PlatformFileForTransitToPlatformFile(out_fd);
}
PP_FileHandle CreateTemporaryFile(PP_Instance instance) {
......@@ -569,16 +567,14 @@ PP_FileHandle CreateTemporaryFile(PP_Instance instance) {
DCHECK(sender);
if (!sender->Send(new NaClHostMsg_NaClCreateTemporaryFile(
&transit_fd))) {
return base::kInvalidPlatformFileValue;
return PP_kInvalidFileHandle;
}
if (transit_fd == IPC::InvalidPlatformFileForTransit()) {
return base::kInvalidPlatformFileValue;
return PP_kInvalidFileHandle;
}
base::PlatformFile handle = IPC::PlatformFileForTransitToPlatformFile(
transit_fd);
return handle;
return IPC::PlatformFileForTransitToPlatformFile(transit_fd);
}
int32_t GetNumberOfProcessors() {
......@@ -700,16 +696,13 @@ PP_FileHandle OpenNaClExecutable(PP_Instance instance,
&out_fd,
nonce_lo,
nonce_hi))) {
return base::kInvalidPlatformFileValue;
return PP_kInvalidFileHandle;
}
if (out_fd == IPC::InvalidPlatformFileForTransit()) {
return base::kInvalidPlatformFileValue;
}
if (out_fd == IPC::InvalidPlatformFileForTransit())
return PP_kInvalidFileHandle;
base::PlatformFile handle =
IPC::PlatformFileForTransitToPlatformFile(out_fd);
return handle;
return IPC::PlatformFileForTransitToPlatformFile(out_fd);
}
void DispatchEvent(PP_Instance instance,
......@@ -1127,8 +1120,8 @@ PP_Bool GetPNaClResourceInfo(PP_Instance instance,
if (!load_manager)
return PP_FALSE;
base::PlatformFile file = GetReadonlyPnaclFd(filename);
if (file == base::kInvalidPlatformFileValue) {
base::File file(GetReadonlyPnaclFd(filename));
if (!file.IsValid()) {
load_manager->ReportLoadError(
PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
"The Portable Native Client (pnacl) component is not "
......@@ -1137,8 +1130,8 @@ PP_Bool GetPNaClResourceInfo(PP_Instance instance,
return PP_FALSE;
}
base::PlatformFileInfo file_info;
if (!GetPlatformFileInfo(file, &file_info)) {
base::File::Info file_info;
if (!file.GetInfo(&file_info)) {
load_manager->ReportLoadError(
PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
std::string("GetPNaClResourceInfo, GetFileInfo failed for: ") +
......@@ -1162,7 +1155,7 @@ PP_Bool GetPNaClResourceInfo(PP_Instance instance,
return PP_FALSE;
}
int rc = base::ReadPlatformFile(file, 0, buffer.get(), file_info.size);
int rc = file.Read(0, buffer.get(), file_info.size);
if (rc < 0) {
load_manager->ReportLoadError(
PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
......@@ -1315,9 +1308,9 @@ class ProgressEventRateLimiter {
};
void DownloadNexeCompletion(const DownloadNexeRequest& request,
base::PlatformFile target_file,
PP_NaClFileInfo* out_file_info,
FileDownloader::Status status,
base::File target_file,
int http_status);
void DownloadNexe(PP_Instance instance,
......@@ -1339,16 +1332,16 @@ void DownloadNexe(PP_Instance instance,
&out_file_info->token_hi);
if (handle != PP_kInvalidFileHandle) {
DownloadNexeCompletion(request,
handle,
out_file_info,
FileDownloader::SUCCESS,
base::File(handle),
200);
return;
}
// The fast path didn't work, we'll fetch the file using URLLoader and write
// it to local storage.
base::PlatformFile target_file = CreateTemporaryFile(instance);
base::File target_file(CreateTemporaryFile(instance));
GURL gurl(url);
content::PepperPluginInstance* plugin_instance =
......@@ -1370,31 +1363,28 @@ void DownloadNexe(PP_Instance instance,
// FileDownloader deletes itself after invoking DownloadNexeCompletion.
FileDownloader* file_downloader = new FileDownloader(
url_loader.Pass(),
target_file,
base::Bind(&DownloadNexeCompletion, request, target_file, out_file_info),
target_file.Pass(),
base::Bind(&DownloadNexeCompletion, request, out_file_info),
base::Bind(&ProgressEventRateLimiter::ReportProgress,
base::Owned(tracker), url));
file_downloader->Load(url_request);
}
void DownloadNexeCompletion(const DownloadNexeRequest& request,
base::PlatformFile target_file,
PP_NaClFileInfo* out_file_info,
FileDownloader::Status status,
base::File target_file,
int http_status) {
int32_t pp_error = FileDownloaderToPepperError(status);
if (pp_error == PP_OK)
out_file_info->handle = target_file;
int64_t bytes_read = -1;
if (pp_error == PP_OK && target_file != base::kInvalidPlatformFileValue) {
base::PlatformFileInfo info;
if (GetPlatformFileInfo(target_file, &info))
if (pp_error == PP_OK && target_file.IsValid()) {
base::File::Info info;
if (target_file.GetInfo(&info))
bytes_read = info.size;
}
if (bytes_read == -1) {
base::ClosePlatformFile(target_file);
target_file.Close();
pp_error = PP_ERROR_FAILED;
}
......@@ -1410,17 +1400,22 @@ void DownloadNexeCompletion(const DownloadNexeRequest& request,
download_time);
}
if (pp_error == PP_OK && target_file.IsValid())
out_file_info->handle = target_file.TakePlatformFile();
else
out_file_info->handle = PP_kInvalidFileHandle;
request.callback.func(request.callback.user_data, pp_error);
}
void DownloadFileCompletion(base::PlatformFile file,
PP_NaClFileInfo* file_info,
void DownloadFileCompletion(PP_NaClFileInfo* file_info,
PP_CompletionCallback callback,
FileDownloader::Status status,
base::File file,
int http_status) {
int32_t pp_error = FileDownloaderToPepperError(status);
if (pp_error == PP_OK) {
file_info->handle = file;
file_info->handle = file.TakePlatformFile();
file_info->token_lo = 0;
file_info->token_hi = 0;
}
......@@ -1499,7 +1494,7 @@ void DownloadFile(PP_Instance instance,
// The fast path didn't work, we'll fetch the file using URLLoader and write
// it to local storage.
base::PlatformFile target_file = CreateTemporaryFile(instance);
base::File target_file(CreateTemporaryFile(instance));
GURL gurl(url);
content::PepperPluginInstance* plugin_instance =
......@@ -1521,8 +1516,8 @@ void DownloadFile(PP_Instance instance,
// FileDownloader deletes itself after invoking DownloadNexeCompletion.
FileDownloader* file_downloader = new FileDownloader(
url_loader.Pass(),
target_file,
base::Bind(&DownloadFileCompletion, target_file, file_info, callback),
target_file.Pass(),
base::Bind(&DownloadFileCompletion, file_info, callback),
base::Bind(&ProgressEventRateLimiter::ReportProgress,
base::Owned(tracker), url));
file_downloader->Load(url_request);
......
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