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

Side by Side Diff: net/websockets/websocket_job.h

Issue 669157: Refactor WebSocket throttling feature. (Closed)
Patch Set: Fix for tyoshino's comment 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
« no previous file with comments | « net/socket_stream/socket_stream_throttle.cc ('k') | net/websockets/websocket_job.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 Authors. All rights reserved. 1 // Copyright (c) 2010 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 #ifndef NET_WEBSOCKETS_WEBSOCKET_JOB_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_JOB_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_JOB_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_JOB_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "net/base/address_list.h"
12 #include "net/base/completion_callback.h" 13 #include "net/base/completion_callback.h"
13 #include "net/socket_stream/socket_stream_job.h" 14 #include "net/socket_stream/socket_stream_job.h"
14 15
15 class GURL; 16 class GURL;
16 17
17 namespace net { 18 namespace net {
18 19
19 // WebSocket protocol specific job on SocketStream. 20 // WebSocket protocol specific job on SocketStream.
20 // It captures WebSocket handshake message and handles cookie operations. 21 // It captures WebSocket handshake message and handles cookie operations.
21 // Chome security policy doesn't allow renderer process (except dev tools) 22 // Chrome security policy doesn't allow renderer process (except dev tools)
22 // see HttpOnly cookies, so it injects cookie header in handshake request and 23 // see HttpOnly cookies, so it injects cookie header in handshake request and
23 // strips set-cookie headers in handshake response. 24 // strips set-cookie headers in handshake response.
24 // TODO(ukai): refactor to merge WebSocketThrottle functionality.
25 // TODO(ukai): refactor websocket.cc to use this. 25 // TODO(ukai): refactor websocket.cc to use this.
26 class WebSocketJob : public SocketStreamJob, public SocketStream::Delegate { 26 class WebSocketJob : public SocketStreamJob, public SocketStream::Delegate {
27 public: 27 public:
28 // This is state of WebSocket, not SocketStream. 28 // This is state of WebSocket, not SocketStream.
29 enum State { 29 enum State {
30 INITIALIZED = -1, 30 INITIALIZED = -1,
31 CONNECTING = 0, 31 CONNECTING = 0,
32 OPEN = 1, 32 OPEN = 1,
33 CLOSED = 2, 33 CLOSED = 2,
34 }; 34 };
35 static void EnsureInit(); 35 static void EnsureInit();
36 36
37 explicit WebSocketJob(SocketStream::Delegate* delegate); 37 explicit WebSocketJob(SocketStream::Delegate* delegate);
38 38
39 State state() const { return state_; }
39 virtual void Connect(); 40 virtual void Connect();
40 virtual bool SendData(const char* data, int len); 41 virtual bool SendData(const char* data, int len);
41 virtual void Close(); 42 virtual void Close();
42 virtual void RestartWithAuth( 43 virtual void RestartWithAuth(
43 const std::wstring& username, 44 const std::wstring& username,
44 const std::wstring& password); 45 const std::wstring& password);
45 virtual void DetachDelegate(); 46 virtual void DetachDelegate();
46 47
47 // SocketStream::Delegate methods. 48 // SocketStream::Delegate methods.
49 virtual int OnStartOpenConnection(
50 SocketStream* socket, CompletionCallback* callback);
48 virtual void OnConnected( 51 virtual void OnConnected(
49 SocketStream* socket, int max_pending_send_allowed); 52 SocketStream* socket, int max_pending_send_allowed);
50 virtual void OnSentData( 53 virtual void OnSentData(
51 SocketStream* socket, int amount_sent); 54 SocketStream* socket, int amount_sent);
52 virtual void OnReceivedData( 55 virtual void OnReceivedData(
53 SocketStream* socket, const char* data, int len); 56 SocketStream* socket, const char* data, int len);
54 virtual void OnClose(SocketStream* socket); 57 virtual void OnClose(SocketStream* socket);
55 virtual void OnAuthRequired( 58 virtual void OnAuthRequired(
56 SocketStream* socket, AuthChallengeInfo* auth_info); 59 SocketStream* socket, AuthChallengeInfo* auth_info);
57 virtual void OnError( 60 virtual void OnError(
58 const SocketStream* socket, int error); 61 const SocketStream* socket, int error);
59 62
60 private: 63 private:
64 friend class WebSocketThrottle;
61 friend class WebSocketJobTest; 65 friend class WebSocketJobTest;
62 virtual ~WebSocketJob(); 66 virtual ~WebSocketJob();
63 67
64 bool SendHandshakeRequest(const char* data, int len); 68 bool SendHandshakeRequest(const char* data, int len);
65 void AddCookieHeaderAndSend(); 69 void AddCookieHeaderAndSend();
66 void OnCanGetCookiesCompleted(int policy); 70 void OnCanGetCookiesCompleted(int policy);
67 71
68 void OnSentHandshakeRequest(SocketStream* socket, int amount_sent); 72 void OnSentHandshakeRequest(SocketStream* socket, int amount_sent);
69 void OnReceivedHandshakeResponse( 73 void OnReceivedHandshakeResponse(
70 SocketStream* socket, const char* data, int len); 74 SocketStream* socket, const char* data, int len);
71 void SaveCookiesAndNotifyHeaderComplete(); 75 void SaveCookiesAndNotifyHeaderComplete();
72 void SaveNextCookie(); 76 void SaveNextCookie();
73 void OnCanSetCookieCompleted(int policy); 77 void OnCanSetCookieCompleted(int policy);
74 78
75 GURL GetURLForCookies() const; 79 GURL GetURLForCookies() const;
76 80
81 const AddressList& address_list() const;
82 void SetWaiting();
83 bool IsWaiting() const;
84 void Wakeup();
85
77 SocketStream::Delegate* delegate_; 86 SocketStream::Delegate* delegate_;
78 State state_; 87 State state_;
88 bool waiting_;
89 AddressList addresses_;
90 CompletionCallback* callback_; // for throttling.
79 91
80 std::string original_handshake_request_; 92 std::string original_handshake_request_;
81 int original_handshake_request_header_length_; 93 int original_handshake_request_header_length_;
82 std::string handshake_request_; 94 std::string handshake_request_;
83 size_t handshake_request_sent_; 95 size_t handshake_request_sent_;
84 96
85 std::string handshake_response_; 97 std::string handshake_response_;
86 int handshake_response_header_length_; 98 int handshake_response_header_length_;
87 std::vector<std::string> response_cookies_; 99 std::vector<std::string> response_cookies_;
88 size_t response_cookies_save_index_; 100 size_t response_cookies_save_index_;
89 101
90 CompletionCallbackImpl<WebSocketJob> can_get_cookies_callback_; 102 CompletionCallbackImpl<WebSocketJob> can_get_cookies_callback_;
91 CompletionCallbackImpl<WebSocketJob> can_set_cookie_callback_; 103 CompletionCallbackImpl<WebSocketJob> can_set_cookie_callback_;
92 104
93 DISALLOW_COPY_AND_ASSIGN(WebSocketJob); 105 DISALLOW_COPY_AND_ASSIGN(WebSocketJob);
94 }; 106 };
95 107
96 } // namespace 108 } // namespace
97 109
98 #endif // NET_WEBSOCKETS_WEBSOCKET_JOB_H_ 110 #endif // NET_WEBSOCKETS_WEBSOCKET_JOB_H_
OLDNEW
« no previous file with comments | « net/socket_stream/socket_stream_throttle.cc ('k') | net/websockets/websocket_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698