OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "content/browser/loader/resource_hints_controller.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 9 #include "content/public/browser/browser_context.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/resource_context.h" |
| 13 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 14 #include "content/public/browser/resource_hints.h" |
| 15 #include "net/base/address_list.h" |
| 16 #include "net/dns/host_resolver.h" |
| 17 #include "net/dns/single_request_host_resolver.h" |
| 18 #include "net/url_request/url_request_context.h" |
| 19 |
| 20 namespace content { |
| 21 |
| 22 // static |
| 23 void ResourceHintsController::RegisterConnection( |
| 24 RenderProcessHost* render_process_host, |
| 25 mojo::InterfaceRequest<blink::mojom::ResourceHintsDispatcherHost> request) { |
| 26 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 27 BrowserThread::PostTask( |
| 28 BrowserThread::IO, FROM_HERE, |
| 29 base::Bind(&ResourceHintsController::RegisterConnectionOnIOThread, |
| 30 render_process_host->GetBrowserContext()->GetResourceContext(), |
| 31 base::Passed(&request))); |
| 32 } |
| 33 |
| 34 // static |
| 35 void ResourceHintsController::RegisterConnectionOnIOThread( |
| 36 ResourceContext* resource_context, |
| 37 mojo::InterfaceRequest<blink::mojom::ResourceHintsDispatcherHost> request) { |
| 38 // Will be deleted when the connection goes away. |
| 39 new ResourceHintsController(std::move(request), resource_context); |
| 40 } |
| 41 |
| 42 ResourceHintsController::ResourceHintsController( |
| 43 mojo::InterfaceRequest<blink::mojom::ResourceHintsDispatcherHost> request, |
| 44 ResourceContext* resource_context) |
| 45 : resource_context_(resource_context), binding_(this, std::move(request)) { |
| 46 binding_.set_connection_error_handler( |
| 47 base::Bind(&ResourceHintsController::HostHadConnectionError, |
| 48 base::Unretained(this))); |
| 49 } |
| 50 |
| 51 ResourceHintsController::~ResourceHintsController() {} |
| 52 |
| 53 void ResourceHintsController::HostHadConnectionError() { |
| 54 delete this; |
| 55 } |
| 56 |
| 57 void ResourceHintsController::DispatchPreresolve(const GURL& url) { |
| 58 PreresolveUrl(resource_context_, url, net::CompletionCallback()); |
| 59 } |
| 60 |
| 61 void ResourceHintsController::DispatchPreconnect(const GURL& url, |
| 62 bool credentials_flag, |
| 63 uint8_t num_connections) { |
| 64 // TODO(csharrison): Remove HttpRequestInfo::RequestMotivation and add a |
| 65 // better enum at the //content layer. |
| 66 PreconnectUrl(resource_context_, url, GURL(), num_connections, |
| 67 credentials_flag, net::HttpRequestInfo::EARLY_LOAD_MOTIVATED); |
| 68 } |
| 69 |
| 70 } // namespace content |
OLD | NEW |