Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / socket_stream / socket_stream_job.cc
bloba481b97526e2a314373d5331e60710fce9720aac
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"
13 namespace net {
15 // static
16 SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory(
17 const std::string& scheme, ProtocolFactory* factory) {
18 return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory(
19 scheme, factory);
22 // static
23 SocketStreamJob* SocketStreamJob::CreateSocketStreamJob(
24 const GURL& url,
25 SocketStream::Delegate* delegate,
26 TransportSecurityState* sts,
27 SSLConfigService* ssl,
28 URLRequestContext* context,
29 CookieStore* cookie_store) {
30 GURL socket_url(url);
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() {
55 socket_->Connect();
58 bool SocketStreamJob::SendData(const char* data, int len) {
59 return socket_->SendData(data, len);
62 void SocketStreamJob::Close() {
63 socket_->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() {
87 if (socket_.get())
88 socket_->DetachContext();
91 SocketStreamJob::~SocketStreamJob() {}
93 } // namespace net