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 "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/thunk/enter.h" | 11 #include "ppapi/thunk/enter.h" |
12 #include "ppapi/thunk/ppb_file_system_api.h" | 12 #include "ppapi/thunk/ppb_file_system_api.h" |
13 #include "ppapi/shared_impl/time_conversion.h" | 13 #include "ppapi/shared_impl/time_conversion.h" |
14 #include "ppapi/shared_impl/var.h" | 14 #include "ppapi/shared_impl/var.h" |
15 #include "webkit/plugins/ppapi/common.h" | 15 #include "webkit/plugins/ppapi/common.h" |
16 #include "webkit/plugins/ppapi/file_callbacks.h" | 16 #include "webkit/plugins/ppapi/file_callbacks.h" |
17 #include "webkit/plugins/ppapi/plugin_delegate.h" | 17 #include "webkit/plugins/ppapi/plugin_delegate.h" |
18 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" | 20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | 21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
22 #include "webkit/plugins/ppapi/resource_helper.h" | 22 #include "webkit/plugins/ppapi/resource_helper.h" |
23 | 23 |
| 24 using ppapi::ApiCallbackType; |
24 using ppapi::HostResource; | 25 using ppapi::HostResource; |
25 using ppapi::PPB_FileRef_CreateInfo; | 26 using ppapi::PPB_FileRef_CreateInfo; |
26 using ppapi::PPTimeToTime; | 27 using ppapi::PPTimeToTime; |
27 using ppapi::StringVar; | 28 using ppapi::StringVar; |
28 using ppapi::thunk::EnterResourceNoLock; | 29 using ppapi::thunk::EnterResourceNoLock; |
29 using ppapi::thunk::PPB_FileRef_API; | 30 using ppapi::thunk::PPB_FileRef_API; |
30 using ppapi::thunk::PPB_FileSystem_API; | 31 using ppapi::thunk::PPB_FileSystem_API; |
31 | 32 |
32 namespace webkit { | 33 namespace webkit { |
33 namespace ppapi { | 34 namespace ppapi { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 std::string parent_path = virtual_path.substr(0, pos); | 156 std::string parent_path = virtual_path.substr(0, pos); |
156 | 157 |
157 scoped_refptr<PPB_FileRef_Impl> parent_ref( | 158 scoped_refptr<PPB_FileRef_Impl> parent_ref( |
158 CreateInternal(file_system_->pp_resource(), parent_path)); | 159 CreateInternal(file_system_->pp_resource(), parent_path)); |
159 if (!parent_ref.get()) | 160 if (!parent_ref.get()) |
160 return 0; | 161 return 0; |
161 return parent_ref->GetReference(); | 162 return parent_ref->GetReference(); |
162 } | 163 } |
163 | 164 |
164 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, | 165 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, |
165 PP_CompletionCallback callback) { | 166 ::ppapi::ApiCallbackType callback) { |
166 if (!callback.func) | |
167 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
168 if (!IsValidNonExternalFileSystem()) | 167 if (!IsValidNonExternalFileSystem()) |
169 return PP_ERROR_NOACCESS; | 168 return PP_ERROR_NOACCESS; |
170 | 169 |
171 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 170 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
172 if (!plugin_instance) | 171 if (!plugin_instance) |
173 return PP_ERROR_FAILED; | 172 return PP_ERROR_FAILED; |
174 if (!plugin_instance->delegate()->MakeDirectory( | 173 if (!plugin_instance->delegate()->MakeDirectory( |
175 GetFileSystemURL(), PP_ToBool(make_ancestors), | 174 GetFileSystemURL(), PP_ToBool(make_ancestors), |
176 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 175 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
177 return PP_ERROR_FAILED; | 176 return PP_ERROR_FAILED; |
178 return PP_OK_COMPLETIONPENDING; | 177 return PP_OK_COMPLETIONPENDING; |
179 } | 178 } |
180 | 179 |
181 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, | 180 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, |
182 PP_Time last_modified_time, | 181 PP_Time last_modified_time, |
183 PP_CompletionCallback callback) { | 182 ::ppapi::ApiCallbackType callback) { |
184 if (!callback.func) | |
185 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
186 if (!IsValidNonExternalFileSystem()) | 183 if (!IsValidNonExternalFileSystem()) |
187 return PP_ERROR_NOACCESS; | 184 return PP_ERROR_NOACCESS; |
188 | 185 |
189 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 186 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
190 if (!plugin_instance) | 187 if (!plugin_instance) |
191 return PP_ERROR_FAILED; | 188 return PP_ERROR_FAILED; |
192 if (!plugin_instance->delegate()->Touch( | 189 if (!plugin_instance->delegate()->Touch( |
193 GetFileSystemURL(), | 190 GetFileSystemURL(), |
194 PPTimeToTime(last_access_time), | 191 PPTimeToTime(last_access_time), |
195 PPTimeToTime(last_modified_time), | 192 PPTimeToTime(last_modified_time), |
196 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 193 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
197 return PP_ERROR_FAILED; | 194 return PP_ERROR_FAILED; |
198 return PP_OK_COMPLETIONPENDING; | 195 return PP_OK_COMPLETIONPENDING; |
199 } | 196 } |
200 | 197 |
201 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { | 198 int32_t PPB_FileRef_Impl::Delete(::ppapi::ApiCallbackType callback) { |
202 if (!callback.func) | |
203 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
204 if (!IsValidNonExternalFileSystem()) | 199 if (!IsValidNonExternalFileSystem()) |
205 return PP_ERROR_NOACCESS; | 200 return PP_ERROR_NOACCESS; |
206 | 201 |
207 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 202 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
208 if (!plugin_instance) | 203 if (!plugin_instance) |
209 return PP_ERROR_FAILED; | 204 return PP_ERROR_FAILED; |
210 if (!plugin_instance->delegate()->Delete( | 205 if (!plugin_instance->delegate()->Delete( |
211 GetFileSystemURL(), | 206 GetFileSystemURL(), |
212 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 207 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
213 return PP_ERROR_FAILED; | 208 return PP_ERROR_FAILED; |
214 return PP_OK_COMPLETIONPENDING; | 209 return PP_OK_COMPLETIONPENDING; |
215 } | 210 } |
216 | 211 |
217 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, | 212 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, |
218 PP_CompletionCallback callback) { | 213 ::ppapi::ApiCallbackType callback) { |
219 if (!callback.func) | |
220 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
221 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); | 214 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); |
222 if (enter.failed()) | 215 if (enter.failed()) |
223 return PP_ERROR_BADRESOURCE; | 216 return PP_ERROR_BADRESOURCE; |
224 PPB_FileRef_Impl* new_file_ref = | 217 PPB_FileRef_Impl* new_file_ref = |
225 static_cast<PPB_FileRef_Impl*>(enter.object()); | 218 static_cast<PPB_FileRef_Impl*>(enter.object()); |
226 | 219 |
227 if (!IsValidNonExternalFileSystem() || | 220 if (!IsValidNonExternalFileSystem() || |
228 file_system_.get() != new_file_ref->file_system_.get()) | 221 file_system_.get() != new_file_ref->file_system_.get()) |
229 return PP_ERROR_NOACCESS; | 222 return PP_ERROR_NOACCESS; |
230 | 223 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 return file_system_ && file_system_->opened(); | 274 return file_system_ && file_system_->opened(); |
282 } | 275 } |
283 | 276 |
284 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | 277 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { |
285 return file_system_ && file_system_->opened() && | 278 return file_system_ && file_system_->opened() && |
286 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | 279 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; |
287 } | 280 } |
288 | 281 |
289 } // namespace ppapi | 282 } // namespace ppapi |
290 } // namespace webkit | 283 } // namespace webkit |
OLD | NEW |