Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc

Issue 93403002: Pepper: Add PepperFileSystemBrowserHost::GotFileSystemContext method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_file_system_browser_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h " 5 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h "
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "content/public/browser/browser_ppapi_host.h" 9 #include "content/public/browser/browser_ppapi_host.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 void PepperFileSystemBrowserHost::OpenExisting(const GURL& root_url, 65 void PepperFileSystemBrowserHost::OpenExisting(const GURL& root_url,
66 const base::Closure& callback) { 66 const base::Closure& callback) {
67 root_url_ = root_url; 67 root_url_ = root_url;
68 int render_process_id = 0; 68 int render_process_id = 0;
69 int unused; 69 int unused;
70 if (!browser_ppapi_host_->GetRenderViewIDsForInstance( 70 if (!browser_ppapi_host_->GetRenderViewIDsForInstance(
71 pp_instance(), &render_process_id, &unused)) { 71 pp_instance(), &render_process_id, &unused)) {
72 NOTREACHED(); 72 NOTREACHED();
73 } 73 }
74 called_open_ = true; 74 called_open_ = true;
75 // Get the file system context asynchronously, and then complete the Open 75 // Get the file system context asynchronously, set up the file system context,
76 // operation by calling |callback|. 76 // and then complete the Open operation by calling |callback|.
77 BrowserThread::PostTaskAndReplyWithResult( 77 BrowserThread::PostTaskAndReplyWithResult(
78 BrowserThread::UI, 78 BrowserThread::UI,
79 FROM_HERE, 79 FROM_HERE,
80 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), 80 base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
81 base::Bind(&PepperFileSystemBrowserHost::OpenExistingWithContext, 81 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext,
82 weak_factory_.GetWeakPtr(), callback)); 82 weak_factory_.GetWeakPtr(),
83 base::Bind(
84 &PepperFileSystemBrowserHost::OpenExistingFileSystem,
85 weak_factory_.GetWeakPtr(),
86 callback)));
83 } 87 }
84 88
85 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived( 89 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived(
86 const IPC::Message& msg, 90 const IPC::Message& msg,
87 ppapi::host::HostMessageContext* context) { 91 ppapi::host::HostMessageContext* context) {
88 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemBrowserHost, msg) 92 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemBrowserHost, msg)
89 PPAPI_DISPATCH_HOST_RESOURCE_CALL( 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
90 PpapiHostMsg_FileSystem_Open, 94 PpapiHostMsg_FileSystem_Open,
91 OnHostMsgOpen) 95 OnHostMsgOpen)
92 PPAPI_DISPATCH_HOST_RESOURCE_CALL( 96 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
(...skipping 30 matching lines...) Expand all
123 &unused)) { 127 &unused)) {
124 return PP_ERROR_FAILED; 128 return PP_ERROR_FAILED;
125 } 129 }
126 130
127 BrowserThread::PostTaskAndReplyWithResult( 131 BrowserThread::PostTaskAndReplyWithResult(
128 BrowserThread::UI, 132 BrowserThread::UI,
129 FROM_HERE, 133 FROM_HERE,
130 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), 134 base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
131 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext, 135 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext,
132 weak_factory_.GetWeakPtr(), 136 weak_factory_.GetWeakPtr(),
133 context->MakeReplyMessageContext(), 137 base::Bind(&PepperFileSystemBrowserHost::OpenFileSystem,
134 file_system_type)); 138 weak_factory_.GetWeakPtr(),
139 context->MakeReplyMessageContext(),
140 file_system_type)));
135 return PP_OK_COMPLETIONPENDING; 141 return PP_OK_COMPLETIONPENDING;
136 } 142 }
137 143
138 void PepperFileSystemBrowserHost::OpenExistingWithContext( 144 void PepperFileSystemBrowserHost::OpenExistingFileSystem(
139 const base::Closure& callback, 145 const base::Closure& callback) {
140 scoped_refptr<fileapi::FileSystemContext> file_system_context) { 146 if (file_system_context_.get()) {
141 if (file_system_context.get()) {
142 opened_ = true; 147 opened_ = true;
143 } else { 148 } else {
144 // If there is no file system context, we log a warning and continue with an 149 // If there is no file system context, we log a warning and continue with an
145 // invalid resource (which will produce errors when used), since we have no 150 // invalid resource (which will produce errors when used), since we have no
146 // way to communicate the error to the caller. 151 // way to communicate the error to the caller.
147 LOG(WARNING) << "Could not retrieve file system context."; 152 LOG(WARNING) << "Could not retrieve file system context.";
148 } 153 }
149 SetFileSystemContext(file_system_context);
150 callback.Run(); 154 callback.Run();
151 } 155 }
152 156
153 void PepperFileSystemBrowserHost::GotFileSystemContext( 157 void PepperFileSystemBrowserHost::OpenFileSystem(
154 ppapi::host::ReplyMessageContext reply_context, 158 ppapi::host::ReplyMessageContext reply_context,
155 fileapi::FileSystemType file_system_type, 159 fileapi::FileSystemType file_system_type) {
156 scoped_refptr<fileapi::FileSystemContext> file_system_context) { 160 if (!file_system_context_.get()) {
157 if (!file_system_context.get()) {
158 OpenFileSystemComplete( 161 OpenFileSystemComplete(
159 reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED); 162 reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED);
160 return; 163 return;
161 } 164 }
162 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( 165 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance(
163 pp_instance()).GetOrigin(); 166 pp_instance()).GetOrigin();
164 file_system_context->OpenFileSystem(origin, file_system_type, 167 file_system_context_->OpenFileSystem(origin, file_system_type,
165 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 168 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
166 base::Bind(&PepperFileSystemBrowserHost::OpenFileSystemComplete, 169 base::Bind(&PepperFileSystemBrowserHost::OpenFileSystemComplete,
167 weak_factory_.GetWeakPtr(), reply_context)); 170 weak_factory_.GetWeakPtr(), reply_context));
168 SetFileSystemContext(file_system_context);
169 } 171 }
170 172
171 void PepperFileSystemBrowserHost::OpenFileSystemComplete( 173 void PepperFileSystemBrowserHost::OpenFileSystemComplete(
172 ppapi::host::ReplyMessageContext reply_context, 174 ppapi::host::ReplyMessageContext reply_context,
173 const GURL& root, 175 const GURL& root,
174 const std::string& /* unused */, 176 const std::string& /* unused */,
175 base::PlatformFileError error) { 177 base::PlatformFileError error) {
176 int32 pp_error = ppapi::PlatformFileErrorToPepperError(error); 178 int32 pp_error = ppapi::PlatformFileErrorToPepperError(error);
177 if (pp_error == PP_OK) { 179 if (pp_error == PP_OK) {
178 opened_ = true; 180 opened_ = true;
179 root_url_ = root; 181 root_url_ = root;
180 } 182 }
181 reply_context.params.set_result(pp_error); 183 reply_context.params.set_result(pp_error);
182 host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply()); 184 host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply());
183 } 185 }
184 186
185 void PepperFileSystemBrowserHost::GotIsolatedFileSystemContext( 187 void PepperFileSystemBrowserHost::OpenIsolatedFileSystem(
186 ppapi::host::ReplyMessageContext reply_context, 188 ppapi::host::ReplyMessageContext reply_context,
187 const std::string& fsid, 189 const std::string& fsid,
188 PP_IsolatedFileSystemType_Private type, 190 PP_IsolatedFileSystemType_Private type) {
189 scoped_refptr<fileapi::FileSystemContext> file_system_context) { 191 if (!file_system_context_.get()) {
190 if (!file_system_context.get()) {
191 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_FAILED); 192 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_FAILED);
192 return; 193 return;
193 } 194 }
194 SetFileSystemContext(file_system_context);
195 195
196 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( 196 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString(
197 browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()).GetOrigin(), 197 browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()).GetOrigin(),
198 fsid, ppapi::IsolatedFileSystemTypeToRootName(type))); 198 fsid, ppapi::IsolatedFileSystemTypeToRootName(type)));
199 if (!root_url_.is_valid()) { 199 if (!root_url_.is_valid()) {
200 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_FAILED); 200 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_FAILED);
201 return; 201 return;
202 } 202 }
203 203
204 switch (type) { 204 switch (type) {
205 case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX: 205 case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX:
206 opened_ = true; 206 opened_ = true;
207 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_OK); 207 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_OK);
208 return; 208 return;
209 case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE: 209 case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE:
210 OpenPluginPrivateFileSystem(reply_context, fsid, file_system_context_); 210 OpenPluginPrivateFileSystem(reply_context, fsid);
211 return; 211 return;
212 default: 212 default:
213 NOTREACHED(); 213 NOTREACHED();
214 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_BADARGUMENT); 214 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_BADARGUMENT);
215 return; 215 return;
216 } 216 }
217 } 217 }
218 218
219 void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystem( 219 void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystem(
220 ppapi::host::ReplyMessageContext reply_context, 220 ppapi::host::ReplyMessageContext reply_context,
221 const std::string& fsid, 221 const std::string& fsid) {
222 scoped_refptr<fileapi::FileSystemContext> file_system_context) {
223 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( 222 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance(
224 pp_instance()).GetOrigin(); 223 pp_instance()).GetOrigin();
225 if (!origin.is_valid()) { 224 if (!origin.is_valid()) {
226 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_FAILED); 225 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_FAILED);
227 return; 226 return;
228 } 227 }
229 228
230 const std::string& plugin_id = GeneratePluginId(GetPluginMimeType()); 229 const std::string& plugin_id = GeneratePluginId(GetPluginMimeType());
231 if (plugin_id.empty()) { 230 if (plugin_id.empty()) {
232 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_BADARGUMENT); 231 SendReplyForIsolatedFileSystem(reply_context, fsid, PP_ERROR_BADARGUMENT);
233 return; 232 return;
234 } 233 }
235 234
236 file_system_context->OpenPluginPrivateFileSystem( 235 file_system_context_->OpenPluginPrivateFileSystem(
237 origin, fileapi::kFileSystemTypePluginPrivate, fsid, plugin_id, 236 origin, fileapi::kFileSystemTypePluginPrivate, fsid, plugin_id,
238 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 237 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
239 base::Bind( 238 base::Bind(
240 &PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete, 239 &PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete,
241 weak_factory_.GetWeakPtr(), reply_context, fsid)); 240 weak_factory_.GetWeakPtr(), reply_context, fsid));
242 } 241 }
243 242
244 void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete( 243 void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete(
245 ppapi::host::ReplyMessageContext reply_context, 244 ppapi::host::ReplyMessageContext reply_context,
246 const std::string& fsid, 245 const std::string& fsid,
(...skipping 23 matching lines...) Expand all
270 &render_process_id, 269 &render_process_id,
271 &unused)) { 270 &unused)) {
272 fileapi::IsolatedContext::GetInstance()->RevokeFileSystem(fsid); 271 fileapi::IsolatedContext::GetInstance()->RevokeFileSystem(fsid);
273 return PP_ERROR_FAILED; 272 return PP_ERROR_FAILED;
274 } 273 }
275 274
276 BrowserThread::PostTaskAndReplyWithResult( 275 BrowserThread::PostTaskAndReplyWithResult(
277 BrowserThread::UI, 276 BrowserThread::UI,
278 FROM_HERE, 277 FROM_HERE,
279 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), 278 base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
280 base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext, 279 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext,
281 weak_factory_.GetWeakPtr(), 280 weak_factory_.GetWeakPtr(),
282 context->MakeReplyMessageContext(), fsid, type)); 281 base::Bind(
282 &PepperFileSystemBrowserHost::OpenIsolatedFileSystem,
283 weak_factory_.GetWeakPtr(),
284 context->MakeReplyMessageContext(), fsid, type)));
285
283 return PP_OK_COMPLETIONPENDING; 286 return PP_OK_COMPLETIONPENDING;
284 } 287 }
285 288
286 void PepperFileSystemBrowserHost::SendReplyForIsolatedFileSystem( 289 void PepperFileSystemBrowserHost::SendReplyForIsolatedFileSystem(
287 ppapi::host::ReplyMessageContext reply_context, 290 ppapi::host::ReplyMessageContext reply_context,
288 const std::string& fsid, 291 const std::string& fsid,
289 int32_t error) { 292 int32_t error) {
290 if (error != PP_OK) 293 if (error != PP_OK)
291 fileapi::IsolatedContext::GetInstance()->RevokeFileSystem(fsid); 294 fileapi::IsolatedContext::GetInstance()->RevokeFileSystem(fsid);
292 reply_context.params.set_result(error); 295 reply_context.params.set_result(error);
293 host()->SendReply(reply_context, 296 host()->SendReply(reply_context,
294 PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply()); 297 PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply());
295 } 298 }
296 299
297 void PepperFileSystemBrowserHost::SetFileSystemContext( 300 void PepperFileSystemBrowserHost::GotFileSystemContext(
301 const base::Closure& closure,
298 scoped_refptr<fileapi::FileSystemContext> file_system_context) { 302 scoped_refptr<fileapi::FileSystemContext> file_system_context) {
299 file_system_context_ = file_system_context; 303 file_system_context_ = file_system_context;
300 if (type_ != PP_FILESYSTEMTYPE_EXTERNAL) { 304 if (type_ != PP_FILESYSTEMTYPE_EXTERNAL) {
301 file_system_operation_runner_ = 305 file_system_operation_runner_ =
302 file_system_context_->CreateFileSystemOperationRunner(); 306 file_system_context_->CreateFileSystemOperationRunner();
303 } 307 }
308 closure.Run();
304 } 309 }
305 310
306 std::string PepperFileSystemBrowserHost::GetPluginMimeType() const { 311 std::string PepperFileSystemBrowserHost::GetPluginMimeType() const {
307 base::FilePath plugin_path = browser_ppapi_host_->GetPluginPath(); 312 base::FilePath plugin_path = browser_ppapi_host_->GetPluginPath();
308 PepperPluginInfo* info = 313 PepperPluginInfo* info =
309 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(plugin_path); 314 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(plugin_path);
310 if (!info || info->mime_types.empty()) 315 if (!info || info->mime_types.empty())
311 return std::string(); 316 return std::string();
312 // Use the first element in |info->mime_types| even if several elements exist. 317 // Use the first element in |info->mime_types| even if several elements exist.
313 return info->mime_types[0].mime_type; 318 return info->mime_types[0].mime_type;
(...skipping 19 matching lines...) Expand all
333 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && 338 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) &&
334 *it != '.' && *it != '_' && *it != '-') { 339 *it != '.' && *it != '_' && *it != '-') {
335 LOG(WARNING) << "Failed to generate a plugin id."; 340 LOG(WARNING) << "Failed to generate a plugin id.";
336 return std::string(); 341 return std::string();
337 } 342 }
338 } 343 }
339 return output; 344 return output;
340 } 345 }
341 346
342 } // namespace content 347 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_file_system_browser_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698