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

Side by Side Diff: chrome/browser/extensions/api/socket/socket.h

Issue 76403004: An implementation of chrome.socket.secure(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: An integration test, and some nits fixed. Created 6 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 24 matching lines...) Expand all
35 typedef base::Callback< 35 typedef base::Callback<
36 void(int, net::TCPClientSocket*)> AcceptCompletionCallback; 36 void(int, net::TCPClientSocket*)> AcceptCompletionCallback;
37 37
38 // A Socket wraps a low-level socket and includes housekeeping information that 38 // A Socket wraps a low-level socket and includes housekeeping information that
39 // we need to manage it in the context of an extension. 39 // we need to manage it in the context of an extension.
40 class Socket : public ApiResource { 40 class Socket : public ApiResource {
41 public: 41 public:
42 enum SocketType { 42 enum SocketType {
43 TYPE_TCP, 43 TYPE_TCP,
44 TYPE_UDP, 44 TYPE_UDP,
45 TYPE_TLS
45 }; 46 };
46 47
47 virtual ~Socket(); 48 virtual ~Socket();
49
50 const std::string& hostname() const {
51 return hostname_;
52 }
53
54 void set_hostname(const std::string& hostname) {
55 hostname_ = hostname;
56 }
57
58 // |address| is a resolved IP address. Call set_hostname() to save the
59 // original DNS name of the host if this socket may later get upgraded to
60 // TLS (see TLSSocket::UpgradeSocketToTLS()).
48 virtual void Connect(const std::string& address, 61 virtual void Connect(const std::string& address,
49 int port, 62 int port,
50 const CompletionCallback& callback) = 0; 63 const CompletionCallback& callback) = 0;
51 virtual void Disconnect() = 0; 64 virtual void Disconnect() = 0;
52 virtual int Bind(const std::string& address, int port) = 0; 65 virtual int Bind(const std::string& address, int port) = 0;
53 66
54 // The |callback| will be called with the number of bytes read into the 67 // The |callback| will be called with the number of bytes read into the
55 // buffer, or a negative number if an error occurred. 68 // buffer, or a negative number if an error occurred.
56 virtual void Read(int count, 69 virtual void Read(int count,
57 const ReadCompletionCallback& callback) = 0; 70 const ReadCompletionCallback& callback) = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 108
96 protected: 109 protected:
97 explicit Socket(const std::string& owner_extension_id_); 110 explicit Socket(const std::string& owner_extension_id_);
98 111
99 void WriteData(); 112 void WriteData();
100 virtual int WriteImpl(net::IOBuffer* io_buffer, 113 virtual int WriteImpl(net::IOBuffer* io_buffer,
101 int io_buffer_size, 114 int io_buffer_size,
102 const net::CompletionCallback& callback) = 0; 115 const net::CompletionCallback& callback) = 0;
103 virtual void OnWriteComplete(int result); 116 virtual void OnWriteComplete(int result);
104 117
105 const std::string address_; 118 // The DNS name of the host that this socket is connected to, used when
119 // verifying a TLS certificate.
120 std::string hostname_;
106 bool is_connected_; 121 bool is_connected_;
107 122
108 private: 123 private:
109 friend class ApiResourceManager<Socket>; 124 friend class ApiResourceManager<Socket>;
110 static const char* service_name() { 125 static const char* service_name() {
111 return "SocketManager"; 126 return "SocketManager";
112 } 127 }
113 128
114 struct WriteRequest { 129 struct WriteRequest {
115 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, 130 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer,
116 int byte_count, 131 int byte_count,
117 const CompletionCallback& callback); 132 const CompletionCallback& callback);
118 ~WriteRequest(); 133 ~WriteRequest();
119 scoped_refptr<net::IOBuffer> io_buffer; 134 scoped_refptr<net::IOBuffer> io_buffer;
120 int byte_count; 135 int byte_count;
121 CompletionCallback callback; 136 CompletionCallback callback;
122 int bytes_written; 137 int bytes_written;
123 }; 138 };
124 std::queue<WriteRequest> write_queue_; 139 std::queue<WriteRequest> write_queue_;
125 scoped_refptr<net::IOBuffer> io_buffer_write_; 140 scoped_refptr<net::IOBuffer> io_buffer_write_;
126 }; 141 };
127 142
128 } // namespace extensions 143 } // namespace extensions
129 144
130 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 145 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698