blob: 7f8175d83164cb375df0ae8247412df9e7180a8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_
#define NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_
#pragma once
#include <string>
#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "net/base/net_api.h"
#include "net/socket_stream/socket_stream.h"
class GURL;
namespace net {
class SSLConfigService;
class TransportSecurityState;
// SocketStreamJob represents full-duplex communication over SocketStream.
// If a protocol (e.g. WebSocket protocol) needs to inspect/modify data
// over SocketStream, you can implement protocol specific job (e.g.
// WebSocketJob) to do some work on data over SocketStream.
// Registers the protocol specific SocketStreamJob by RegisterProtocolFactory
// and call CreateSocketStreamJob to create SocketStreamJob for the URL.
class NET_API SocketStreamJob
: public base::RefCountedThreadSafe<SocketStreamJob> {
public:
// Callback function implemented by protocol handlers to create new jobs.
typedef SocketStreamJob* (ProtocolFactory)(const GURL& url,
SocketStream::Delegate* delegate);
static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
ProtocolFactory* factory);
static SocketStreamJob* CreateSocketStreamJob(
const GURL& url,
SocketStream::Delegate* delegate,
TransportSecurityState* sts,
SSLConfigService* ssl);
SocketStreamJob();
void InitSocketStream(SocketStream* socket) {
socket_ = socket;
}
virtual SocketStream::UserData* GetUserData(const void* key) const;
virtual void SetUserData(const void* key, SocketStream::UserData* data);
URLRequestContext* context() const {
return socket_->context();
}
void set_context(URLRequestContext* context) {
socket_->set_context(context);
}
virtual void Connect();
virtual bool SendData(const char* data, int len);
virtual void Close();
virtual void RestartWithAuth(const string16& username,
const string16& password);
virtual void DetachDelegate();
protected:
friend class WebSocketJobTest;
friend class base::RefCountedThreadSafe<SocketStreamJob>;
virtual ~SocketStreamJob();
scoped_refptr<SocketStream> socket_;
DISALLOW_COPY_AND_ASSIGN(SocketStreamJob);
};
} // namespace net
#endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_
|