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