Skip to content

Commit

Permalink
Main benefits of NetLog inner classes extraction:
Browse files Browse the repository at this point in the history
- Greater code organization.
- Promotion of files being "include-what-you-use" clean. Less files now need
  to include "net_log.h"; these files are no longer susceptible to having their
  includes hidden by the many inner includes of "net_log.h".
- All touched files are also now forward-clean re: NetLog,
  NetLogCaptureMode and the new, extracted classes.

Here is the new structuring:
  - NetLogSource (net_log_source.h/.cc)
  - NetLogEntry, NetLogEntryData (net_log_entry.h/.cc)
  - NetLogWithSource (net_log_with_source.h/.cc)

***Did not extract NetLog::ThreadSafeObserver into its own class since
   NetLog::ThreadSafeObserver and NetLog are interrelated enough to keep
   NetLog::ThreadSafeObserver as an inner class.

Further Notes:
1) On top of scripting, all files were checked manually, ensuring:
     - Forwards/including added only when appropriate. No extras added.
     - "net_log.h" include removals done correctly. No "net_log.h"-hiding
       to occur as a result of new changes.

2) Just as any .cc file will not do the include/forward if the paired .h file
   already has the include/forward, *_unittests.cc, *_browsertest.cc and
   *_test.cc files exhibit the same behavior when they have a paired .h file.

3) Override methods' types do not add to logic for inserting forwards, since it
   is guaranteed that the base class has the forward.
     - Saw this done in codebase several times, so making sure to
       follow the same rule.

4) A big change was the mass adjustment for the include-hiding of
   NetLogCaptureMode by net_log.h includes. Now the NetLogCaptureMode class is
   being properly forwarded/included in all files changed by the original
   NetLog inner classes extraction work.

5) Many NetLog/NetLogWithSource includes/forwards were added across codebase.
   All instances of files seeing their NetLog/NetLogWithSource include/forward
   being hidden by their own includes should now be gone. This is to promote
   greater flexibility in future changes upon the codebase.

BUG=473710
R=eroman@chromium.org,tfarina@chromium.org
TBR=droger@chromium.org, hirono@chromium.org, rdevlin.cronin@chromium.org, skyostil@chromium.org, wez@chromium.org, juliatuttle@chromium.org, sergeyu@chromium.org, dgozman@chromium.org, hubbe@chromium.org, rdsmith@chromium.org, stevenjb@chromium.org, scheib@chromium.org, bengr@chromium.org, alokp@chromium.org, raymes@chromium.org, samuong@chromium.org, creis@chromium.org, scottbyer@chromium.org, zea@chromium.org, mmenke@chromium.org, eranm@chromium.org

Review-Url: https://codereview.chromium.org/2333923004
Cr-Commit-Position: refs/heads/master@{#422691}
  • Loading branch information
RedKrovvy2013 authored and Commit bot committed Oct 4, 2016
1 parent de19ad7 commit f22f981
Show file tree
Hide file tree
Showing 449 changed files with 1,613 additions and 1,044 deletions.
3 changes: 2 additions & 1 deletion blimp/net/tcp_client_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/message_loop/message_loop.h"
#include "blimp/net/message_port.h"
#include "blimp/net/stream_socket_connection.h"
#include "net/log/net_log_source.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_client_socket.h"
Expand All @@ -39,7 +40,7 @@ void TCPClientTransport::Connect(const net::CompletionCallback& callback) {

connect_callback_ = callback;
socket_ = socket_factory_->CreateTransportClientSocket(
net::AddressList(ip_endpoint_), nullptr, net_log_, net::NetLog::Source());
net::AddressList(ip_endpoint_), nullptr, net_log_, net::NetLogSource());
net::CompletionCallback completion_callback = base::Bind(
&TCPClientTransport::OnTCPConnectComplete, base::Unretained(this));

Expand Down
3 changes: 2 additions & 1 deletion blimp/net/tcp_engine_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/memory/ptr_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "blimp/net/message_port.h"
#include "net/log/net_log_source.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"

Expand All @@ -30,7 +31,7 @@ void TCPEngineTransport::Connect(const net::CompletionCallback& callback) {

if (!server_socket_) {
server_socket_.reset(
new net::TCPServerSocket(net_log_, net::NetLog::Source()));
new net::TCPServerSocket(net_log_, net::NetLogSource()));
int result = server_socket_->Listen(address_, 5);
if (result != net::OK) {
server_socket_.reset();
Expand Down
1 change: 1 addition & 0 deletions blimp/net/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "blimp/net/message_port.h"
#include "blimp/net/packet_reader.h"
#include "blimp/net/packet_writer.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/stream_socket.h"
#include "testing/gmock/include/gmock/gmock.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/policy/policy_cert_verifier.h"

#include <memory>
#include <string>

#include "base/bind.h"
#include "base/bind_helpers.h"
Expand All @@ -21,7 +22,7 @@
#include "net/cert/cert_verify_result.h"
#include "net/cert/nss_cert_database_chromeos.h"
#include "net/cert/x509_certificate.h"
#include "net/log/net_log.h"
#include "net/log/net_log_with_source.h"
#include "net/test/cert_test_util.h"
#include "net/test/test_data_directory.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/devtools/device/adb/adb_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/strings/stringprintf.h"
#include "net/base/ip_address.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_source.h"
#include "net/socket/tcp_client_socket.h"

namespace {
Expand Down Expand Up @@ -184,7 +185,7 @@ void AdbClientSocket::Connect(const net::CompletionCallback& callback) {
net::AddressList address_list =
net::AddressList::CreateFromIPAddress(ip_address, port_);
socket_.reset(new net::TCPClientSocket(address_list, NULL, NULL,
net::NetLog::Source()));
net::NetLogSource()));
int result = socket_->Connect(callback);
if (result != net::ERR_IO_PENDING)
callback.Run(result);
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/devtools/device/adb/adb_client_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_ADB_ADB_CLIENT_SOCKET_H_
#define CHROME_BROWSER_DEVTOOLS_DEVICE_ADB_ADB_CLIENT_SOCKET_H_

#include <string>

#include "base/callback.h"
#include "base/macros.h"
#include "net/base/io_buffer.h"
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/devtools/device/adb/mock_adb_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_source.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"

Expand Down Expand Up @@ -231,7 +232,7 @@ class SimpleHttpServer : base::NonThreadSafe {
SimpleHttpServer::SimpleHttpServer(const ParserFactory& factory,
net::IPEndPoint endpoint)
: factory_(factory),
socket_(new net::TCPServerSocket(nullptr, net::NetLog::Source())),
socket_(new net::TCPServerSocket(nullptr, net::NetLogSource())),
weak_factory_(this) {
socket_->Listen(endpoint, 5);
OnConnect();
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/devtools/device/port_forwarding_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/dns/host_resolver.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/tcp_client_socket.h"

using content::BrowserThread;
Expand Down Expand Up @@ -81,7 +83,7 @@ class SocketTunnel : public base::NonThreadSafe {
}

host_socket_.reset(new net::TCPClientSocket(address_list_, nullptr, nullptr,
net::NetLog::Source()));
net::NetLogSource()));
result = host_socket_->Connect(base::Bind(&SocketTunnel::OnConnected,
base::Unretained(this)));
if (result != net::ERR_IO_PENDING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_

#include <map>
#include <string>

#include "base/macros.h"
#include "chrome/browser/devtools/device/devtools_android_bridge.h"
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/devtools/device/tcp_device_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "chrome/browser/devtools/device/adb/adb_client_socket.h"
#include "net/base/net_errors.h"
#include "net/dns/host_resolver.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/tcp_client_socket.h"

namespace {
Expand Down Expand Up @@ -53,7 +55,7 @@ class ResolveHostAndOpenSocket final {
return;
}
std::unique_ptr<net::StreamSocket> socket(new net::TCPClientSocket(
address_list_, NULL, NULL, net::NetLog::Source()));
address_list_, NULL, NULL, net::NetLogSource()));
socket->Connect(
base::Bind(&RunSocketCallback, callback_, base::Passed(&socket)));
delete this;
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/devtools/device/usb/android_usb_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

#include <stdint.h>

#include <string>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/devtools/device/usb/android_usb_device.h"
#include "net/base/ip_endpoint.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/stream_socket.h"

namespace base {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "chrome/browser/devtools/devtools_network_upload_data_stream.h"
#include "net/base/chunked_upload_data_stream.h"
#include "net/http/http_transaction_test_util.h"
#include "net/log/net_log_with_source.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/devtools/remote_debugging_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "content/public/browser/devtools_frontend_host.h"
#include "content/public/browser/devtools_socket_factory.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_source.h"
#include "net/socket/tcp_server_socket.h"
#include "ui/base/resource/resource_bundle.h"

Expand All @@ -45,7 +46,7 @@ class TCPServerSocketFactory
private:
std::unique_ptr<net::ServerSocket> CreateLocalHostServerSocket(int port) {
std::unique_ptr<net::ServerSocket> socket(
new net::TCPServerSocket(nullptr, net::NetLog::Source()));
new net::TCPServerSocket(nullptr, net::NetLogSource()));
if (socket->ListenWithAddressAndPort(
"127.0.0.1", port, kBackLog) == net::OK)
return socket;
Expand All @@ -57,7 +58,7 @@ class TCPServerSocketFactory
// content::DevToolsSocketFactory.
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
std::unique_ptr<net::ServerSocket> socket(
new net::TCPServerSocket(nullptr, net::NetLog::Source()));
new net::TCPServerSocket(nullptr, net::NetLogSource()));
if (address_.empty())
return CreateLocalHostServerSocket(port_);
if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) == net::OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "media/cast/test/utility/standalone_cast_environment.h"
#include "net/base/net_errors.h"
#include "net/base/rand_callback.h"
#include "net/log/net_log_source.h"
#include "net/udp/udp_server_socket.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -345,7 +346,7 @@ class CastStreamingApiTestWithPixelOutput : public CastStreamingApiTest {
#endif
IN_PROC_BROWSER_TEST_F(CastStreamingApiTestWithPixelOutput, MAYBE_EndToEnd) {
std::unique_ptr<net::UDPServerSocket> receive_socket(
new net::UDPServerSocket(NULL, net::NetLog::Source()));
new net::UDPServerSocket(NULL, net::NetLogSource()));
receive_socket->AllowAddressReuse();
ASSERT_EQ(net::OK, receive_socket->Listen(GetFreeLocalPort()));
net::IPEndPoint receiver_end_point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/rand_callback.h"
#include "net/log/net_log_source.h"
#include "net/udp/udp_server_socket.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"
Expand Down Expand Up @@ -336,7 +337,7 @@ class CastV2PerformanceTest
// Method: Bind a UDP socket on port 0, and then check which port the
// operating system assigned to it.
std::unique_ptr<net::UDPServerSocket> receive_socket(
new net::UDPServerSocket(NULL, net::NetLog::Source()));
new net::UDPServerSocket(NULL, net::NetLogSource()));
receive_socket->AllowAddressReuse();
CHECK_EQ(net::OK, receive_socket->Listen(
net::IPEndPoint(net::IPAddress::IPv4Localhost(), 0)));
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/extensions/api/dial/dial_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "net/base/network_interfaces.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/log/net_log.h"
#include "net/log/net_log_source_type.h"
#include "url/gurl.h"

Expand Down Expand Up @@ -164,7 +165,7 @@ DialServiceImpl::DialSocket::~DialSocket() {
bool DialServiceImpl::DialSocket::CreateAndBindSocket(
const IPAddress& bind_ip_address,
net::NetLog* net_log,
net::NetLog::Source net_log_source) {
net::NetLogSource net_log_source) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!socket_);
DCHECK(bind_ip_address.IsIPv4());
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/extensions/api/dial/dial_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
#include "base/observer_list.h"
#include "base/timer/timer.h"
#include "net/base/ip_address.h"
#include "net/log/net_log.h"
#include "net/log/net_log_source.h"
#include "net/udp/udp_socket.h"

namespace net {
class IOBuffer;
class IPEndPoint;
class StringIOBuffer;
class NetLog;
struct NetworkInterface;
}

Expand Down Expand Up @@ -125,7 +126,7 @@ class DialServiceImpl : public DialService {
// |bind_ip_address|.
bool CreateAndBindSocket(const net::IPAddress& bind_ip_address,
net::NetLog* net_log,
net::NetLog::Source net_log_source);
net::NetLogSource net_log_source);

// Sends a single discovery request |send_buffer| to |send_address|
// over the socket.
Expand Down Expand Up @@ -244,7 +245,7 @@ class DialServiceImpl : public DialService {
net::NetLog* const net_log_;

// The NetLog source for this service.
net::NetLog::Source net_log_source_;
net::NetLogSource net_log_source_;

// The multicast address:port for search requests.
net::IPEndPoint send_address_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class LogPrivateAPI : public BrowserContextKeyedAPI,
UnloadedExtensionInfo::Reason reason) override;

// NetLog::ThreadSafeObserver implementation:
void OnAddEntry(const net::NetLog::Entry& entry) override;
void OnAddEntry(const net::NetLogEntry& entry) override;

void PostPendingEntries();
void AddEntriesOnUI(std::unique_ptr<base::ListValue> value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/granted_file_entry.h"
#include "net/log/net_log_entry.h"

#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/system_logs/debug_log_writer.h"
Expand Down Expand Up @@ -213,7 +214,7 @@ LogPrivateAPI::GetFactoryInstance() {
return g_factory.Pointer();
}

void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) {
void LogPrivateAPI::OnAddEntry(const net::NetLogEntry& entry) {
// We could receive events on whatever thread they happen to be generated,
// since we are only interested in network events, we should ignore any
// other thread than BrowserThread::IO.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "net/cert/cert_verifier.h"
#include "net/cert/cert_verify_result.h"
#include "net/cert/x509_certificate.h"
#include "net/log/net_log.h"
#include "net/log/net_log_with_source.h"
#include "net/ssl/ssl_config_service.h"

namespace extensions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_MOCK_TCP_CLIENT_SOCKET_H_
#define CHROME_BROWSER_EXTENSIONS_API_SOCKET_MOCK_TCP_CLIENT_SOCKET_H_

#include "net/log/net_log_source.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/tcp_client_socket.h"
#include "testing/gmock/include/gmock/gmock.h"

Expand Down Expand Up @@ -51,7 +53,7 @@ MockTCPClientSocket::MockTCPClientSocket()
: TCPClientSocket(net::AddressList(),
nullptr,
nullptr,
net::NetLog::Source()) {}
net::NetLogSource()) {}
MockTCPClientSocket::~MockTCPClientSocket() {}

} // namespace extensions
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/extensions/api/socket/tcp_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/rand_callback.h"
#include "net/log/net_log_source.h"
#include "net/socket/tcp_client_socket.h"
#include "net/socket/tcp_server_socket.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand All @@ -25,7 +26,7 @@ namespace extensions {
class MockTCPSocket : public net::TCPClientSocket {
public:
explicit MockTCPSocket(const net::AddressList& address_list)
: net::TCPClientSocket(address_list, NULL, NULL, net::NetLog::Source()) {}
: net::TCPClientSocket(address_list, NULL, NULL, net::NetLogSource()) {}

MOCK_METHOD3(Read, int(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback));
Expand All @@ -43,7 +44,7 @@ class MockTCPSocket : public net::TCPClientSocket {

class MockTCPServerSocket : public net::TCPServerSocket {
public:
MockTCPServerSocket() : net::TCPServerSocket(NULL, net::NetLog::Source()) {}
MockTCPServerSocket() : net::TCPServerSocket(NULL, net::NetLogSource()) {}
MOCK_METHOD2(Listen, int(const net::IPEndPoint& address, int backlog));
MOCK_METHOD2(Accept,
int(std::unique_ptr<net::StreamSocket>* socket,
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/extensions/api/socket/tls_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/rand_callback.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/next_proto.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/tcp_client_socket.h"
Expand Down Expand Up @@ -87,7 +89,7 @@ class MockSSLClientSocket : public net::SSLClientSocket {
class MockTCPSocket : public net::TCPClientSocket {
public:
explicit MockTCPSocket(const net::AddressList& address_list)
: net::TCPClientSocket(address_list, NULL, NULL, net::NetLog::Source()) {}
: net::TCPClientSocket(address_list, NULL, NULL, net::NetLogSource()) {}

MOCK_METHOD3(Read,
int(net::IOBuffer* buf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_file_element_reader.h"
#include "net/dns/mock_host_resolver.h"
#include "net/log/net_log_with_source.h"
#include "net/log/test_net_log.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_test_util.h"
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/loader/safe_browsing_resource_throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/web_contents.h"
#include "net/base/load_flags.h"
#include "net/log/net_log.h"
#include "net/log/net_log_capture_mode.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_source_type.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/url_request.h"
Expand Down
Loading

0 comments on commit f22f981

Please sign in to comment.