OLD | NEW |
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" |
11 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
12 #include "ppapi/shared_impl/array_writer.h" | 12 #include "ppapi/shared_impl/array_writer.h" |
13 #include "ppapi/shared_impl/file_ref_create_info.h" | 13 #include "ppapi/shared_impl/file_ref_create_info.h" |
14 #include "ppapi/shared_impl/file_system_util.h" | 14 #include "ppapi/shared_impl/file_system_util.h" |
15 #include "ppapi/shared_impl/file_type_conversion.h" | 15 #include "ppapi/shared_impl/file_type_conversion.h" |
16 #include "ppapi/shared_impl/ppapi_globals.h" | 16 #include "ppapi/shared_impl/ppapi_globals.h" |
17 #include "ppapi/shared_impl/proxy_lock.h" | 17 #include "ppapi/shared_impl/proxy_lock.h" |
18 #include "ppapi/shared_impl/resource_tracker.h" | 18 #include "ppapi/shared_impl/resource_tracker.h" |
19 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
20 #include "ppapi/thunk/ppb_file_ref_api.h" | 20 #include "ppapi/thunk/ppb_file_ref_api.h" |
| 21 #include "ppapi/thunk/ppb_file_system_api.h" |
21 | 22 |
22 using ppapi::thunk::EnterResourceNoLock; | 23 using ppapi::thunk::EnterResourceNoLock; |
23 using ppapi::thunk::PPB_FileIO_API; | 24 using ppapi::thunk::PPB_FileIO_API; |
24 using ppapi::thunk::PPB_FileRef_API; | 25 using ppapi::thunk::PPB_FileRef_API; |
| 26 using ppapi::thunk::PPB_FileSystem_API; |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 // We must allocate a buffer sized according to the request of the plugin. To | 30 // We must allocate a buffer sized according to the request of the plugin. To |
29 // reduce the chance of out-of-memory errors, we cap the read and write size to | 31 // reduce the chance of out-of-memory errors, we cap the read and write size to |
30 // 32MB. This is OK since the API specifies that it may perform a partial read | 32 // 32MB. This is OK since the API specifies that it may perform a partial read |
31 // or write. | 33 // or write. |
32 static const int32_t kMaxReadWriteSize = 32 * 1024 * 1024; // 32MB | 34 static const int32_t kMaxReadWriteSize = 32 * 1024 * 1024; // 32MB |
33 | 35 |
34 // An adapter to let Read() share the same implementation with ReadToArray(). | 36 // An adapter to let Read() share the same implementation with ReadToArray(). |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 FileIOResource::~FileIOResource() { | 89 FileIOResource::~FileIOResource() { |
88 } | 90 } |
89 | 91 |
90 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { | 92 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { |
91 return this; | 93 return this; |
92 } | 94 } |
93 | 95 |
94 int32_t FileIOResource::Open(PP_Resource file_ref, | 96 int32_t FileIOResource::Open(PP_Resource file_ref, |
95 int32_t open_flags, | 97 int32_t open_flags, |
96 scoped_refptr<TrackedCallback> callback) { | 98 scoped_refptr<TrackedCallback> callback) { |
97 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); | 99 EnterResourceNoLock<PPB_FileRef_API> enter_file_ref(file_ref, true); |
98 if (enter.failed()) | 100 if (enter_file_ref.failed()) |
99 return PP_ERROR_BADRESOURCE; | 101 return PP_ERROR_BADRESOURCE; |
100 | 102 |
101 PPB_FileRef_API* file_ref_api = enter.object(); | 103 PPB_FileRef_API* file_ref_api = enter_file_ref.object(); |
102 const FileRefCreateInfo& create_info = file_ref_api->GetCreateInfo(); | 104 const FileRefCreateInfo& create_info = file_ref_api->GetCreateInfo(); |
103 if (!FileSystemTypeIsValid(create_info.file_system_type)) { | 105 if (!FileSystemTypeIsValid(create_info.file_system_type)) { |
104 NOTREACHED(); | 106 NOTREACHED(); |
105 return PP_ERROR_FAILED; | 107 return PP_ERROR_FAILED; |
106 } | 108 } |
107 | |
108 int32_t rv = state_manager_.CheckOperationState( | 109 int32_t rv = state_manager_.CheckOperationState( |
109 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 110 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
110 if (rv != PP_OK) | 111 if (rv != PP_OK) |
111 return rv; | 112 return rv; |
112 | 113 |
113 file_system_type_ = create_info.file_system_type; | 114 file_system_type_ = create_info.file_system_type; |
114 // Keep the FileSystem host alive by taking a reference to its resource. The | 115 |
115 // FileIO host uses the FileSystem host for running tasks. | 116 if (create_info.file_system_plugin_resource) { |
116 file_system_resource_ = create_info.file_system_plugin_resource; | 117 EnterResourceNoLock<PPB_FileSystem_API> enter_file_system( |
| 118 create_info.file_system_plugin_resource, true); |
| 119 if (enter_file_system.failed()) |
| 120 return PP_ERROR_FAILED; |
| 121 // Take a reference on the FileSystem resource. The FileIO host uses the |
| 122 // FileSystem host for running tasks and checking quota. |
| 123 file_system_resource_ = enter_file_system.resource(); |
| 124 } |
117 | 125 |
118 // Take a reference on the FileRef resource while we're opening the file; we | 126 // Take a reference on the FileRef resource while we're opening the file; we |
119 // don't want the plugin destroying it during the Open operation. | 127 // don't want the plugin destroying it during the Open operation. |
120 file_ref_ = enter.resource(); | 128 file_ref_ = enter_file_ref.resource(); |
121 | 129 |
122 Call<PpapiPluginMsg_FileIO_OpenReply>(BROWSER, | 130 Call<PpapiPluginMsg_FileIO_OpenReply>(BROWSER, |
123 PpapiHostMsg_FileIO_Open( | 131 PpapiHostMsg_FileIO_Open( |
124 file_ref, | 132 file_ref, |
125 open_flags), | 133 open_flags), |
126 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, | 134 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, |
127 callback)); | 135 callback)); |
128 | 136 |
129 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 137 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
130 return PP_OK_COMPLETIONPENDING; | 138 return PP_OK_COMPLETIONPENDING; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 465 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
458 | 466 |
459 // End this operation now, so the user's callback can execute another FileIO | 467 // End this operation now, so the user's callback can execute another FileIO |
460 // operation, assuming there are no other pending operations. | 468 // operation, assuming there are no other pending operations. |
461 state_manager_.SetOperationFinished(); | 469 state_manager_.SetOperationFinished(); |
462 callback->Run(result); | 470 callback->Run(result); |
463 } | 471 } |
464 | 472 |
465 } // namespace proxy | 473 } // namespace proxy |
466 } // namespace ppapi | 474 } // namespace ppapi |
OLD | NEW |