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

Side by Side Diff: src/trusted/plugin/srpc/closure.cc

Issue 1092005: Issue 1092005 (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: Created 10 years, 9 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 /* 1 /*
2 * Copyright 2008 The Native Client Authors. All rights reserved. 2 * Copyright 2008 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 */ 5 */
6 6
7 7
8 #include <string.h> 8 #include <string.h>
9 #include <string> 9 #include <string>
10 #include <list>
10 11
11 #include "native_client/src/shared/npruntime/npmodule.h" 12 #include "native_client/src/shared/npruntime/npmodule.h"
12 #include "native_client/src/shared/platform/nacl_host_desc.h" 13 #include "native_client/src/shared/platform/nacl_host_desc.h"
13 14
14 #include "native_client/src/trusted/desc/nacl_desc_invalid.h" 15 #include "native_client/src/trusted/desc/nacl_desc_invalid.h"
15 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 16 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
16 #include "native_client/src/trusted/plugin/srpc/npapi_native.h" 17 #include "native_client/src/trusted/plugin/srpc/npapi_native.h"
17 #include "native_client/src/trusted/plugin/srpc/scriptable_handle.h" 18 #include "native_client/src/trusted/plugin/srpc/scriptable_handle.h"
18 19
19 #include "native_client/src/trusted/plugin/origin.h" 20 #include "native_client/src/trusted/plugin/origin.h"
20 #include "native_client/src/trusted/plugin/srpc/closure.h" 21 #include "native_client/src/trusted/plugin/srpc/closure.h"
21 #include "native_client/src/trusted/plugin/srpc/desc_based_handle.h" 22 #include "native_client/src/trusted/plugin/srpc/desc_based_handle.h"
22 #include "native_client/src/trusted/plugin/srpc/shared_memory.h" 23 #include "native_client/src/trusted/plugin/srpc/shared_memory.h"
23 #include "native_client/src/trusted/plugin/srpc/srpc.h" 24 #include "native_client/src/trusted/plugin/srpc/srpc.h"
24 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 25 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
25 26
26 struct NPObject; 27 struct NPObject;
27 28
28 namespace nacl_srpc { 29 namespace nacl_srpc {
29 30
30 bool Closure::StartDownload() { 31 bool Closure::StartDownload() {
31 dprintf(("StartDownload plugin_identifier_=%p, url_=%s, this=%p\n", 32 dprintf(("StartDownload plugin_identifier_=%p, url_=%s, this=%p\n",
32 reinterpret_cast<void*>(plugin_identifier_), 33 reinterpret_cast<void*>(plugin_identifier_),
33 url_.c_str(), 34 url_.c_str(),
34 reinterpret_cast<void*>(this))); 35 reinterpret_cast<void*>(this)));
35 NPError err = NPN_GetURLNotify(plugin_identifier_, url_.c_str(), NULL, this); 36 NPError err = NPN_GetURLNotify(plugin_identifier_, url_.c_str(), NULL, this);
36 return (NPERR_NO_ERROR == err); 37 return (NPERR_NO_ERROR == err);
37 } 38 }
38 39
39 LoadNaClAppNotify::LoadNaClAppNotify(Plugin* plugin, std::string url) 40 LoadNaClAppNotify::LoadNaClAppNotify(Plugin* plugin,
40 : Closure(plugin, url) { 41 const std::list<std::string>& urls)
41 dprintf(("LoadNaClAppNotify ctor\n")); 42 : Closure(plugin, urls.front()),
43 fallback_urls_(urls) {
44 fallback_urls_.pop_front();
45 dprintf(("LoadNaClAppNotify ctor (trying URL %s + %d more)\n",
46 url().c_str(), fallback_urls_.size()));
42 } 47 }
43 48
44 LoadNaClAppNotify::~LoadNaClAppNotify() { 49 LoadNaClAppNotify::~LoadNaClAppNotify() {
45 dprintf(("LoadNaClAppNotify dtor\n")); 50 dprintf(("LoadNaClAppNotify dtor\n"));
46 } 51 }
47 52
48 void LoadNaClAppNotify::Run(NPStream* stream, const char* fname) { 53 void LoadNaClAppNotify::Run(NPStream* stream, const char* fname) {
49 dprintf(("LoadNaClAppNotify Run %p, %s\n", 54 dprintf(("LoadNaClAppNotify Run %p, %s\n",
50 static_cast<void*>(stream), 55 static_cast<void*>(stream),
51 fname)); 56 fname));
52 if (NULL != fname) { 57 if (NULL != fname) {
58 assert(stream != NULL);
53 plugin()->Load(stream->url, fname); 59 plugin()->Load(stream->url, fname);
60 } else {
61 // Loading failed. Try another URL if we have one.
62 if (fallback_urls_.size() > 0) {
63 LoadNaClAppNotify* callback =
64 new(std::nothrow) LoadNaClAppNotify(plugin(), fallback_urls_);
65 if ((NULL == callback) || (!callback->StartDownload())) {
66 dprintf(("Failed to load URL to local file.\n"));
67 // callback is always deleted in URLNotify
68 // FIXME(adonovan): it is? even when StartDownload failed?
69 // FIXME(adonovan): shouldn't this result in the onfail handler
70 // getting called?
71 }
72 }
54 } 73 }
55 } 74 }
56 75
57 void LoadNaClAppNotify::Run(const char *url, 76 void LoadNaClAppNotify::Run(const char *url,
58 const void* buffer, 77 const void* buffer,
59 int32_t size) { 78 int32_t size) {
60 dprintf(("LoadNaClAppNotify Run %s, %p, %x\n", url, buffer, size)); 79 dprintf(("LoadNaClAppNotify Run %s, %p, %x\n", url, buffer, size));
61 if (NULL != buffer) { 80 if (NULL != buffer) {
62 plugin()->Load(url, url, buffer, size); 81 plugin()->Load(url, url, buffer, size);
63 } 82 }
64 } 83 }
65 84
66
67 UrlAsNaClDescNotify::UrlAsNaClDescNotify(Plugin* plugin, 85 UrlAsNaClDescNotify::UrlAsNaClDescNotify(Plugin* plugin,
68 std::string url, 86 std::string url,
69 void* callback_obj) : 87 void* callback_obj) :
70 Closure(plugin, url), 88 Closure(plugin, url),
71 np_callback_(reinterpret_cast<NPObject*>(callback_obj)) { 89 np_callback_(reinterpret_cast<NPObject*>(callback_obj)) {
72 dprintf(("UrlAsNaClDescNotify ctor\n")); 90 dprintf(("UrlAsNaClDescNotify ctor\n"));
73 NPN_RetainObject(np_callback_); 91 NPN_RetainObject(np_callback_);
74 } 92 }
75 93
76 UrlAsNaClDescNotify::~UrlAsNaClDescNotify() { 94 UrlAsNaClDescNotify::~UrlAsNaClDescNotify() {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 const_cast<NaClDesc*>( 364 const_cast<NaClDesc*>(
347 reinterpret_cast<const NaClDesc*>(NaClDescInvalidMake())); 365 reinterpret_cast<const NaClDesc*>(NaClDescInvalidMake()));
348 module_->StreamAsFile(npp_, invalid, const_cast<char*>(url)); 366 module_->StreamAsFile(npp_, invalid, const_cast<char*>(url));
349 } else { 367 } else {
350 module_->StreamAsFile(npp_, ndshm->desc(), const_cast<char*>(url)); 368 module_->StreamAsFile(npp_, ndshm->desc(), const_cast<char*>(url));
351 ndshm->Delete(); 369 ndshm->Delete();
352 } 370 }
353 } 371 }
354 372
355 } // namespace nacl_srpc 373 } // namespace nacl_srpc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698