- add sources.
[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/message_loop/message_loop.h"
10 #include "net/base/load_timing_info.h"
11
12 namespace net {
13
14 URLRequestRedirectJob::URLRequestRedirectJob(URLRequest* request,
15                                              NetworkDelegate* network_delegate,
16                                              const GURL& redirect_destination,
17                                              StatusCode http_status_code)
18     : URLRequestJob(request, network_delegate),
19       redirect_destination_(redirect_destination),
20       http_status_code_(http_status_code),
21       weak_factory_(this) {}
22
23 void URLRequestRedirectJob::Start() {
24   base::MessageLoop::current()->PostTask(
25       FROM_HERE,
26       base::Bind(&URLRequestRedirectJob::StartAsync,
27                  weak_factory_.GetWeakPtr()));
28 }
29
30 bool URLRequestRedirectJob::IsRedirectResponse(GURL* location,
31                                                int* http_status_code) {
32   *location = redirect_destination_;
33   *http_status_code = http_status_code_;
34   return true;
35 }
36
37 URLRequestRedirectJob::~URLRequestRedirectJob() {}
38
39 void URLRequestRedirectJob::StartAsync() {
40   receive_headers_end_ = base::TimeTicks::Now();
41   NotifyHeadersComplete();
42 }
43
44 void URLRequestRedirectJob::GetLoadTimingInfo(
45     LoadTimingInfo* load_timing_info) const {
46   // Set send_start and send_end to receive_headers_end_ to keep consistent
47   // with network cache behavior.
48   load_timing_info->send_start = receive_headers_end_;
49   load_timing_info->send_end = receive_headers_end_;
50   load_timing_info->receive_headers_end = receive_headers_end_;
51 }
52
53 }  // namespace net