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
3 // found in the LICENSE file.
5 #include "net/socket_stream/socket_stream_job.h"
7 #include "base/memory/singleton.h"
8 #include "net/http/transport_security_state.h"
9 #include "net/socket_stream/socket_stream_job_manager.h"
10 #include "net/ssl/ssl_config_service.h"
11 #include "net/url_request/url_request_context.h"
16 SocketStreamJob::ProtocolFactory
* SocketStreamJob::RegisterProtocolFactory(
17 const std::string
& scheme
, ProtocolFactory
* factory
) {
18 return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory(
23 SocketStreamJob
* SocketStreamJob::CreateSocketStreamJob(
25 SocketStream::Delegate
* delegate
,
26 TransportSecurityState
* sts
,
27 SSLConfigService
* ssl
,
28 URLRequestContext
* context
,
29 CookieStore
* cookie_store
) {
31 if (url
.scheme() == "ws" && sts
&&
32 sts
->ShouldUpgradeToSSL(url
.host(),
33 SSLConfigService::IsSNIAvailable(ssl
))) {
34 url::Replacements
<char> replacements
;
35 static const char kNewScheme
[] = "wss";
36 replacements
.SetScheme(kNewScheme
, url::Component(0, strlen(kNewScheme
)));
37 socket_url
= url
.ReplaceComponents(replacements
);
39 return SocketStreamJobManager::GetInstance()->CreateJob(
40 socket_url
, delegate
, context
, cookie_store
);
43 SocketStreamJob::SocketStreamJob() {}
45 SocketStream::UserData
* SocketStreamJob::GetUserData(const void* key
) const {
46 return socket_
->GetUserData(key
);
49 void SocketStreamJob::SetUserData(const void* key
,
50 SocketStream::UserData
* data
) {
51 socket_
->SetUserData(key
, data
);
54 void SocketStreamJob::Connect() {
58 bool SocketStreamJob::SendData(const char* data
, int len
) {
59 return socket_
->SendData(data
, len
);
62 void SocketStreamJob::Close() {
66 void SocketStreamJob::RestartWithAuth(const AuthCredentials
& credentials
) {
67 socket_
->RestartWithAuth(credentials
);
70 void SocketStreamJob::CancelWithError(int error
) {
71 socket_
->CancelWithError(error
);
74 void SocketStreamJob::CancelWithSSLError(const net::SSLInfo
& ssl_info
) {
75 socket_
->CancelWithSSLError(ssl_info
);
78 void SocketStreamJob::ContinueDespiteError() {
79 socket_
->ContinueDespiteError();
82 void SocketStreamJob::DetachDelegate() {
83 socket_
->DetachDelegate();
86 void SocketStreamJob::DetachContext() {
88 socket_
->DetachContext();
91 SocketStreamJob::~SocketStreamJob() {}