OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_REF_IMPL_H_ | |
6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_REF_IMPL_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/files/file_path.h" | |
12 #include "base/memory/linked_ptr.h" | |
13 #include "ppapi/c/pp_file_info.h" | |
14 #include "ppapi/c/ppb_file_ref.h" | |
15 #include "ppapi/shared_impl/ppb_file_ref_shared.h" | |
16 #include "ppapi/shared_impl/scoped_pp_resource.h" | |
17 #include "ppapi/shared_impl/var.h" | |
18 #include "url/gurl.h" | |
19 #include "webkit/plugins/webkit_plugins_export.h" | |
20 | |
21 namespace webkit { | |
22 namespace ppapi { | |
23 | |
24 using ::ppapi::StringVar; | |
25 | |
26 class PPB_FileSystem_Impl; | |
27 | |
28 class WEBKIT_PLUGINS_EXPORT PPB_FileRef_Impl | |
29 : public ::ppapi::PPB_FileRef_Shared { | |
30 public: | |
31 PPB_FileRef_Impl(const ::ppapi::PPB_FileRef_CreateInfo& info, | |
32 PP_Resource file_system); | |
33 PPB_FileRef_Impl(const ::ppapi::PPB_FileRef_CreateInfo& info, | |
34 const base::FilePath& external_file_path); | |
35 virtual ~PPB_FileRef_Impl(); | |
36 | |
37 // The returned object will have a refcount of 0 (just like "new"). | |
38 static PPB_FileRef_Impl* CreateInternal(PP_Instance instance, | |
39 PP_Resource pp_file_system, | |
40 const std::string& path); | |
41 | |
42 // The returned object will have a refcount of 0 (just like "new"). | |
43 static PPB_FileRef_Impl* CreateExternal( | |
44 PP_Instance instance, | |
45 const base::FilePath& external_file_path, | |
46 const std::string& display_name); | |
47 | |
48 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). | |
49 virtual PP_Resource GetParent() OVERRIDE; | |
50 virtual int32_t MakeDirectory( | |
51 PP_Bool make_ancestors, | |
52 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
53 virtual int32_t Touch( | |
54 PP_Time last_access_time, | |
55 PP_Time last_modified_time, | |
56 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
57 virtual int32_t Delete( | |
58 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
59 virtual int32_t Rename( | |
60 PP_Resource new_file_ref, | |
61 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
62 virtual int32_t Query( | |
63 PP_FileInfo* info, | |
64 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
65 virtual int32_t ReadDirectoryEntries( | |
66 const PP_ArrayOutput& output, | |
67 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
68 virtual int32_t QueryInHost( | |
69 linked_ptr<PP_FileInfo> info, | |
70 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
71 virtual int32_t ReadDirectoryEntriesInHost( | |
72 linked_ptr<std::vector< ::ppapi::PPB_FileRef_CreateInfo> > files, | |
73 linked_ptr<std::vector<PP_FileType> > file_types, | |
74 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
75 virtual PP_Var GetAbsolutePath(); | |
76 | |
77 PP_Resource file_system_resource() const { return file_system_; } | |
78 | |
79 // Returns the system path corresponding to this file. Valid only for | |
80 // external filesystems. | |
81 base::FilePath GetSystemPath() const; | |
82 | |
83 // Returns the FileSystem API URL corresponding to this file. | |
84 GURL GetFileSystemURL() const; | |
85 | |
86 // Checks if file ref has file system instance and if the instance is opened. | |
87 bool HasValidFileSystem() const; | |
88 | |
89 void AddFileSystemRefCount() { | |
90 file_system_ref_ = file_system_; | |
91 } | |
92 | |
93 private: | |
94 // Many mutation functions are allow only to non-external filesystems, This | |
95 // function returns true if the filesystem is opened and isn't external as an | |
96 // access check for these functions. | |
97 bool IsValidNonExternalFileSystem() const; | |
98 | |
99 // 0 for external filesystems. This is a plugin side resource that we don't | |
100 // hold a reference here, so file_system_ could be destroyed earlier than | |
101 // this object. Right now we checked the existance in plugin delegate before | |
102 // use. But it's better to hold a reference once we migrate FileRef to the | |
103 // new design. | |
104 PP_Resource file_system_; | |
105 | |
106 // Holds a reference of FileSystem when running in process. See | |
107 // PPB_FileRef_Proxy for corresponding code for out-of-process mode. Note | |
108 // that this ScopedPPResource is only expected to be used when running in | |
109 // process (since PPB_FileRef_Proxy takes care of out-of-process case). | |
110 // Also note that this workaround will be no longer needed after FileRef | |
111 // refactoring. | |
112 ::ppapi::ScopedPPResource file_system_ref_; | |
113 | |
114 // Used only for external filesystems. | |
115 base::FilePath external_file_system_path_; | |
116 | |
117 // Lazily initialized var created from the external path. This is so we can | |
118 // return the identical string object every time it is requested. | |
119 scoped_refptr<StringVar> external_path_var_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Impl); | |
122 }; | |
123 | |
124 } // namespace ppapi | |
125 } // namespace webkit | |
126 | |
127 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_REF_IMPL_H_ | |
OLD | NEW |