| 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 CONTENT_RENDERER_PEPPER_PPB_FILE_REF_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PPB_FILE_REF_IMPL_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PPB_FILE_REF_IMPL_H_ | 6 #define CONTENT_RENDERER_PEPPER_PPB_FILE_REF_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/id_map.h" |
| 12 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/platform_file.h" |
| 16 #include "ipc/ipc_listener.h" |
| 17 #include "ipc/ipc_platform_file.h" |
| 13 #include "ppapi/c/pp_file_info.h" | 18 #include "ppapi/c/pp_file_info.h" |
| 14 #include "ppapi/c/ppb_file_ref.h" | 19 #include "ppapi/c/ppb_file_ref.h" |
| 15 #include "ppapi/shared_impl/ppb_file_ref_shared.h" | 20 #include "ppapi/shared_impl/ppb_file_ref_shared.h" |
| 16 #include "ppapi/shared_impl/scoped_pp_resource.h" | 21 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 17 #include "ppapi/shared_impl/var.h" | 22 #include "ppapi/shared_impl/var.h" |
| 18 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 19 | 24 |
| 20 namespace ppapi { | 25 namespace ppapi { |
| 21 namespace host { | 26 namespace host { |
| 22 class ResourceHost; | 27 class ResourceHost; |
| 23 } | 28 } |
| 24 } | 29 } |
| 25 | 30 |
| 26 namespace content { | 31 namespace content { |
| 27 | 32 |
| 28 using ::ppapi::StringVar; | 33 using ::ppapi::StringVar; |
| 29 | 34 |
| 30 class PepperFileSystemHost; | 35 class PepperFileSystemHost; |
| 31 | 36 |
| 32 class PPB_FileRef_Impl : public ::ppapi::PPB_FileRef_Shared { | 37 class PPB_FileRef_Impl : public ::ppapi::PPB_FileRef_Shared, |
| 38 public IPC::Listener { |
| 33 public: | 39 public: |
| 34 PPB_FileRef_Impl(const ::ppapi::PPB_FileRef_CreateInfo& info, | 40 PPB_FileRef_Impl(const ::ppapi::PPB_FileRef_CreateInfo& info, |
| 35 PP_Resource file_system); | 41 PP_Resource file_system); |
| 36 PPB_FileRef_Impl(const ::ppapi::PPB_FileRef_CreateInfo& info, | 42 PPB_FileRef_Impl(const ::ppapi::PPB_FileRef_CreateInfo& info, |
| 37 const base::FilePath& external_file_path); | 43 const base::FilePath& external_file_path); |
| 38 | 44 |
| 39 // The returned object will have a refcount of 0 (just like "new"). | 45 // The returned object will have a refcount of 0 (just like "new"). |
| 40 static PPB_FileRef_Impl* CreateInternal(PP_Instance instance, | 46 static PPB_FileRef_Impl* CreateInternal(PP_Instance instance, |
| 41 PP_Resource pp_file_system, | 47 PP_Resource pp_file_system, |
| 42 const std::string& path); | 48 const std::string& path); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // Checks if file ref has file system instance and if the instance is opened. | 94 // Checks if file ref has file system instance and if the instance is opened. |
| 89 bool HasValidFileSystem() const; | 95 bool HasValidFileSystem() const; |
| 90 | 96 |
| 91 void AddFileSystemRefCount() { | 97 void AddFileSystemRefCount() { |
| 92 file_system_ref_ = file_system_; | 98 file_system_ref_ = file_system_; |
| 93 } | 99 } |
| 94 | 100 |
| 95 private: | 101 private: |
| 96 virtual ~PPB_FileRef_Impl(); | 102 virtual ~PPB_FileRef_Impl(); |
| 97 | 103 |
| 104 // IPC::Listener implementation. |
| 105 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 106 |
| 107 void OnAsyncFileOpened( |
| 108 base::PlatformFileError error_code, |
| 109 IPC::PlatformFileForTransit file_for_transit, |
| 110 int message_id); |
| 111 |
| 98 // Many mutation functions are allow only to non-external filesystems, This | 112 // Many mutation functions are allow only to non-external filesystems, This |
| 99 // function returns true if the filesystem is opened and isn't external as an | 113 // function returns true if the filesystem is opened and isn't external as an |
| 100 // access check for these functions. | 114 // access check for these functions. |
| 101 bool IsValidNonExternalFileSystem() const; | 115 bool IsValidNonExternalFileSystem() const; |
| 102 | 116 |
| 103 PepperFileSystemHost* GetFileSystemHost() const; | 117 PepperFileSystemHost* GetFileSystemHost() const; |
| 104 static PepperFileSystemHost* GetFileSystemHostInternal( | 118 static PepperFileSystemHost* GetFileSystemHostInternal( |
| 105 PP_Instance instance, PP_Resource resource); | 119 PP_Instance instance, PP_Resource resource); |
| 106 | 120 |
| 107 // 0 for external filesystems. This is a plugin side resource that we don't | 121 // 0 for external filesystems. This is a plugin side resource that we don't |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 // refactoring. | 133 // refactoring. |
| 120 ::ppapi::ScopedPPResource file_system_ref_; | 134 ::ppapi::ScopedPPResource file_system_ref_; |
| 121 | 135 |
| 122 // Used only for external filesystems. | 136 // Used only for external filesystems. |
| 123 base::FilePath external_file_system_path_; | 137 base::FilePath external_file_system_path_; |
| 124 | 138 |
| 125 // Lazily initialized var created from the external path. This is so we can | 139 // Lazily initialized var created from the external path. This is so we can |
| 126 // return the identical string object every time it is requested. | 140 // return the identical string object every time it is requested. |
| 127 scoped_refptr<StringVar> external_path_var_; | 141 scoped_refptr<StringVar> external_path_var_; |
| 128 | 142 |
| 143 int routing_id_; |
| 144 |
| 145 typedef base::Callback<void (base::PlatformFileError, base::PassPlatformFile)> |
| 146 AsyncOpenFileCallback; |
| 147 |
| 148 IDMap<AsyncOpenFileCallback> pending_async_open_files_; |
| 149 |
| 129 DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Impl); | 150 DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Impl); |
| 130 }; | 151 }; |
| 131 | 152 |
| 132 } // namespace content | 153 } // namespace content |
| 133 | 154 |
| 134 #endif // CONTENT_RENDERER_PEPPER_PPB_FILE_REF_IMPL_H_ | 155 #endif // CONTENT_RENDERER_PEPPER_PPB_FILE_REF_IMPL_H_ |
| OLD | NEW |