Home | History | Annotate | Download | only in socket_stream
      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
     16 SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory(
     17     const std::string& scheme, ProtocolFactory* factory) {
     18   return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory(
     19       scheme, factory);
     20 }
     21 
     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     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 
     42 SocketStreamJob::SocketStreamJob() {}
     43 
     44 SocketStream::UserData* SocketStreamJob::GetUserData(const void* key) const {
     45   return socket_->GetUserData(key);
     46 }
     47 
     48 void SocketStreamJob::SetUserData(const void* key,
     49                                   SocketStream::UserData* data) {
     50   socket_->SetUserData(key, data);
     51 }
     52 
     53 void SocketStreamJob::Connect() {
     54   socket_->Connect();
     55 }
     56 
     57 bool SocketStreamJob::SendData(const char* data, int len) {
     58   return socket_->SendData(data, len);
     59 }
     60 
     61 void SocketStreamJob::Close() {
     62   socket_->Close();
     63 }
     64 
     65 void SocketStreamJob::RestartWithAuth(const AuthCredentials& credentials) {
     66   socket_->RestartWithAuth(credentials);
     67 }
     68 
     69 void SocketStreamJob::CancelWithError(int error) {
     70   socket_->CancelWithError(error);
     71 }
     72 
     73 void SocketStreamJob::CancelWithSSLError(const net::SSLInfo& ssl_info) {
     74   socket_->CancelWithSSLError(ssl_info);
     75 }
     76 
     77 void SocketStreamJob::ContinueDespiteError() {
     78   socket_->ContinueDespiteError();
     79 }
     80 
     81 void SocketStreamJob::DetachDelegate() {
     82   socket_->DetachDelegate();
     83 }
     84 
     85 void SocketStreamJob::DetachContext() {
     86   if (socket_.get())
     87     socket_->DetachContext();
     88 }
     89 
     90 SocketStreamJob::~SocketStreamJob() {}
     91 
     92 }  // namespace net
     93