Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / net / url_request / url_request_redirect_job.cc
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.
4
5 #include "net/url_request/url_request_redirect_job.h"
6
7 #include "base/bind.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"
14
15 namespace net {
16
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),
26       weak_factory_(this) {
27   DCHECK(!redirect_reason_.empty());
28 }
29
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(
35       FROM_HERE,
36       base::Bind(&URLRequestRedirectJob::StartAsync,
37                  weak_factory_.GetWeakPtr()));
38 }
39
40 bool URLRequestRedirectJob::IsRedirectResponse(GURL* location,
41                                                int* http_status_code) {
42   *location = redirect_destination_;
43   *http_status_code = http_status_code_;
44   return true;
45 }
46
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.
50   return false;
51 }
52
53 URLRequestRedirectJob::~URLRequestRedirectJob() {}
54
55 void URLRequestRedirectJob::StartAsync() {
56   receive_headers_end_ = base::TimeTicks::Now();
57   NotifyHeadersComplete();
58 }
59
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_;
67 }
68
69 }  // namespace net