<commit_before>// Copyright (c) 2006-2008 The Chromium Authors. 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/http_network_layer.h"

#include "base/logging.h"
#include "net/base/client_socket_factory.h"
#include "net/http/http_network_session.h"
#include "net/http/http_network_transaction.h"
#include "net/proxy/proxy_resolver_fixed.h"
#include "net/proxy/proxy_resolver_null.h"
#if defined(OS_WIN)
#include "net/http/http_transaction_winhttp.h"
#include "net/proxy/proxy_resolver_winhttp.h"
#elif defined(OS_MACOSX)
#include "net/proxy/proxy_resolver_mac.h"
#endif

namespace net {

//-----------------------------------------------------------------------------

#if defined(OS_WIN)
// static
bool HttpNetworkLayer::use_winhttp_ = false;
#endif

// static
HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
    const ProxyInfo* pi) {
#if defined(OS_WIN)
  if (use_winhttp_)
    return new HttpTransactionWinHttp::Factory(pi);
#endif

  return new HttpNetworkLayer(pi);
}

#if defined(OS_WIN)
// static
void HttpNetworkLayer::UseWinHttp(bool value) {
  use_winhttp_ = value;
}
#endif

//-----------------------------------------------------------------------------

HttpNetworkLayer::HttpNetworkLayer(const ProxyInfo* pi)
    : suspended_(false) {
  if (pi) {
    proxy_resolver_.reset(new ProxyResolverFixed(*pi));
  } else {
#if defined(OS_WIN)
    proxy_resolver_.reset(new ProxyResolverWinHttp());
#elif defined(OS_MACOSX)
    proxy_resolver_.reset(new ProxyResolverMac());
#else
    NOTIMPLEMENTED();
    proxy_resolver_.reset(new ProxyResolverNull());
#endif
  }
}

HttpNetworkLayer::~HttpNetworkLayer() {
}

HttpTransaction* HttpNetworkLayer::CreateTransaction() {
  if (suspended_)
    return NULL;

  if (!session_)
    session_ = new HttpNetworkSession(proxy_resolver_.release());

  return new HttpNetworkTransaction(
      session_, ClientSocketFactory::GetDefaultFactory());
}

HttpCache* HttpNetworkLayer::GetCache() {
  return NULL;
}

void HttpNetworkLayer::Suspend(bool suspend) {
  suspended_ = suspend;
<commit_msg>Punt the proxy errors into a bug.<commit_after>// Copyright (c) 2006-2008 The Chromium Authors. 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/http_network_layer.h"

#include "base/logging.h"
#include "net/base/client_socket_factory.h"
#include "net/http/http_network_session.h"
#include "net/http/http_network_transaction.h"
#include "net/proxy/proxy_resolver_fixed.h"
#include "net/proxy/proxy_resolver_null.h"
#if defined(OS_WIN)
#include "net/http/http_transaction_winhttp.h"
#include "net/proxy/proxy_resolver_winhttp.h"
#elif defined(OS_MACOSX)
#include "net/proxy/proxy_resolver_mac.h"
#endif

namespace net {

//-----------------------------------------------------------------------------

#if defined(OS_WIN)
// static
bool HttpNetworkLayer::use_winhttp_ = false;
#endif

// static
HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
    const ProxyInfo* pi) {
#if defined(OS_WIN)
  if (use_winhttp_)
    return new HttpTransactionWinHttp::Factory(pi);
#endif

  return new HttpNetworkLayer(pi);
}

#if defined(OS_WIN)
// static
void HttpNetworkLayer::UseWinHttp(bool value) {
  use_winhttp_ = value;
}
#endif

//-----------------------------------------------------------------------------

HttpNetworkLayer::HttpNetworkLayer(const ProxyInfo* pi)
    : suspended_(false) {
  if (pi) {
    proxy_resolver_.reset(new ProxyResolverFixed(*pi));
  } else {
#if defined(OS_WIN)
    proxy_resolver_.reset(new ProxyResolverWinHttp());
#elif defined(OS_MACOSX)
    proxy_resolver_.reset(new ProxyResolverMac());
#else
    // This used to be a NOTIMPLEMENTED(), but that logs as an error,
    // screwing up layout tests.
    LOG(WARNING) << "Proxies are not implemented; remove me once that's fixed.";
    // http://code.google.com/p/chromium/issues/detail?id=4523 is the bug
    // to implement this.
    proxy_resolver_.reset(new ProxyResolverNull());
#endif
  }
}

HttpNetworkLayer::~HttpNetworkLayer() {
}

HttpTransaction* HttpNetworkLayer::CreateTransaction() {
  if (suspended_)
    return NULL;

  if (!session_)
    session_ = new HttpNetworkSession(proxy_resolver_.release());

  return new HttpNetworkTransaction(
      session_, ClientSocketFactory::GetDefaultFactory());
}

HttpCache* HttpNetworkLayer::GetCache() {
  return NULL;
}

void HttpNetworkLayer::Suspend(bool suspend) {
  suspended_ = suspend;

{'fraction_non_alphanumeric': 0.17857142857142858, 'fraction_numerical': 0.0043821209465381246, 'mean_word_length': 3.565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7033983', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1405, 'n_words': 312}