OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_browsing/two_phase_uploader.h" | 5 #include "chrome/browser/safe_browsing/two_phase_uploader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/task_runner.h" | 8 #include "base/task_runner.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 DCHECK(CalledOnValidThread()); | 56 DCHECK(CalledOnValidThread()); |
57 net::URLRequestStatus status = source->GetStatus(); | 57 net::URLRequestStatus status = source->GetStatus(); |
58 int response_code = source->GetResponseCode(); | 58 int response_code = source->GetResponseCode(); |
59 | 59 |
60 DVLOG(1) << __FUNCTION__ << " " << source->GetURL().spec() | 60 DVLOG(1) << __FUNCTION__ << " " << source->GetURL().spec() |
61 << " " << status.status() << " " << response_code; | 61 << " " << status.status() << " " << response_code; |
62 | 62 |
63 if (!status.is_success()) { | 63 if (!status.is_success()) { |
64 LOG(ERROR) << "URLFetcher failed, status=" << status.status() | 64 LOG(ERROR) << "URLFetcher failed, status=" << status.status() |
65 << " err=" << status.error(); | 65 << " err=" << status.error(); |
66 Finish(status.error(), response_code, ""); | 66 Finish(status.error(), response_code, std::string()); |
67 return; | 67 return; |
68 } | 68 } |
69 | 69 |
70 std::string response; | 70 std::string response; |
71 source->GetResponseAsString(&response); | 71 source->GetResponseAsString(&response); |
72 | 72 |
73 switch (state_) { | 73 switch (state_) { |
74 case UPLOAD_METADATA: | 74 case UPLOAD_METADATA: |
75 { | 75 { |
76 if (response_code != 201) { | 76 if (response_code != 201) { |
77 LOG(ERROR) << "Invalid response to initial request: " | 77 LOG(ERROR) << "Invalid response to initial request: " |
78 << response_code; | 78 << response_code; |
79 Finish(net::OK, response_code, response); | 79 Finish(net::OK, response_code, response); |
80 return; | 80 return; |
81 } | 81 } |
82 std::string location; | 82 std::string location; |
83 if (!source->GetResponseHeaders()->EnumerateHeader( | 83 if (!source->GetResponseHeaders()->EnumerateHeader( |
84 NULL, kLocationHeader, &location)) { | 84 NULL, kLocationHeader, &location)) { |
85 LOG(ERROR) << "no location header"; | 85 LOG(ERROR) << "no location header"; |
86 Finish(net::OK, response_code, ""); | 86 Finish(net::OK, response_code, std::string()); |
87 return; | 87 return; |
88 } | 88 } |
89 DVLOG(1) << "upload location: " << location; | 89 DVLOG(1) << "upload location: " << location; |
90 upload_url_ = GURL(location); | 90 upload_url_ = GURL(location); |
91 UploadFile(); | 91 UploadFile(); |
92 break; | 92 break; |
93 } | 93 } |
94 case UPLOAD_FILE: | 94 case UPLOAD_FILE: |
95 if (response_code != 200) { | 95 if (response_code != 200) { |
96 LOG(ERROR) << "Invalid response to upload request: " | 96 LOG(ERROR) << "Invalid response to upload request: " |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 file_task_runner_); | 137 file_task_runner_); |
138 url_fetcher_->Start(); | 138 url_fetcher_->Start(); |
139 } | 139 } |
140 | 140 |
141 void TwoPhaseUploader::Finish(int net_error, | 141 void TwoPhaseUploader::Finish(int net_error, |
142 int response_code, | 142 int response_code, |
143 const std::string& response) { | 143 const std::string& response) { |
144 DCHECK(CalledOnValidThread()); | 144 DCHECK(CalledOnValidThread()); |
145 finish_callback_.Run(state_, net_error, response_code, response); | 145 finish_callback_.Run(state_, net_error, response_code, response); |
146 } | 146 } |
OLD | NEW |