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

Side by Side Diff: components/nacl/renderer/manifest_service_channel.cc

Issue 418423002: Pepper: Stop using SRPC for irt_open_resource(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes for mseaborn and dmichael Created 6 years, 3 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/nacl/renderer/manifest_service_channel.h" 5 #include "components/nacl/renderer/manifest_service_channel.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 "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "content/public/common/sandbox_init.h"
10 #include "content/public/renderer/render_thread.h" 11 #include "content/public/renderer/render_thread.h"
11 #include "ipc/ipc_channel.h" 12 #include "ipc/ipc_channel.h"
12 #include "ipc/ipc_sync_channel.h" 13 #include "ipc/ipc_sync_channel.h"
13 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/c/ppb_file_io.h"
14 #include "ppapi/proxy/ppapi_messages.h" 16 #include "ppapi/proxy/ppapi_messages.h"
15 17
16 namespace nacl { 18 namespace nacl {
17 19
18 ManifestServiceChannel::ManifestServiceChannel( 20 ManifestServiceChannel::ManifestServiceChannel(
19 const IPC::ChannelHandle& handle, 21 const IPC::ChannelHandle& handle,
20 const base::Callback<void(int32_t)>& connected_callback, 22 const base::Callback<void(int32_t)>& connected_callback,
21 scoped_ptr<Delegate> delegate, 23 scoped_ptr<Delegate> delegate,
22 base::WaitableEvent* waitable_event) 24 base::WaitableEvent* waitable_event)
23 : connected_callback_(connected_callback), 25 : connected_callback_(connected_callback),
24 delegate_(delegate.Pass()), 26 delegate_(delegate.Pass()),
25 channel_(IPC::SyncChannel::Create( 27 channel_(IPC::SyncChannel::Create(
26 handle, 28 handle,
27 IPC::Channel::MODE_CLIENT, 29 IPC::Channel::MODE_CLIENT,
28 this, 30 this,
29 content::RenderThread::Get()->GetIOMessageLoopProxy(), 31 content::RenderThread::Get()->GetIOMessageLoopProxy(),
30 true, 32 true,
31 waitable_event)), 33 waitable_event)),
34 peer_pid_(base::kNullProcessId),
32 weak_ptr_factory_(this) { 35 weak_ptr_factory_(this) {
33 } 36 }
34 37
35 ManifestServiceChannel::~ManifestServiceChannel() { 38 ManifestServiceChannel::~ManifestServiceChannel() {
36 if (!connected_callback_.is_null()) 39 if (!connected_callback_.is_null())
37 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); 40 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED);
38 } 41 }
39 42
40 void ManifestServiceChannel::Send(IPC::Message* message) { 43 void ManifestServiceChannel::Send(IPC::Message* message) {
41 channel_->Send(message); 44 channel_->Send(message);
42 } 45 }
43 46
44 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { 47 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) {
45 bool handled = true; 48 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) 49 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message)
47 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, 50 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete,
48 OnStartupInitializationComplete) 51 OnStartupInitializationComplete)
49 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource, 52 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource,
50 OnOpenResource) 53 OnOpenResource)
51 IPC_MESSAGE_UNHANDLED(handled = false) 54 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP() 55 IPC_END_MESSAGE_MAP()
53 return handled; 56 return handled;
54 } 57 }
55 58
56 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) { 59 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) {
60 peer_pid_ = peer_pid;
57 if (!connected_callback_.is_null()) 61 if (!connected_callback_.is_null())
58 base::ResetAndReturn(&connected_callback_).Run(PP_OK); 62 base::ResetAndReturn(&connected_callback_).Run(PP_OK);
59 } 63 }
60 64
61 void ManifestServiceChannel::OnChannelError() { 65 void ManifestServiceChannel::OnChannelError() {
62 if (!connected_callback_.is_null()) 66 if (!connected_callback_.is_null())
63 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); 67 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED);
64 } 68 }
65 69
66 void ManifestServiceChannel::OnStartupInitializationComplete() { 70 void ManifestServiceChannel::OnStartupInitializationComplete() {
67 delegate_->StartupInitializationComplete(); 71 delegate_->StartupInitializationComplete();
68 } 72 }
69 73
70 void ManifestServiceChannel::OnOpenResource( 74 void ManifestServiceChannel::OnOpenResource(
71 const std::string& key, IPC::Message* reply) { 75 const std::string& key, IPC::Message* reply) {
72 // Currently this is used only for non-SFI mode, which is not supported on
73 // windows.
74 #if !defined(OS_WIN)
75 delegate_->OpenResource( 76 delegate_->OpenResource(
76 key, 77 key,
77 base::Bind(&ManifestServiceChannel::DidOpenResource, 78 base::Bind(&ManifestServiceChannel::DidOpenResource,
78 weak_ptr_factory_.GetWeakPtr(), reply)); 79 weak_ptr_factory_.GetWeakPtr(), reply));
79 #else
80 PpapiHostMsg_OpenResource::WriteReplyParams(
81 reply, ppapi::proxy::SerializedHandle());
82 Send(reply);
83 #endif
84 } 80 }
85 81
86 #if !defined(OS_WIN) 82 void ManifestServiceChannel::DidOpenResource(IPC::Message* reply,
87 void ManifestServiceChannel::DidOpenResource( 83 base::File file,
88 IPC::Message* reply, base::File file) { 84 uint64_t token_lo,
89 // Here, PlatformFileForTransit is alias of base::FileDescriptor. 85 uint64_t token_hi) {
90 PpapiHostMsg_OpenResource::WriteReplyParams( 86 ppapi::proxy::SerializedHandle handle;
91 reply, 87 if (file.IsValid()) {
92 ppapi::proxy::SerializedHandle( 88 IPC::PlatformFileForTransit file_for_transit;
93 ppapi::proxy::SerializedHandle::FILE, 89 #if defined(OS_WIN)
94 base::FileDescriptor(file.Pass()))); 90 bool ok = content::BrokerDuplicateHandle(
91 file.TakePlatformFile(),
92 peer_pid_,
93 &file_for_transit,
94 0, // desired_access is 0 since we're using DUPLICATE_SAME_ACCESS.
95 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
96 if (ok)
97 handle.set_file_handle(file_for_transit, PP_FILEOPENFLAG_READ, 0);
98 #else
99 file_for_transit = base::FileDescriptor(file.Pass());
100 handle.set_file_handle(file_for_transit, PP_FILEOPENFLAG_READ, 0);
101 #endif
102 }
103 PpapiHostMsg_OpenResource::WriteReplyParams(reply,
104 handle,
105 token_lo,
106 token_hi);
95 Send(reply); 107 Send(reply);
96 } 108 }
97 #endif
98 109
99 } // namespace nacl 110 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698