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

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

Issue 33053002: Pepper: Move FileIO host from renderer to browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes for bbudge Created 7 years, 2 months 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
OLDNEW
(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 #include "content/browser/renderer_host/pepper/pepper_file_io_host.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/callback_helpers.h"
10 #include "base/command_line.h"
bbudge 2013/10/22 17:25:37 Is this needed?
teravest 2013/10/23 16:54:27 Removed.
11 #include "base/files/file_util_proxy.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h"
14 #include "content/browser/renderer_host/pepper/pepper_security_helper.h"
15 #include "content/browser/renderer_host/pepper/quota_file_io.h"
16 #include "content/common/fileapi/file_system_messages.h"
17 #include "content/common/sandbox_util.h"
18 #include "content/common/view_messages.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/storage_partition.h"
23 #include "content/public/common/content_client.h"
24 #include "ppapi/c/pp_errors.h"
25 #include "ppapi/c/ppb_file_io.h"
26 #include "ppapi/host/dispatch_host_message.h"
27 #include "ppapi/host/ppapi_host.h"
28 #include "ppapi/proxy/ppapi_messages.h"
29 #include "ppapi/shared_impl/file_type_conversion.h"
30 #include "ppapi/shared_impl/time_conversion.h"
31 #include "webkit/browser/fileapi/file_observers.h"
32 #include "webkit/browser/fileapi/file_system_context.h"
33 #include "webkit/browser/fileapi/task_runner_bound_observer_list.h"
34 #include "webkit/browser/quota/quota_manager.h"
35 #include "webkit/common/fileapi/file_system_util.h"
36
37 namespace content {
38
39 using ppapi::FileIOStateManager;
40 using ppapi::PPTimeToTime;
41
42 namespace {
43
44 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) {
45 // On the plugin side, some callbacks expect a parameter that means different
46 // things depending on whether it is negative or not. We translate for those
47 // callbacks here.
48 return pp_error == PP_OK ? byte_number : pp_error;
49 }
50
51 class QuotaFileIODelegate : public QuotaFileIO::Delegate {
52 public:
53 QuotaFileIODelegate(scoped_refptr<fileapi::FileSystemContext> context,
54 int render_process_id)
55 : context_(context),
56 weak_factory_(this) { }
57 virtual ~QuotaFileIODelegate() {}
58
59 virtual void QueryAvailableSpace(
60 const GURL& origin,
61 quota::StorageType type,
62 const AvailableSpaceCallback& callback) OVERRIDE {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
64 quota::QuotaManagerProxy* quota_manager_proxy =
65 context_->quota_manager_proxy();
66 DCHECK(quota_manager_proxy);
67 if (!quota_manager_proxy) {
68 callback.Run(0);
69 return;
70 }
71 quota::QuotaManager* qm = quota_manager_proxy->quota_manager();
72 DCHECK(qm);
73 if (!qm) {
74 callback.Run(0);
75 return;
76 }
77 qm->GetUsageAndQuotaForWebApps(
78 origin,
79 type,
80 base::Bind(&QuotaFileIODelegate::GotUsageAndQuotaForWebApps,
81 weak_factory_.GetWeakPtr(), callback));
82 }
83
84 void GotUsageAndQuotaForWebApps(const AvailableSpaceCallback& callback,
85 quota::QuotaStatusCode code,
86 int64 usage,
87 int64 quota) {
88 if (code == quota::kQuotaStatusOk)
89 callback.Run(std::max(static_cast<int64>(0), quota - usage));
90 else
91 callback.Run(0);
92 }
93
94 virtual void WillUpdateFile(const GURL& file_path) OVERRIDE {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
96 fileapi::FileSystemURL url(context_->CrackURL(file_path));
97 if (!url.is_valid())
98 return;
99 const fileapi::UpdateObserverList* observers =
100 context_->GetUpdateObservers(url.type());
101 if (!observers)
102 return;
103 observers->Notify(&fileapi::FileUpdateObserver::OnStartUpdate,
104 MakeTuple(url));
105 }
106 virtual void DidUpdateFile(const GURL& file_path, int64_t delta) OVERRIDE {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
108 fileapi::FileSystemURL url(context_->CrackURL(file_path));
109 if (!url.is_valid())
110 return;
111 const fileapi::UpdateObserverList* observers =
112 context_->GetUpdateObservers(url.type());
113 if (!observers)
114 return;
115 observers->Notify(&fileapi::FileUpdateObserver::OnUpdate,
116 MakeTuple(url, delta));
117 observers->Notify(&fileapi::FileUpdateObserver::OnEndUpdate,
118 MakeTuple(url));
119 }
120 virtual scoped_refptr<base::MessageLoopProxy>
121 GetFileThreadMessageLoopProxy() OVERRIDE {
122 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
123 }
124 private:
125 scoped_refptr<fileapi::FileSystemContext> context_;
126 base::WeakPtrFactory<QuotaFileIODelegate> weak_factory_;
127 };
128
129 // TODO(teravest): Don't duplicate code with PepperFileSystemBrowserHost.
130 scoped_refptr<fileapi::FileSystemContext>
131 GetFileSystemContextFromRenderId(int render_process_id) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
133 RenderProcessHost* render_process_host =
bbudge 2013/10/22 17:25:37 Maybe change variable name to 'host' as in PepperF
teravest 2013/10/23 16:54:27 Done.
134 RenderProcessHost::FromID(render_process_id);
135 if (!render_process_host)
136 return NULL;
137 StoragePartition* storage_partition =
138 render_process_host->GetStoragePartition();
139 if (!storage_partition)
140 return NULL;
141 return storage_partition->GetFileSystemContext();
142 }
143
144 } // namespace
145
146 PepperFileIOHost::PepperFileIOHost(BrowserPpapiHostImpl* host,
147 PP_Instance instance,
148 PP_Resource resource)
149 : ResourceHost(host->GetPpapiHost(), instance, resource),
150 browser_ppapi_host_(host),
151 render_process_host_(NULL),
152 file_(base::kInvalidPlatformFileValue),
153 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
154 quota_policy_(quota::kQuotaLimitTypeUnknown),
155 open_flags_(0),
156 weak_factory_(this) {
157 int unused;
158 if (!host->GetRenderViewIDsForInstance(instance,
159 &render_process_id_,
160 &unused)) {
161 render_process_id_ = -1;
162 }
163 file_message_loop_ = BrowserThread::GetMessageLoopProxyForThread(
164 BrowserThread::FILE);
165 }
166
167 PepperFileIOHost::~PepperFileIOHost() {
168 OnHostMsgClose(NULL);
bbudge 2013/10/22 17:25:37 It might be cleaner to define a Close() method to
teravest 2013/10/23 16:54:27 I'll change this if you feel strongly, but I don't
bbudge 2013/10/23 17:04:52 OK
169 }
170
171 int32_t PepperFileIOHost::OnResourceMessageReceived(
172 const IPC::Message& msg,
173 ppapi::host::HostMessageContext* context) {
174 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg)
175 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open,
176 OnHostMsgOpen)
177 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Touch,
178 OnHostMsgTouch)
179 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Write,
180 OnHostMsgWrite)
181 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_SetLength,
182 OnHostMsgSetLength)
183 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Flush,
184 OnHostMsgFlush)
185 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Close,
186 OnHostMsgClose)
187 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_RequestOSFileHandle,
188 OnHostMsgRequestOSFileHandle)
189 IPC_END_MESSAGE_MAP()
190 return PP_ERROR_FAILED;
191 }
192
193 int32_t PepperFileIOHost::OnHostMsgOpen(
194 ppapi::host::HostMessageContext* context,
195 PP_Resource file_ref_resource,
196 int32_t open_flags) {
197 int32_t rv = state_manager_.CheckOperationState(
198 FileIOStateManager::OPERATION_EXCLUSIVE, false);
199 if (rv != PP_OK)
200 return rv;
201
202 int platform_file_flags = 0;
203 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags,
204 &platform_file_flags))
205 return PP_ERROR_BADARGUMENT;
206
207 ppapi::host::ResourceHost* resource_host =
208 host()->GetResourceHost(file_ref_resource);
209 if (!resource_host || !resource_host->IsFileRefHost())
210 return PP_ERROR_BADRESOURCE;
211 PepperFileRefHost* file_ref_host =
212 static_cast<PepperFileRefHost*>(resource_host);
213 if (file_ref_host->GetFileSystemType() == PP_FILESYSTEMTYPE_INVALID)
214 return PP_ERROR_FAILED;
215
216 open_flags_ = open_flags;
217 file_system_type_ = file_ref_host->GetFileSystemType();
218 file_system_url_ = file_ref_host->GetFileSystemURL();
219
220 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
222 fileapi::FileSystemURL url(file_ref_host->GetFileSystemURL());
223 if (!url.is_valid())
224 return PP_ERROR_BADARGUMENT;
225 if (!CanOpenFileSystemURLWithPepperFlags(open_flags,
226 render_process_id_,
227 url))
228 return PP_ERROR_NOACCESS;
229
230 BrowserThread::PostTaskAndReplyWithResult(
231 BrowserThread::UI,
232 FROM_HERE,
233 base::Bind(&GetFileSystemContextFromRenderId, render_process_id_),
234 base::Bind(&PepperFileIOHost::GotFileSystemContext,
235 weak_factory_.GetWeakPtr(),
236 context->MakeReplyMessageContext(),
237 platform_file_flags));
238 } else {
239 base::FilePath path = file_ref_host->GetExternalFilePath();
240 if (!CanOpenWithPepperFlags(open_flags, render_process_id_, path))
241 return PP_ERROR_NOACCESS;
242 base::FileUtilProxy::CreateOrOpen(
243 file_message_loop_,
244 path,
245 platform_file_flags,
246 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback,
247 weak_factory_.GetWeakPtr(),
248 context->MakeReplyMessageContext()));
249 }
250 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
251 return PP_OK_COMPLETIONPENDING;
252 }
253
254 void PepperFileIOHost::GotFileSystemContext(
255 ppapi::host::ReplyMessageContext reply_context,
256 int platform_file_flags,
257 scoped_refptr<fileapi::FileSystemContext> file_system_context) {
258 if (!file_system_context.get()) {
259 reply_context.params.set_result(PP_ERROR_FAILED);
260 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenReply());
261 return;
262 }
263 file_system_context_ = file_system_context;
264
265 if (!file_system_context_->GetFileSystemBackend(file_system_url_.type())) {
266 reply_context.params.set_result(PP_ERROR_FAILED);
267 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenReply());
268 return;
269 }
270 quota_policy_ = quota::kQuotaLimitTypeUnknown;
271 quota::QuotaManagerProxy* quota_manager_proxy =
272 file_system_context_->quota_manager_proxy();
273 CHECK(quota_manager_proxy);
274 CHECK(quota_manager_proxy->quota_manager());
275 if (quota_manager_proxy->quota_manager()->IsStorageUnlimited(
276 file_system_url_.origin(),
277 fileapi::FileSystemTypeToQuotaStorageType(file_system_url_.type())))
278 quota_policy_ = quota::kQuotaLimitTypeUnlimited;
279 else
280 quota_policy_ = quota::kQuotaLimitTypeLimited;
281 file_system_operation_runner_ =
282 file_system_context_->CreateFileSystemOperationRunner();
283 file_system_operation_runner_->OpenFile(
284 file_system_url_,
285 platform_file_flags,
286 base::Bind(&PepperFileIOHost::DidOpenFile,
287 weak_factory_.GetWeakPtr(),
288 reply_context));
289 }
290
291 void PepperFileIOHost::DidOpenFile(
292 ppapi::host::ReplyMessageContext reply_context,
293 base::PlatformFileError result,
294 base::PlatformFile file,
295 const base::Closure& on_close_callback) {
296 if (result == base::PLATFORM_FILE_OK)
297 on_close_callback_ = on_close_callback;
bbudge 2013/10/22 17:25:37 on_close_callback_ doesn't seem to be used anywher
teravest 2013/10/23 16:54:27 Fixed.
298 ExecutePlatformOpenFileCallback(
299 reply_context, result, base::PassPlatformFile(&file), true);
300 }
301
302 int32_t PepperFileIOHost::OnHostMsgTouch(
303 ppapi::host::HostMessageContext* context,
304 PP_Time last_access_time,
305 PP_Time last_modified_time) {
306 int32_t rv = state_manager_.CheckOperationState(
307 FileIOStateManager::OPERATION_EXCLUSIVE, true);
308 if (rv != PP_OK)
309 return rv;
310
311 if (!base::FileUtilProxy::Touch(
312 file_message_loop_,
313 file_,
314 PPTimeToTime(last_access_time),
315 PPTimeToTime(last_modified_time),
316 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
317 weak_factory_.GetWeakPtr(),
318 context->MakeReplyMessageContext())))
319 return PP_ERROR_FAILED;
320
321 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
322 return PP_OK_COMPLETIONPENDING;
323 }
324
325 int32_t PepperFileIOHost::OnHostMsgWrite(
326 ppapi::host::HostMessageContext* context,
327 int64_t offset,
328 const std::string& buffer) {
329 int32_t rv = state_manager_.CheckOperationState(
330 FileIOStateManager::OPERATION_WRITE, true);
331 if (rv != PP_OK)
332 return rv;
333
334 if (quota_file_io_) {
335 if (!quota_file_io_->Write(
336 offset, buffer.c_str(), buffer.size(),
337 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback,
338 weak_factory_.GetWeakPtr(),
339 context->MakeReplyMessageContext())))
340 return PP_ERROR_FAILED;
341 } else {
342 if (!base::FileUtilProxy::Write(
343 file_message_loop_,
344 file_,
345 offset,
346 buffer.c_str(),
347 buffer.size(),
348 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback,
349 weak_factory_.GetWeakPtr(),
350 context->MakeReplyMessageContext())))
351 return PP_ERROR_FAILED;
352 }
353
354 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE);
355 return PP_OK_COMPLETIONPENDING;
356 }
357
358 int32_t PepperFileIOHost::OnHostMsgSetLength(
359 ppapi::host::HostMessageContext* context,
360 int64_t length) {
361 int32_t rv = state_manager_.CheckOperationState(
362 FileIOStateManager::OPERATION_EXCLUSIVE, true);
363 if (rv != PP_OK)
364 return rv;
365
366 QuotaFileIO::StatusCallback cb =
367 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
368 weak_factory_.GetWeakPtr(),
369 context->MakeReplyMessageContext());
bbudge 2013/10/22 17:25:37 Could you factor out creating the callback in OnHo
teravest 2013/10/23 16:54:27 Done.
370 if (quota_file_io_) {
371 if (!quota_file_io_->SetLength(length, cb))
372 return PP_ERROR_FAILED;
373 } else {
374 if (!base::FileUtilProxy::Truncate(file_message_loop_, file_, length, cb))
375 return PP_ERROR_FAILED;
376 }
377
378 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
379 return PP_OK_COMPLETIONPENDING;
380 }
381
382 int32_t PepperFileIOHost::OnHostMsgFlush(
383 ppapi::host::HostMessageContext* context) {
384 int32_t rv = state_manager_.CheckOperationState(
385 FileIOStateManager::OPERATION_EXCLUSIVE, true);
386 if (rv != PP_OK)
387 return rv;
388
389 if (!base::FileUtilProxy::Flush(
390 file_message_loop_,
391 file_,
392 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
393 weak_factory_.GetWeakPtr(),
394 context->MakeReplyMessageContext())))
395 return PP_ERROR_FAILED;
396
397 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
398 return PP_OK_COMPLETIONPENDING;
399 }
400
401 int32_t PepperFileIOHost::OnHostMsgClose(
402 ppapi::host::HostMessageContext* context) {
403 if (file_ != base::kInvalidPlatformFileValue) {
404 base::FileUtilProxy::Close(
405 file_message_loop_,
406 file_,
407 base::ResetAndReturn(&notify_close_file_callback_));
kinuko 2013/10/23 07:16:04 No one sets this callback any more?
teravest 2013/10/23 16:54:27 Fixed.
408 file_ = base::kInvalidPlatformFileValue;
409 quota_file_io_.reset();
410 }
kinuko 2013/10/23 07:16:04 Please call on_close_callback_ here if it's non-nu
teravest 2013/10/23 16:54:27 Done. Thanks for catching this. I changed this sli
411 return PP_OK;
412 }
413
414 int32_t PepperFileIOHost::OnHostMsgRequestOSFileHandle(
415 ppapi::host::HostMessageContext* context) {
416 if (open_flags_ != PP_FILEOPENFLAG_READ &&
417 quota_policy_ != quota::kQuotaLimitTypeUnlimited)
418 return PP_ERROR_FAILED;
419 GetRenderProcessHost(
420 base::Bind(&PepperFileIOHost::FinishRequestOSFileHandle,
421 weak_factory_.GetWeakPtr(),
422 context->MakeReplyMessageContext()));
423 return PP_OK_COMPLETIONPENDING;
424 }
425
426 void PepperFileIOHost::FinishRequestOSFileHandle(
427 ppapi::host::ReplyMessageContext reply_context,
428 RenderProcessHost* render_process_host) {
429 // Whitelist to make it privately accessible.
430 if (!browser_ppapi_host_->external_plugin() ||
431 host()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE) ||
432 GetContentClient()->browser()->IsPluginAllowedToCallRequestOSFileHandle(
433 render_process_host->GetBrowserContext(),
434 browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()))) {
kinuko 2013/10/23 07:16:04 Instead of returning raw render_process_host ptr f
teravest 2013/10/23 16:54:27 The problem is that BrowserPpapiHost lives entirel
kinuko 2013/10/24 02:31:01 I see. Could we do this then: call BrowserPpapiHos
435 if (!AddFileToReplyContext(open_flags_, &reply_context))
436 reply_context.params.set_result(PP_ERROR_FAILED);
437 } else {
438 reply_context.params.set_result(PP_ERROR_NOACCESS);
439 }
440 host()->SendReply(reply_context,
441 PpapiPluginMsg_FileIO_RequestOSFileHandleReply());
442 }
443
444 void PepperFileIOHost::ExecutePlatformGeneralCallback(
445 ppapi::host::ReplyMessageContext reply_context,
446 base::PlatformFileError error_code) {
447 reply_context.params.set_result(
448 ppapi::PlatformFileErrorToPepperError(error_code));
449 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
450 state_manager_.SetOperationFinished();
451 }
452
453 void PepperFileIOHost::ExecutePlatformOpenFileCallback(
454 ppapi::host::ReplyMessageContext reply_context,
455 base::PlatformFileError error_code,
456 base::PassPlatformFile file,
457 bool unused_created) {
458 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code);
459 if (pp_error == PP_OK)
460 state_manager_.SetOpenSucceed();
461
462 DCHECK(file_ == base::kInvalidPlatformFileValue);
463 file_ = file.ReleaseValue();
464
465 DCHECK(!quota_file_io_.get());
466 if (file_ != base::kInvalidPlatformFileValue) {
467 if (file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY ||
468 file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT) {
469 quota_file_io_.reset(new QuotaFileIO(
470 new QuotaFileIODelegate(file_system_context_, render_process_id_),
471 file_, file_system_url_.ToGURL(), file_system_type_));
472 }
473 int32_t flags_to_send = open_flags_;
474 if (!host()->permissions().HasPermission(ppapi::PERMISSION_DEV)) {
475 // IMPORTANT: Clear PP_FILEOPENFLAG_WRITE and PP_FILEOPENFLAG_APPEND so
476 // the plugin can't write and so bypass our quota checks.
477 flags_to_send =
478 open_flags_ & ~(PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_APPEND);
479 }
480 if (!AddFileToReplyContext(flags_to_send, &reply_context))
481 pp_error = PP_ERROR_FAILED;
482 }
483 reply_context.params.set_result(pp_error);
484 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenReply());
485 state_manager_.SetOperationFinished();
486 }
487
488 void PepperFileIOHost::ExecutePlatformWriteCallback(
489 ppapi::host::ReplyMessageContext reply_context,
490 base::PlatformFileError error_code,
491 int bytes_written) {
492 // On the plugin side, the callback expects a parameter with different meaning
493 // depends on whether is negative or not. It is the result here. We translate
494 // for the callback.
495 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code);
496 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
497 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
498 state_manager_.SetOperationFinished();
499 }
500
501 void PepperFileIOHost::GetRenderProcessHost(
502 base::Callback<void(RenderProcessHost*)> callback) {
503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
504 if (render_process_host_) {
kinuko 2013/10/23 07:16:04 We're caching this raw ptr on IO thread while it's
teravest 2013/10/23 16:54:27 I was thinking that RenderProcessHost::FromID was
505 callback.Run(render_process_host_);
506 } else {
507 BrowserThread::PostTaskAndReplyWithResult(
508 BrowserThread::UI,
509 FROM_HERE,
510 base::Bind(&RenderProcessHost::FromID, render_process_id_),
511 base::Bind(&PepperFileIOHost::GotRenderProcessHost,
512 weak_factory_.GetWeakPtr(),
513 callback));
514 }
515 }
516
517 void PepperFileIOHost::GotRenderProcessHost(
518 base::Callback<void(RenderProcessHost*)> callback,
519 RenderProcessHost* host) {
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
521 render_process_host_ = host;
522 callback.Run(render_process_host_);
523 }
524
525 bool PepperFileIOHost::AddFileToReplyContext(
526 int32_t open_flags,
527 ppapi::host::ReplyMessageContext* reply_context) const {
528 base::ProcessId plugin_process_id;
529 if (browser_ppapi_host_->external_plugin()) {
530 plugin_process_id =
531 base::GetProcId(browser_ppapi_host_->GetPluginProcessHandle());
532 } else {
533 plugin_process_id = render_process_id_;
534 }
535 IPC::PlatformFileForTransit transit_file = BrokerGetFileHandleForProcess(
536 file_, plugin_process_id, false);
537 if (transit_file == IPC::InvalidPlatformFileForTransit())
538 return false;
539 ppapi::proxy::SerializedHandle file_handle;
540 file_handle.set_file_handle(transit_file, open_flags);
541 reply_context->params.AppendHandle(file_handle);
542 return true;
543 }
544
545 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698