1 // Copyright (c) 2012 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 "net/url_request/url_request_redirect_job.h"
8 #include "base/compiler_specific.h"
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "net/base/load_timing_info.h"
12 #include "net/base/net_log.h"
13 #include "net/url_request/url_request.h"
17 URLRequestRedirectJob::URLRequestRedirectJob(URLRequest* request,
18 NetworkDelegate* network_delegate,
19 const GURL& redirect_destination,
20 StatusCode http_status_code,
21 const std::string& redirect_reason)
22 : URLRequestJob(request, network_delegate),
23 redirect_destination_(redirect_destination),
24 http_status_code_(http_status_code),
25 redirect_reason_(redirect_reason),
27 DCHECK(!redirect_reason_.empty());
30 void URLRequestRedirectJob::Start() {
31 request()->net_log().AddEvent(
32 NetLog::TYPE_URL_REQUEST_REDIRECT_JOB,
33 NetLog::StringCallback("reason", &redirect_reason_));
34 base::MessageLoop::current()->PostTask(
36 base::Bind(&URLRequestRedirectJob::StartAsync,
37 weak_factory_.GetWeakPtr()));
40 bool URLRequestRedirectJob::IsRedirectResponse(GURL* location,
41 int* http_status_code) {
42 *location = redirect_destination_;
43 *http_status_code = http_status_code_;
47 bool URLRequestRedirectJob::CopyFragmentOnRedirect(const GURL& location) const {
48 // The instantiators have full control over the desired redirection target,
49 // including the reference fragment part of the URL.
53 URLRequestRedirectJob::~URLRequestRedirectJob() {}
55 void URLRequestRedirectJob::StartAsync() {
56 receive_headers_end_ = base::TimeTicks::Now();
57 NotifyHeadersComplete();
60 void URLRequestRedirectJob::GetLoadTimingInfo(
61 LoadTimingInfo* load_timing_info) const {
62 // Set send_start and send_end to receive_headers_end_ to keep consistent
63 // with network cache behavior.
64 load_timing_info->send_start = receive_headers_end_;
65 load_timing_info->send_end = receive_headers_end_;
66 load_timing_info->receive_headers_end = receive_headers_end_;