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