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

Side by Side Diff: chrome/renderer/pepper/pnacl_translation_resource_host.cc

Issue 19863003: PNaCl on-demand installs: Make a separate async IPC to check if PNaCl is installed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: int64_t to int64 Created 7 years, 4 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 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 "pnacl_translation_resource_host.h" 5 #include "pnacl_translation_resource_host.h"
6 6
7 #ifndef DISABLE_NACL 7 #ifndef DISABLE_NACL
8 #include "components/nacl/common/nacl_host_messages.h" 8 #include "components/nacl/common/nacl_host_messages.h"
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/shared_impl/ppapi_globals.h" 10 #include "ppapi/shared_impl/ppapi_globals.h"
11 11
12 using ppapi::TrackedCallback; 12 using ppapi::TrackedCallback;
13 using ppapi::PpapiGlobals; 13 using ppapi::PpapiGlobals;
14 14
15 PnaclTranslationResourceHost::CacheRequestInfo::CacheRequestInfo( 15 PnaclTranslationResourceHost::CacheRequestInfo::CacheRequestInfo(
16 PP_Bool* hit, 16 PP_Bool* hit,
17 PP_FileHandle* handle, 17 PP_FileHandle* handle,
18 scoped_refptr<TrackedCallback> cb) 18 scoped_refptr<TrackedCallback> cb)
19 : is_hit(hit), file_handle(handle), callback(cb) {} 19 : is_hit(hit), file_handle(handle), callback(cb) {}
20 20
21 PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {} 21 PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {}
22 22
23 PnaclTranslationResourceHost::PnaclTranslationResourceHost( 23 PnaclTranslationResourceHost::PnaclTranslationResourceHost(
24 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) 24 const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
25 : io_message_loop_(io_message_loop), channel_(NULL) {} 25 : io_message_loop_(io_message_loop), channel_(NULL) {}
26 26
27 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { 27 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() {
28 CleanupCacheRequests(); 28 CleanupCacheRequests();
29 CleanupEnsurePnaclRequests();
29 } 30 }
30 31
31 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) { 32 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) {
32 DCHECK(io_message_loop_->BelongsToCurrentThread()); 33 DCHECK(io_message_loop_->BelongsToCurrentThread());
33 channel_ = channel; 34 channel_ = channel;
34 } 35 }
35 36
36 void PnaclTranslationResourceHost::OnFilterRemoved() { 37 void PnaclTranslationResourceHost::OnFilterRemoved() {
37 DCHECK(io_message_loop_->BelongsToCurrentThread()); 38 DCHECK(io_message_loop_->BelongsToCurrentThread());
38 channel_ = NULL; 39 channel_ = NULL;
39 } 40 }
40 41
41 void PnaclTranslationResourceHost::OnChannelClosing() { 42 void PnaclTranslationResourceHost::OnChannelClosing() {
42 DCHECK(io_message_loop_->BelongsToCurrentThread()); 43 DCHECK(io_message_loop_->BelongsToCurrentThread());
43 channel_ = NULL; 44 channel_ = NULL;
44 } 45 }
45 46
46 bool PnaclTranslationResourceHost::OnMessageReceived( 47 bool PnaclTranslationResourceHost::OnMessageReceived(
47 const IPC::Message& message) { 48 const IPC::Message& message) {
48 DCHECK(io_message_loop_->BelongsToCurrentThread()); 49 DCHECK(io_message_loop_->BelongsToCurrentThread());
49 bool handled = true; 50 bool handled = true;
50 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) 51 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message)
51 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) 52 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply)
53 IPC_MESSAGE_HANDLER(NaClViewMsg_EnsurePnaclInstalledReply,
54 OnEnsurePnaclInstalledReply)
55 IPC_MESSAGE_HANDLER(NaClViewMsg_EnsurePnaclInstalledProgress,
56 OnEnsurePnaclInstalledProgress)
52 IPC_MESSAGE_UNHANDLED(handled = false) 57 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP() 58 IPC_END_MESSAGE_MAP()
54 return handled; 59 return handled;
55 } 60 }
56 61
57 void PnaclTranslationResourceHost::RequestNexeFd( 62 void PnaclTranslationResourceHost::RequestNexeFd(
58 int render_view_id, 63 int render_view_id,
59 PP_Instance instance, 64 PP_Instance instance,
60 const nacl::PnaclCacheInfo& cache_info, 65 const nacl::PnaclCacheInfo& cache_info,
61 PP_Bool* is_hit, 66 PP_Bool* is_hit,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 142
138 void PnaclTranslationResourceHost::CleanupCacheRequests() { 143 void PnaclTranslationResourceHost::CleanupCacheRequests() {
139 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); 144 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin();
140 it != pending_cache_requests_.end(); 145 it != pending_cache_requests_.end();
141 ++it) { 146 ++it) {
142 it->second.callback->PostAbort(); 147 it->second.callback->PostAbort();
143 } 148 }
144 pending_cache_requests_.clear(); 149 pending_cache_requests_.clear();
145 } 150 }
146 151
152
153
154 void PnaclTranslationResourceHost::EnsurePnaclInstalled(
155 PP_Instance instance,
156 scoped_refptr<TrackedCallback> callback) {
157 if (!io_message_loop_->BelongsToCurrentThread()) {
dmichael (off chromium) 2013/08/01 17:33:49 EnsurePnaclInstalled should always originate on th
jvoung (off chromium) 2013/08/01 23:14:07 Separated the two halfs of the function and put in
158 io_message_loop_->PostTask(
159 FROM_HERE,
160 base::Bind(&PnaclTranslationResourceHost::EnsurePnaclInstalled,
161 this, instance, callback));
162 return;
163 }
164 if (!channel_ || !channel_->Send(new NaClHostMsg_EnsurePnaclInstalled(
165 instance))) {
166 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
167 FROM_HERE,
168 base::Bind(&TrackedCallback::Run,
169 callback,
170 static_cast<int32_t>(PP_ERROR_FAILED)));
171 return;
172 }
173 pending_ensure_pnacl_requests_.insert(
174 std::make_pair(instance, callback));
175 }
176
177 void PnaclTranslationResourceHost::OnEnsurePnaclInstalledReply(
178 PP_Instance instance,
179 bool success) {
180 EnsurePnaclInstalledMap::iterator it =
181 pending_ensure_pnacl_requests_.find(instance);
182 if (it == pending_ensure_pnacl_requests_.end()) {
183 DLOG(ERROR) << "Could not find pending request for reply";
184 } else {
185 if (TrackedCallback::IsPending(it->second)) {
186 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
187 FROM_HERE,
188 base::Bind(&TrackedCallback::Run,
189 it->second,
190 static_cast<int32_t>(success ? PP_OK : PP_ERROR_FAILED)));
191 }
192 pending_ensure_pnacl_requests_.erase(it);
193 }
194 }
195
196 void PnaclTranslationResourceHost::OnEnsurePnaclInstalledProgress(
197 PP_Instance instance,
198 int64 current_progress,
199 int64 total) {
200 // TODO(jvoung): Issue a progress event w/ dmichael's new DispatchEvent
201 // interface: https://codereview.chromium.org/14588009/
202 }
203
204 void PnaclTranslationResourceHost::CleanupEnsurePnaclRequests() {
205 for (EnsurePnaclInstalledMap::iterator it =
206 pending_ensure_pnacl_requests_.begin();
207 it != pending_ensure_pnacl_requests_.end();
208 ++it) {
209 it->second->PostAbort();
210 }
211 pending_ensure_pnacl_requests_.clear();
dmichael (off chromium) 2013/08/01 17:33:49 So do CleanupEnsurePnaclRequests and the destructo
jvoung (off chromium) 2013/08/01 23:14:07 Yeah, it also has to run on the IO thread. Added D
dmichael (off chromium) 2013/08/02 17:24:03 FWIW, you can call DetachFromThread in that case.
jvoung (off chromium) 2013/08/02 18:32:36 Ah ok. Any preference for using that or explicitl
212 }
213
147 #endif // DISABLE_NACL 214 #endif // DISABLE_NACL
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698