• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "net/socket_stream/socket_stream_job.h"
6 
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"
12 
13 namespace net {
14 
15 // static
RegisterProtocolFactory(const std::string & scheme,ProtocolFactory * factory)16 SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory(
17     const std::string& scheme, ProtocolFactory* factory) {
18   return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory(
19       scheme, factory);
20 }
21 
22 // static
CreateSocketStreamJob(const GURL & url,SocketStream::Delegate * delegate,TransportSecurityState * sts,SSLConfigService * ssl,URLRequestContext * context,CookieStore * cookie_store)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     url::Replacements<char> replacements;
34     static const char kNewScheme[] = "wss";
35     replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme)));
36     socket_url = url.ReplaceComponents(replacements);
37   }
38   return SocketStreamJobManager::GetInstance()->CreateJob(
39       socket_url, delegate, context, cookie_store);
40 }
41 
SocketStreamJob()42 SocketStreamJob::SocketStreamJob() {}
43 
GetUserData(const void * key) const44 SocketStream::UserData* SocketStreamJob::GetUserData(const void* key) const {
45   return socket_->GetUserData(key);
46 }
47 
SetUserData(const void * key,SocketStream::UserData * data)48 void SocketStreamJob::SetUserData(const void* key,
49                                   SocketStream::UserData* data) {
50   socket_->SetUserData(key, data);
51 }
52 
Connect()53 void SocketStreamJob::Connect() {
54   socket_->Connect();
55 }
56 
SendData(const char * data,int len)57 bool SocketStreamJob::SendData(const char* data, int len) {
58   return socket_->SendData(data, len);
59 }
60 
Close()61 void SocketStreamJob::Close() {
62   socket_->Close();
63 }
64 
RestartWithAuth(const AuthCredentials & credentials)65 void SocketStreamJob::RestartWithAuth(const AuthCredentials& credentials) {
66   socket_->RestartWithAuth(credentials);
67 }
68 
CancelWithError(int error)69 void SocketStreamJob::CancelWithError(int error) {
70   socket_->CancelWithError(error);
71 }
72 
CancelWithSSLError(const net::SSLInfo & ssl_info)73 void SocketStreamJob::CancelWithSSLError(const net::SSLInfo& ssl_info) {
74   socket_->CancelWithSSLError(ssl_info);
75 }
76 
ContinueDespiteError()77 void SocketStreamJob::ContinueDespiteError() {
78   socket_->ContinueDespiteError();
79 }
80 
DetachDelegate()81 void SocketStreamJob::DetachDelegate() {
82   socket_->DetachDelegate();
83 }
84 
DetachContext()85 void SocketStreamJob::DetachContext() {
86   if (socket_.get())
87     socket_->DetachContext();
88 }
89 
~SocketStreamJob()90 SocketStreamJob::~SocketStreamJob() {}
91 
92 }  // namespace net
93