summaryrefslogtreecommitdiffstats
path: root/net/http/preconnect.cc
blob: 929b627015c7d2d71cd517e471387af75856ff56 (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
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2012, Code Aurora Forum. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/http/preconnect.h"

#include "base/logging.h"
#include "net/proxy/proxy_info.h"
#include "net/http/http_stream_factory.h"
#include "net/http/http_network_session.h"

namespace net {


// static
void Preconnect::DoPreconnect(HttpNetworkSession* session,
    const GURL& url, int count,
    HttpRequestInfo::RequestMotivation motivation ) {
  Preconnect* preconnect = new Preconnect(session);
  preconnect->Connect(url, count, motivation);
}

Preconnect::Preconnect(HttpNetworkSession* session)
  : session_(session),
  ALLOW_THIS_IN_INITIALIZER_LIST(
      io_callback_(this, &Preconnect::OnPreconnectComplete)) {}

Preconnect::~Preconnect() {}

void Preconnect::Connect(const GURL& url, int count,
    HttpRequestInfo::RequestMotivation motivation) {

  request_info_.reset(new HttpRequestInfo());
  request_info_->url = url;
  request_info_->method = "GET";
  // It almost doesn't matter whether we use net::LOWEST or net::HIGHEST
  // priority here, as we won't make a request, and will surrender the created
  // socket to the pool as soon as we can.  However, we would like to mark the
  // speculative socket as such, and IF we use a net::LOWEST priority, and if
  // a navigation asked for a socket (after us) then it would get our socket,
  // and we'd get its later-arriving socket, which might make us record that
  // the speculation didn't help :-/.  By using net::HIGHEST, we ensure that
  // a socket is given to us if "we asked first" and this allows us to mark it
  // as speculative, and better detect stats (if it gets used).
  // TODO(jar): histogram to see how often we accidentally use a previously-
  // unused socket, when a previously used socket was available.
  request_info_->priority = HIGHEST;
  request_info_->motivation = motivation;

  // Setup the SSL Configuration.
  ssl_config_.reset(new SSLConfig());
  session_->ssl_config_service()->GetSSLConfig(ssl_config_.get());
  if (session_->http_stream_factory()->next_protos())
    ssl_config_->next_protos = *session_->http_stream_factory()->next_protos();

  // All preconnects should perform EV certificate verification.
  ssl_config_->verify_ev_cert = true;

  proxy_info_.reset(new ProxyInfo());
  HttpStreamFactory* stream_factory = session_->http_stream_factory();
  stream_factory->PreconnectStreams(count, *(request_info_.get()),
      *(ssl_config_.get()), net_log_);
}

void Preconnect::OnPreconnectComplete(int error_code) {
  delete this;
}

}  // namespace net