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

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

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 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLOSURE_H_ 8 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLOSURE_H_
9 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLOSURE_H_ 9 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLOSURE_H_
10 10
11 #include <list>
11 #include <string> 12 #include <string>
12 13
13 #include "native_client/src/shared/npruntime/npmodule.h" 14 #include "native_client/src/shared/npruntime/npmodule.h"
14 #include "native_client/src/trusted/plugin/npinstance.h" 15 #include "native_client/src/trusted/plugin/npinstance.h"
15 #include "native_client/src/trusted/plugin/srpc/plugin.h" 16 #include "native_client/src/trusted/plugin/srpc/plugin.h"
16 17
17 namespace nacl { 18 namespace nacl {
18 class StreamBuffer; 19 class StreamBuffer;
19 } 20 }
20 21
21 namespace nacl_srpc { 22 namespace nacl_srpc {
22 23
23 /* 24 /*
24 * Closure base class. Following our C++ style rules, we have 25 * Closure base class. Following our C++ style rules, we have
25 * an explicit Run method rather than overload the operator(). 26 * an explicit Run method rather than overload the operator().
26 * 27 *
27 * This is pretty generic, actually, and not restricted to be used for 28 * This is pretty generic, actually, and not restricted to be used for
28 * notification callbacks. 29 * notification callbacks.
29 */ 30 */
30 class Closure { 31 class Closure {
31 public: 32 public:
32 Closure(Plugin* plugin, std::string url) : 33 Closure(Plugin* plugin, std::string url) :
33 plugin_(plugin), url_(url), buffer_(NULL) { 34 plugin_(plugin), url_(url), buffer_(NULL) {
34 if (NULL != plugin_) { 35 if (NULL != plugin_) {
35 plugin_identifier_ = 36 plugin_identifier_ =
36 plugin_->GetPortablePluginInterface()->GetPluginIdentifier(); 37 plugin_->GetPortablePluginInterface()->GetPluginIdentifier();
37 } 38 }
38 } 39 }
39 virtual ~Closure() {} 40 virtual ~Closure() {}
41 /* TODO(adonovan): documentation, especially nullness invariants. */
40 virtual void Run(NPStream *stream, const char *fname) = 0; 42 virtual void Run(NPStream *stream, const char *fname) = 0;
41 virtual void Run(const char *url, const void* buffer, int32_t size) = 0; 43 virtual void Run(const char *url, const void* buffer, int32_t size) = 0;
42 bool StartDownload(); 44 bool StartDownload();
43 void set_plugin(nacl_srpc::Plugin* plugin) { 45 void set_plugin(nacl_srpc::Plugin* plugin) {
44 plugin_ = plugin; 46 plugin_ = plugin;
45 plugin_identifier_ = 47 plugin_identifier_ =
46 plugin_->GetPortablePluginInterface()->GetPluginIdentifier(); 48 plugin_->GetPortablePluginInterface()->GetPluginIdentifier();
47 } 49 }
48 void set_buffer(nacl::StreamBuffer* buffer) { buffer_ = buffer; } 50 void set_buffer(nacl::StreamBuffer* buffer) { buffer_ = buffer; }
49 nacl::StreamBuffer* buffer() { return buffer_; } 51 nacl::StreamBuffer* buffer() { return buffer_; }
50 protected: 52 protected:
51 Plugin* plugin() { return plugin_; } 53 Plugin* plugin() { return plugin_; }
54 const std::string& url() const { return url_; }
52 private: 55 private:
53 Plugin* plugin_; 56 Plugin* plugin_;
54 std::string url_; 57 std::string url_;
55 nacl::StreamBuffer *buffer_; 58 nacl::StreamBuffer *buffer_;
56 nacl_srpc::PluginIdentifier plugin_identifier_; 59 nacl_srpc::PluginIdentifier plugin_identifier_;
57 }; 60 };
58 61
59 class LoadNaClAppNotify : public Closure { 62 class LoadNaClAppNotify : public Closure {
60 public: 63 public:
61 LoadNaClAppNotify(Plugin *plugin, std::string url); 64 // Precondition: urls.list() > 0.
65 LoadNaClAppNotify(Plugin *plugin, const std::list<std::string>& urls);
62 virtual ~LoadNaClAppNotify(); 66 virtual ~LoadNaClAppNotify();
67 // Run(NULL, NULL) is called if the request failed; a new request
68 // for the fallback_urls should be initiated.
63 virtual void Run(NPStream* stream, const char* fname); 69 virtual void Run(NPStream* stream, const char* fname);
64 virtual void Run(const char *url, const void* buffer, int32_t size); 70 virtual void Run(const char *url, const void* buffer, int32_t size);
71 private:
72 // The list of alternative URLs to try should this request fail.
73 std::list<std::string> fallback_urls_;
65 }; 74 };
66 75
67 class UrlAsNaClDescNotify : public Closure { 76 class UrlAsNaClDescNotify : public Closure {
68 public: 77 public:
69 UrlAsNaClDescNotify(Plugin *plugin, std::string url, void *callback_obj); 78 UrlAsNaClDescNotify(Plugin *plugin, std::string url, void *callback_obj);
70 virtual ~UrlAsNaClDescNotify(); 79 virtual ~UrlAsNaClDescNotify();
71 virtual void Run(NPStream *stream, const char *fname); 80 virtual void Run(NPStream *stream, const char *fname);
72 virtual void Run(const char *url, const void* buffer, int32_t size); 81 virtual void Run(const char *url, const void* buffer, int32_t size);
73 private: 82 private:
74 NPObject* np_callback_; 83 NPObject* np_callback_;
75 }; 84 };
76 85
77 class NpGetUrlClosure : public Closure { 86 class NpGetUrlClosure : public Closure {
78 public: 87 public:
79 NpGetUrlClosure(NPP npp, nacl::NPModule* module, std::string url); 88 NpGetUrlClosure(NPP npp, nacl::NPModule* module, std::string url);
80 virtual ~NpGetUrlClosure(); 89 virtual ~NpGetUrlClosure();
81 virtual void Run(NPStream* stream, const char* fname); 90 virtual void Run(NPStream* stream, const char* fname);
82 virtual void Run(const char* url, const void* buffer, int32_t size); 91 virtual void Run(const char* url, const void* buffer, int32_t size);
83 92
84 private: 93 private:
85 nacl::NPModule* module_; 94 nacl::NPModule* module_;
86 NPP npp_; 95 NPP npp_;
87 }; 96 };
88 } // namespace nacl_srpc 97 } // namespace nacl_srpc
89 98
90 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLOSURE_H_ 99 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLOSURE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698