OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "content/browser/renderer_host/pepper/quota_reservation.h" | 15 #include "content/browser/renderer_host/pepper/quota_reservation.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "ppapi/c/pp_file_info.h" | 17 #include "ppapi/c/pp_file_info.h" |
18 #include "ppapi/c/private/ppb_isolated_file_system_private.h" | 18 #include "ppapi/c/private/ppb_isolated_file_system_private.h" |
19 #include "ppapi/host/host_message_context.h" | 19 #include "ppapi/host/host_message_context.h" |
20 #include "ppapi/host/resource_host.h" | 20 #include "ppapi/host/resource_host.h" |
21 #include "ppapi/shared_impl/file_growth.h" | 21 #include "ppapi/shared_impl/file_growth.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 #include "webkit/browser/fileapi/file_system_context.h" | 23 #include "storage/browser/fileapi/file_system_context.h" |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 class BrowserPpapiHost; | 27 class BrowserPpapiHost; |
28 class PepperFileIOHost; | 28 class PepperFileIOHost; |
29 | 29 |
30 class CONTENT_EXPORT PepperFileSystemBrowserHost | 30 class CONTENT_EXPORT PepperFileSystemBrowserHost |
31 : public ppapi::host::ResourceHost, | 31 : public ppapi::host::ResourceHost, |
32 public base::SupportsWeakPtr<PepperFileSystemBrowserHost> { | 32 public base::SupportsWeakPtr<PepperFileSystemBrowserHost> { |
33 public: | 33 public: |
(...skipping 14 matching lines...) Expand all Loading... |
48 // ppapi::host::ResourceHost overrides. | 48 // ppapi::host::ResourceHost overrides. |
49 virtual int32_t OnResourceMessageReceived( | 49 virtual int32_t OnResourceMessageReceived( |
50 const IPC::Message& msg, | 50 const IPC::Message& msg, |
51 ppapi::host::HostMessageContext* context) OVERRIDE; | 51 ppapi::host::HostMessageContext* context) OVERRIDE; |
52 virtual bool IsFileSystemHost() OVERRIDE; | 52 virtual bool IsFileSystemHost() OVERRIDE; |
53 | 53 |
54 // Supports FileRefs direct access on the host side. | 54 // Supports FileRefs direct access on the host side. |
55 PP_FileSystemType GetType() const { return type_; } | 55 PP_FileSystemType GetType() const { return type_; } |
56 bool IsOpened() const { return opened_; } | 56 bool IsOpened() const { return opened_; } |
57 GURL GetRootUrl() const { return root_url_; } | 57 GURL GetRootUrl() const { return root_url_; } |
58 scoped_refptr<fileapi::FileSystemContext> GetFileSystemContext() const { | 58 scoped_refptr<storage::FileSystemContext> GetFileSystemContext() const { |
59 return file_system_context_; | 59 return file_system_context_; |
60 } | 60 } |
61 | 61 |
62 // Supports FileIOs direct access on the host side. | 62 // Supports FileIOs direct access on the host side. |
63 // Non-NULL only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. | 63 // Non-NULL only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. |
64 fileapi::FileSystemOperationRunner* GetFileSystemOperationRunner() const { | 64 storage::FileSystemOperationRunner* GetFileSystemOperationRunner() const { |
65 return file_system_operation_runner_.get(); | 65 return file_system_operation_runner_.get(); |
66 } | 66 } |
67 bool ChecksQuota() const { return quota_reservation_ != NULL; } | 67 bool ChecksQuota() const { return quota_reservation_ != NULL; } |
68 // Opens a file for writing with quota checks. Returns the file size in the | 68 // Opens a file for writing with quota checks. Returns the file size in the |
69 // callback. | 69 // callback. |
70 typedef base::Callback<void(int64_t)> OpenQuotaFileCallback; | 70 typedef base::Callback<void(int64_t)> OpenQuotaFileCallback; |
71 void OpenQuotaFile(PepperFileIOHost* file_io_host, | 71 void OpenQuotaFile(PepperFileIOHost* file_io_host, |
72 const fileapi::FileSystemURL& url, | 72 const storage::FileSystemURL& url, |
73 const OpenQuotaFileCallback& callback); | 73 const OpenQuotaFileCallback& callback); |
74 // Closes the file. This must be called after OpenQuotaFile and before the | 74 // Closes the file. This must be called after OpenQuotaFile and before the |
75 // PepperFileIOHost is destroyed. | 75 // PepperFileIOHost is destroyed. |
76 void CloseQuotaFile(PepperFileIOHost* file_io_host, | 76 void CloseQuotaFile(PepperFileIOHost* file_io_host, |
77 const ppapi::FileGrowth& file_growth); | 77 const ppapi::FileGrowth& file_growth); |
78 | 78 |
79 private: | 79 private: |
80 friend class PepperFileSystemBrowserHostTest; | 80 friend class PepperFileSystemBrowserHostTest; |
81 | 81 |
82 void OpenExistingFileSystem( | 82 void OpenExistingFileSystem( |
83 const base::Closure& callback, | 83 const base::Closure& callback, |
84 scoped_refptr<fileapi::FileSystemContext> file_system_context); | 84 scoped_refptr<storage::FileSystemContext> file_system_context); |
85 void OpenFileSystem( | 85 void OpenFileSystem( |
86 ppapi::host::ReplyMessageContext reply_context, | 86 ppapi::host::ReplyMessageContext reply_context, |
87 fileapi::FileSystemType file_system_type, | 87 storage::FileSystemType file_system_type, |
88 scoped_refptr<fileapi::FileSystemContext> file_system_context); | 88 scoped_refptr<storage::FileSystemContext> file_system_context); |
89 void OpenFileSystemComplete(ppapi::host::ReplyMessageContext reply_context, | 89 void OpenFileSystemComplete(ppapi::host::ReplyMessageContext reply_context, |
90 const GURL& root, | 90 const GURL& root, |
91 const std::string& name, | 91 const std::string& name, |
92 base::File::Error error); | 92 base::File::Error error); |
93 void OpenIsolatedFileSystem( | 93 void OpenIsolatedFileSystem( |
94 ppapi::host::ReplyMessageContext reply_context, | 94 ppapi::host::ReplyMessageContext reply_context, |
95 const std::string& fsid, | 95 const std::string& fsid, |
96 PP_IsolatedFileSystemType_Private type, | 96 PP_IsolatedFileSystemType_Private type, |
97 scoped_refptr<fileapi::FileSystemContext> file_system_context); | 97 scoped_refptr<storage::FileSystemContext> file_system_context); |
98 void OpenPluginPrivateFileSystem( | 98 void OpenPluginPrivateFileSystem( |
99 ppapi::host::ReplyMessageContext reply_context, | 99 ppapi::host::ReplyMessageContext reply_context, |
100 const std::string& fsid, | 100 const std::string& fsid, |
101 scoped_refptr<fileapi::FileSystemContext> file_system_context); | 101 scoped_refptr<storage::FileSystemContext> file_system_context); |
102 void OpenPluginPrivateFileSystemComplete( | 102 void OpenPluginPrivateFileSystemComplete( |
103 ppapi::host::ReplyMessageContext reply_context, | 103 ppapi::host::ReplyMessageContext reply_context, |
104 const std::string& fsid, | 104 const std::string& fsid, |
105 base::File::Error error); | 105 base::File::Error error); |
106 | 106 |
107 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, | 107 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, |
108 int64_t expected_size); | 108 int64_t expected_size); |
109 int32_t OnHostMsgInitIsolatedFileSystem( | 109 int32_t OnHostMsgInitIsolatedFileSystem( |
110 ppapi::host::HostMessageContext* context, | 110 ppapi::host::HostMessageContext* context, |
111 const std::string& fsid, | 111 const std::string& fsid, |
112 PP_IsolatedFileSystemType_Private type); | 112 PP_IsolatedFileSystemType_Private type); |
113 int32_t OnHostMsgReserveQuota(ppapi::host::HostMessageContext* context, | 113 int32_t OnHostMsgReserveQuota(ppapi::host::HostMessageContext* context, |
114 int64_t amount, | 114 int64_t amount, |
115 const ppapi::FileGrowthMap& file_growths); | 115 const ppapi::FileGrowthMap& file_growths); |
116 | 116 |
117 void SendReplyForFileSystem(ppapi::host::ReplyMessageContext reply_context, | 117 void SendReplyForFileSystem(ppapi::host::ReplyMessageContext reply_context, |
118 int32_t pp_error); | 118 int32_t pp_error); |
119 void SendReplyForIsolatedFileSystem( | 119 void SendReplyForIsolatedFileSystem( |
120 ppapi::host::ReplyMessageContext reply_context, | 120 ppapi::host::ReplyMessageContext reply_context, |
121 const std::string& fsid, | 121 const std::string& fsid, |
122 int32_t error); | 122 int32_t error); |
123 | 123 |
124 void SetFileSystemContext( | 124 void SetFileSystemContext( |
125 scoped_refptr<fileapi::FileSystemContext> file_system_context); | 125 scoped_refptr<storage::FileSystemContext> file_system_context); |
126 | 126 |
127 bool ShouldCreateQuotaReservation() const; | 127 bool ShouldCreateQuotaReservation() const; |
128 void CreateQuotaReservation(const base::Closure& callback); | 128 void CreateQuotaReservation(const base::Closure& callback); |
129 void GotQuotaReservation(const base::Closure& callback, | 129 void GotQuotaReservation(const base::Closure& callback, |
130 scoped_refptr<QuotaReservation> quota_reservation); | 130 scoped_refptr<QuotaReservation> quota_reservation); |
131 | 131 |
132 void GotReservedQuota(ppapi::host::ReplyMessageContext reply_context, | 132 void GotReservedQuota(ppapi::host::ReplyMessageContext reply_context, |
133 int64_t amount, | 133 int64_t amount, |
134 const ppapi::FileSizeMap& file_sizes); | 134 const ppapi::FileSizeMap& file_sizes); |
135 void DidOpenQuotaFile(PP_Resource file_io_resource, | 135 void DidOpenQuotaFile(PP_Resource file_io_resource, |
136 const OpenQuotaFileCallback& callback, | 136 const OpenQuotaFileCallback& callback, |
137 int64_t max_written_offset); | 137 int64_t max_written_offset); |
138 | 138 |
139 std::string GetPluginMimeType() const; | 139 std::string GetPluginMimeType() const; |
140 | 140 |
141 // Returns plugin ID generated from plugin's MIME type. | 141 // Returns plugin ID generated from plugin's MIME type. |
142 std::string GeneratePluginId(const std::string& mime_type) const; | 142 std::string GeneratePluginId(const std::string& mime_type) const; |
143 | 143 |
144 BrowserPpapiHost* browser_ppapi_host_; | 144 BrowserPpapiHost* browser_ppapi_host_; |
145 | 145 |
146 PP_FileSystemType type_; | 146 PP_FileSystemType type_; |
147 bool called_open_; // whether open has been called. | 147 bool called_open_; // whether open has been called. |
148 bool opened_; // whether open succeeded. | 148 bool opened_; // whether open succeeded. |
149 GURL root_url_; | 149 GURL root_url_; |
150 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 150 scoped_refptr<storage::FileSystemContext> file_system_context_; |
151 | 151 |
152 scoped_ptr<fileapi::FileSystemOperationRunner> file_system_operation_runner_; | 152 scoped_ptr<storage::FileSystemOperationRunner> file_system_operation_runner_; |
153 | 153 |
154 // Used only for file systems with quota. | 154 // Used only for file systems with quota. |
155 // When a PepperFileIOHost calls OpenQuotaFile, we add the id and a non-owning | 155 // When a PepperFileIOHost calls OpenQuotaFile, we add the id and a non-owning |
156 // pointer to this map. CloseQuotaFile must be called when before the host is | 156 // pointer to this map. CloseQuotaFile must be called when before the host is |
157 // destroyed. | 157 // destroyed. |
158 typedef std::map<int32_t, PepperFileIOHost*> FileMap; | 158 typedef std::map<int32_t, PepperFileIOHost*> FileMap; |
159 FileMap files_; | 159 FileMap files_; |
160 int64_t reserved_quota_; | 160 int64_t reserved_quota_; |
161 bool reserving_quota_; | 161 bool reserving_quota_; |
162 // Access only on the FileSystemContext's default_file_task_runner(). | 162 // Access only on the FileSystemContext's default_file_task_runner(). |
163 scoped_refptr<QuotaReservation> quota_reservation_; | 163 scoped_refptr<QuotaReservation> quota_reservation_; |
164 | 164 |
165 std::string fsid_; // used only for isolated filesystems. | 165 std::string fsid_; // used only for isolated filesystems. |
166 | 166 |
167 base::WeakPtrFactory<PepperFileSystemBrowserHost> weak_factory_; | 167 base::WeakPtrFactory<PepperFileSystemBrowserHost> weak_factory_; |
168 | 168 |
169 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHost); | 169 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHost); |
170 }; | 170 }; |
171 | 171 |
172 } // namespace content | 172 } // namespace content |
173 | 173 |
174 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_
H_ | 174 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_
H_ |
OLD | NEW |