Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / loader / navigation_url_loader_impl.cc
blob9d7db596e4ae4988ef78a47c31708d1f312178df
1 // Copyright 2014 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.
5 #include "content/browser/loader/navigation_url_loader_impl.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "content/browser/frame_host/navigation_request_info.h"
10 #include "content/browser/loader/navigation_url_loader_delegate.h"
11 #include "content/browser/loader/navigation_url_loader_impl_core.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/stream_handle.h"
16 namespace content {
18 NavigationURLLoaderImpl::NavigationURLLoaderImpl(
19 BrowserContext* browser_context,
20 int frame_tree_node_id,
21 scoped_ptr<NavigationRequestInfo> request_info,
22 NavigationURLLoaderDelegate* delegate)
23 : delegate_(delegate),
24 weak_factory_(this) {
25 DCHECK_CURRENTLY_ON(BrowserThread::UI);
27 core_ = new NavigationURLLoaderImplCore(weak_factory_.GetWeakPtr());
28 BrowserThread::PostTask(
29 BrowserThread::IO, FROM_HERE,
30 base::Bind(&NavigationURLLoaderImplCore::Start, base::Unretained(core_),
31 browser_context->GetResourceContext(), frame_tree_node_id,
32 base::Passed(&request_info)));
35 NavigationURLLoaderImpl::~NavigationURLLoaderImpl() {
36 DCHECK_CURRENTLY_ON(BrowserThread::UI);
38 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, core_);
39 core_ = nullptr;
42 void NavigationURLLoaderImpl::FollowRedirect() {
43 DCHECK_CURRENTLY_ON(BrowserThread::UI);
45 BrowserThread::PostTask(
46 BrowserThread::IO, FROM_HERE,
47 base::Bind(&NavigationURLLoaderImplCore::FollowRedirect,
48 base::Unretained(core_)));
51 void NavigationURLLoaderImpl::NotifyRequestRedirected(
52 const net::RedirectInfo& redirect_info,
53 const scoped_refptr<ResourceResponse>& response) {
54 DCHECK_CURRENTLY_ON(BrowserThread::UI);
56 delegate_->OnRequestRedirected(redirect_info, response);
59 void NavigationURLLoaderImpl::NotifyResponseStarted(
60 const scoped_refptr<ResourceResponse>& response,
61 scoped_ptr<StreamHandle> body) {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
64 delegate_->OnResponseStarted(response, body.Pass());
67 void NavigationURLLoaderImpl::NotifyRequestFailed(bool in_cache,
68 int net_error) {
69 DCHECK_CURRENTLY_ON(BrowserThread::UI);
71 delegate_->OnRequestFailed(in_cache, net_error);
74 void NavigationURLLoaderImpl::NotifyRequestStarted(base::TimeTicks timestamp) {
75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
77 delegate_->OnRequestStarted(timestamp);
80 } // namespace content