[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 2e0ec62 | 2014-04-11 07:18:32 | [diff] [blame] | 5 | #ifndef PPAPI_PROXY_FILE_REF_RESOURCE_H_ |
| 6 | #define PPAPI_PROXY_FILE_REF_RESOURCE_H_ |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 7 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 12 | #include "ppapi/c/pp_instance.h" |
| 13 | #include "ppapi/c/pp_resource.h" |
| 14 | #include "ppapi/c/pp_time.h" |
| 15 | #include "ppapi/proxy/plugin_resource.h" |
| 16 | #include "ppapi/proxy/ppapi_proxy_export.h" |
| 17 | #include "ppapi/shared_impl/file_ref_create_info.h" |
[email protected] | 8abbb67 | 2013-07-03 23:30:05 | [diff] [blame] | 18 | #include "ppapi/shared_impl/scoped_pp_resource.h" |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 19 | #include "ppapi/thunk/ppb_file_ref_api.h" |
| 20 | |
| 21 | namespace ppapi { |
| 22 | class StringVar; |
| 23 | |
| 24 | namespace proxy { |
| 25 | |
| 26 | class PPAPI_PROXY_EXPORT FileRefResource |
| 27 | : public PluginResource, |
| 28 | public thunk::PPB_FileRef_API { |
| 29 | public: |
| 30 | static PP_Resource CreateFileRef(Connection connection, |
| 31 | PP_Instance instance, |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 32 | const FileRefCreateInfo& info); |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 33 | |
Peter Boström | 3d5b3cb | 2021-09-23 21:35:45 | [diff] [blame] | 34 | FileRefResource(const FileRefResource&) = delete; |
| 35 | FileRefResource& operator=(const FileRefResource&) = delete; |
| 36 | |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 37 | ~FileRefResource() override; |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 38 | |
| 39 | // Resource implementation. |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 40 | thunk::PPB_FileRef_API* AsPPB_FileRef_API() override; |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 41 | |
| 42 | // PPB_FileRef_API implementation. |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 43 | PP_FileSystemType GetFileSystemType() const override; |
| 44 | PP_Var GetName() const override; |
| 45 | PP_Var GetPath() const override; |
| 46 | PP_Resource GetParent() override; |
| 47 | int32_t MakeDirectory(int32_t make_directory_flags, |
mostynb | 699af3c | 2014-10-06 18:03:34 | [diff] [blame] | 48 | scoped_refptr<TrackedCallback> callback) override; |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 49 | int32_t Touch(PP_Time last_access_time, |
| 50 | PP_Time last_modified_time, |
| 51 | scoped_refptr<TrackedCallback> callback) override; |
| 52 | int32_t Delete(scoped_refptr<TrackedCallback> callback) override; |
| 53 | int32_t Rename(PP_Resource new_file_ref, |
| 54 | scoped_refptr<TrackedCallback> callback) override; |
| 55 | int32_t Query(PP_FileInfo* info, |
| 56 | scoped_refptr<TrackedCallback> callback) override; |
| 57 | int32_t ReadDirectoryEntries( |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 58 | const PP_ArrayOutput& output, |
mostynb | 699af3c | 2014-10-06 18:03:34 | [diff] [blame] | 59 | scoped_refptr<TrackedCallback> callback) override; |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 60 | const FileRefCreateInfo& GetCreateInfo() const override; |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 61 | |
| 62 | // Private API |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 63 | PP_Var GetAbsolutePath() override; |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | FileRefResource(Connection connection, |
| 67 | PP_Instance instance, |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 68 | const FileRefCreateInfo& info); |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 69 | |
| 70 | void RunTrackedCallback(scoped_refptr<TrackedCallback> callback, |
| 71 | const ResourceMessageReplyParams& params); |
| 72 | |
| 73 | void OnQueryReply(PP_FileInfo* out_info, |
| 74 | scoped_refptr<TrackedCallback> callback, |
| 75 | const ResourceMessageReplyParams& params, |
| 76 | const PP_FileInfo& info); |
| 77 | |
| 78 | void OnDirectoryEntriesReply( |
| 79 | const PP_ArrayOutput& output, |
| 80 | scoped_refptr<TrackedCallback> callback, |
| 81 | const ResourceMessageReplyParams& params, |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 82 | const std::vector<ppapi::FileRefCreateInfo>& infos, |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 83 | const std::vector<PP_FileType>& file_types); |
| 84 | |
[email protected] | 2e0ec62 | 2014-04-11 07:18:32 | [diff] [blame] | 85 | bool uses_internal_paths() const; |
| 86 | |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 87 | // Populated after creation. |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 88 | FileRefCreateInfo create_info_; |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 89 | |
[email protected] | 8abbb67 | 2013-07-03 23:30:05 | [diff] [blame] | 90 | // Some file ref operations may fail if the the file system resource inside |
| 91 | // create_info_ is destroyed. Therefore, we explicitly hold a reference to |
| 92 | // the file system resource to make sure it outlives the file ref. |
| 93 | ScopedPPResource file_system_resource_; |
| 94 | |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 95 | scoped_refptr<StringVar> name_var_; |
| 96 | scoped_refptr<StringVar> path_var_; |
| 97 | scoped_refptr<StringVar> absolute_path_var_; |
[email protected] | dc000e8 | 2013-06-26 04:10:41 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace proxy |
| 101 | } // namespace ppapi |
| 102 | |
[email protected] | 2e0ec62 | 2014-04-11 07:18:32 | [diff] [blame] | 103 | #endif // PPAPI_PROXY_FILE_REF_RESOURCE_H_ |