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

Side by Side Diff: ppapi/proxy/file_io_resource.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/file_io_resource.h ('k') | ppapi/proxy/flash_file_resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/file_io_resource.h" 5 #include "ppapi/proxy/file_io_resource.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/task_runner_util.h" 8 #include "base/task_runner_util.h"
9 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHandleHolder> file_handle) 51 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHandleHolder> file_handle)
52 : file_handle_(file_handle) { 52 : file_handle_(file_handle) {
53 DCHECK(file_handle_); 53 DCHECK(file_handle_);
54 } 54 }
55 55
56 FileIOResource::QueryOp::~QueryOp() { 56 FileIOResource::QueryOp::~QueryOp() {
57 } 57 }
58 58
59 int32_t FileIOResource::QueryOp::DoWork() { 59 int32_t FileIOResource::QueryOp::DoWork() {
60 return base::GetPlatformFileInfo(file_handle_->raw_handle(), &file_info_) ? 60 // TODO(rvargas): Convert this code to use base::File.
61 PP_OK : PP_ERROR_FAILED; 61 base::File file(file_handle_->raw_handle());
62 bool success = file.GetInfo(&file_info_);
63 file.TakePlatformFile();
64 return success ? PP_OK : PP_ERROR_FAILED;
62 } 65 }
63 66
64 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHandleHolder> file_handle, 67 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHandleHolder> file_handle,
65 int64_t offset, 68 int64_t offset,
66 int32_t bytes_to_read) 69 int32_t bytes_to_read)
67 : file_handle_(file_handle), 70 : file_handle_(file_handle),
68 offset_(offset), 71 offset_(offset),
69 bytes_to_read_(bytes_to_read) { 72 bytes_to_read_(bytes_to_read) {
70 DCHECK(file_handle_); 73 DCHECK(file_handle_);
71 } 74 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (!info) 184 if (!info)
182 return PP_ERROR_BADARGUMENT; 185 return PP_ERROR_BADARGUMENT;
183 if (!FileHandleHolder::IsValid(file_handle_)) 186 if (!FileHandleHolder::IsValid(file_handle_))
184 return PP_ERROR_FAILED; 187 return PP_ERROR_FAILED;
185 188
186 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 189 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
187 190
188 // If the callback is blocking, perform the task on the calling thread. 191 // If the callback is blocking, perform the task on the calling thread.
189 if (callback->is_blocking()) { 192 if (callback->is_blocking()) {
190 int32_t result = PP_ERROR_FAILED; 193 int32_t result = PP_ERROR_FAILED;
191 base::PlatformFileInfo file_info; 194 base::File::Info file_info;
192 // The plugin could release its reference to this instance when we release 195 // The plugin could release its reference to this instance when we release
193 // the proxy lock below. 196 // the proxy lock below.
194 scoped_refptr<FileIOResource> protect(this); 197 scoped_refptr<FileIOResource> protect(this);
195 { 198 {
196 // Release the proxy lock while making a potentially slow file call. 199 // Release the proxy lock while making a potentially slow file call.
197 ProxyAutoUnlock unlock; 200 ProxyAutoUnlock unlock;
198 if (base::GetPlatformFileInfo(file_handle_->raw_handle(), &file_info)) 201 // TODO(rvargas): Convert this code to base::File.
202 base::File file(file_handle_->raw_handle());
203 bool success = file.GetInfo(&file_info);
204 file.TakePlatformFile();
205 if (success)
199 result = PP_OK; 206 result = PP_OK;
200 } 207 }
201 if (result == PP_OK) { 208 if (result == PP_OK) {
202 // This writes the file info into the plugin's PP_FileInfo struct. 209 // This writes the file info into the plugin's PP_FileInfo struct.
203 ppapi::PlatformFileInfoToPepperFileInfo(file_info, 210 ppapi::FileInfoToPepperFileInfo(file_info,
204 file_system_type_, 211 file_system_type_,
205 info); 212 info);
206 } 213 }
207 state_manager_.SetOperationFinished(); 214 state_manager_.SetOperationFinished();
208 return result; 215 return result;
209 } 216 }
210 217
211 // For the non-blocking case, post a task to the file thread and add a 218 // For the non-blocking case, post a task to the file thread and add a
212 // completion task to write the result. 219 // completion task to write the result.
213 scoped_refptr<QueryOp> query_op(new QueryOp(file_handle_)); 220 scoped_refptr<QueryOp> query_op(new QueryOp(file_handle_));
214 base::PostTaskAndReplyWithResult( 221 base::PostTaskAndReplyWithResult(
215 PpapiGlobals::Get()->GetFileTaskRunner(), 222 PpapiGlobals::Get()->GetFileTaskRunner(),
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 547 }
541 548
542 int32_t FileIOResource::OnQueryComplete(scoped_refptr<QueryOp> query_op, 549 int32_t FileIOResource::OnQueryComplete(scoped_refptr<QueryOp> query_op,
543 PP_FileInfo* info, 550 PP_FileInfo* info,
544 int32_t result) { 551 int32_t result) {
545 DCHECK(state_manager_.get_pending_operation() == 552 DCHECK(state_manager_.get_pending_operation() ==
546 FileIOStateManager::OPERATION_EXCLUSIVE); 553 FileIOStateManager::OPERATION_EXCLUSIVE);
547 554
548 if (result == PP_OK) { 555 if (result == PP_OK) {
549 // This writes the file info into the plugin's PP_FileInfo struct. 556 // This writes the file info into the plugin's PP_FileInfo struct.
550 ppapi::PlatformFileInfoToPepperFileInfo(query_op->file_info(), 557 ppapi::FileInfoToPepperFileInfo(query_op->file_info(),
551 file_system_type_, 558 file_system_type_,
552 info); 559 info);
553 } 560 }
554 state_manager_.SetOperationFinished(); 561 state_manager_.SetOperationFinished();
555 return result; 562 return result;
556 } 563 }
557 564
558 int32_t FileIOResource::OnReadComplete(scoped_refptr<ReadOp> read_op, 565 int32_t FileIOResource::OnReadComplete(scoped_refptr<ReadOp> read_op,
559 PP_ArrayOutput array_output, 566 PP_ArrayOutput array_output,
560 int32_t result) { 567 int32_t result) {
561 DCHECK(state_manager_.get_pending_operation() == 568 DCHECK(state_manager_.get_pending_operation() ==
562 FileIOStateManager::OPERATION_READ); 569 FileIOStateManager::OPERATION_READ);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); 703 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file);
697 704
698 // End this operation now, so the user's callback can execute another FileIO 705 // End this operation now, so the user's callback can execute another FileIO
699 // operation, assuming there are no other pending operations. 706 // operation, assuming there are no other pending operations.
700 state_manager_.SetOperationFinished(); 707 state_manager_.SetOperationFinished();
701 callback->Run(result); 708 callback->Run(result);
702 } 709 }
703 710
704 } // namespace proxy 711 } // namespace proxy
705 } // namespace ppapi 712 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/file_io_resource.h ('k') | ppapi/proxy/flash_file_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698