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

Side by Side Diff: callback_server.h

Issue 6874035: entd: require a per-entd-invocation session id in every request (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/entd.git@master
Patch Set: few more bug fixes Created 9 years, 8 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
« no previous file with comments | « bin/entdwife.sh ('k') | callback_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 // The callback server listens for http connections on port 5199 (by default), 5 // The callback server listens for http connections on port 5199 (by default),
6 // and dispatches valid requests to javascript function registered by the 6 // and dispatches valid requests to javascript function registered by the
7 // policy. 7 // policy.
8 // 8 //
9 // The incoming request must be an HTTP POST (libevent doesn't have an https 9 // The incoming request must be an HTTP POST (libevent doesn't have an https
10 // server) to the uri "/dispatch". It must have a content-type of 10 // server) to the uri "/dispatch". It must have a content-type of
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 static void SetTemplateBindings( 48 static void SetTemplateBindings(
49 v8::Handle<v8::ObjectTemplate> template_object); 49 v8::Handle<v8::ObjectTemplate> template_object);
50 50
51 // Initialize the CallbackServer instance. Must be called before any 51 // Initialize the CallbackServer instance. Must be called before any
52 // other method. 52 // other method.
53 virtual bool Initialize() { 53 virtual bool Initialize() {
54 JSObjectWrapper<CallbackServer>::Initialize(); 54 JSObjectWrapper<CallbackServer>::Initialize();
55 return true; 55 return true;
56 } 56 }
57 57
58 virtual std::string request_header_value() {
59 return request_header_value_;
60 }
61
62 virtual void set_request_header_value(std::string value) {
63 request_header_value_ = value;
64 }
65
66 // Start the callback server with a particular set of callbacks and 58 // Start the callback server with a particular set of callbacks and
67 // on a given port number. 59 // on a given port number.
68 virtual bool Start(v8::Handle<v8::Object> callbacks, int port); 60 virtual bool Start(v8::Handle<v8::Object> callbacks, int port);
69 61
70 // Stop the server. 62 // Stop the server.
71 virtual void Stop(); 63 virtual void Stop();
72 64
73 // Return true if the callback server has been started. 65 // Return true if the callback server has been started.
74 virtual bool IsRunning(); 66 virtual bool IsRunning();
75 67
76 // Dispatch a given http request. 68 // Dispatch a given http request.
77 virtual void OnRequest(struct evhttp_request* request); 69 virtual void OnRequest(struct evhttp_request* request);
78 70
79 // Sets whether or not the server is busy. While busy, it cannot be stopped. 71 // Sets whether or not the server is busy. While busy, it cannot be stopped.
80 // This should only matter when someone attempts to stop the server from 72 // This should only matter when someone attempts to stop the server from
81 // script during a callback. In other cases, the single threadedness of 73 // script during a callback. In other cases, the single threadedness of
82 // entd should keep us from ever trying to stop while busy. This is not 74 // entd should keep us from ever trying to stop while busy. This is not
83 // nestable. 75 // nestable.
84 virtual void SetBusy(bool state) { 76 virtual void SetBusy(bool state) {
85 if (state == busy_) 77 if (state == busy_)
86 LOG(WARNING) << "Busy status is already " << (state ? "set" : "clear"); 78 LOG(WARNING) << "Busy status is already " << (state ? "set" : "clear");
87 busy_ = state; 79 busy_ = state;
88 }; 80 };
89 virtual bool IsBusy() { return busy_; } 81 virtual bool IsBusy() { return busy_; }
90 82
83 static void SetSessionId(const std::string& session_id) {
rginda 2011/04/18 16:55:20 lowercase_and_underscores
84 session_id_ = session_id;
85 }
86
87 static std::string session_id() {
88 return session_id_;
89 }
90
91 static std::string required_origin; 91 static std::string required_origin;
92 92
93 private: 93 private:
94 // State for SetBusy/IsBusy. 94 // State for SetBusy/IsBusy.
95 bool busy_; 95 bool busy_;
96 96
97 // Parent entd object. 97 // Parent entd object.
98 Entd* entd_; 98 Entd* entd_;
99 99
100 // JS Object containing the callback functions we might dispatch to. 100 // JS Object containing the callback functions we might dispatch to.
101 v8::Persistent<v8::Object> callbacks_; 101 v8::Persistent<v8::Object> callbacks_;
102 102
103 // The value required in the X-Entd-Request header. 103 // X-Entd-Session-Id that must come in every request.
104 std::string request_header_value_; 104 static std::string session_id_;
105 105
106 // Non-null if the server is running. 106 // Non-null if the server is running.
107 struct evhttp* evhttp_; 107 struct evhttp* evhttp_;
108 108
109 // Port we're listening on, or 0 if not running. 109 // Port we're listening on, or 0 if not running.
110 int port_; 110 int port_;
111 111
112 DISALLOW_COPY_AND_ASSIGN(CallbackServer); 112 DISALLOW_COPY_AND_ASSIGN(CallbackServer);
113 }; 113 };
114 114
115 } // namespace entd 115 } // namespace entd
116 116
117 #endif // ENTD_CALLBACK_SERVER_H_ 117 #endif // ENTD_CALLBACK_SERVER_H_
OLDNEW
« no previous file with comments | « bin/entdwife.sh ('k') | callback_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698