OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/nacl/renderer/file_downloader.h" | 5 #include "components/nacl/renderer/file_downloader.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/callback.h" | 9 #include "base/callback.h" |
8 #include "components/nacl/renderer/nexe_load_manager.h" | 10 #include "components/nacl/renderer/nexe_load_manager.h" |
9 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
10 #include "third_party/WebKit/public/platform/WebURLError.h" | 12 #include "third_party/WebKit/public/platform/WebURLError.h" |
11 #include "third_party/WebKit/public/platform/WebURLLoader.h" | 13 #include "third_party/WebKit/public/platform/WebURLLoader.h" |
12 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 14 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
13 | 15 |
14 namespace nacl { | 16 namespace nacl { |
15 | 17 |
16 FileDownloader::FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader, | 18 FileDownloader::FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader, |
17 base::File file, | 19 base::File file, |
18 StatusCallback status_cb, | 20 StatusCallback status_cb, |
19 ProgressCallback progress_cb) | 21 ProgressCallback progress_cb) |
20 : url_loader_(url_loader.Pass()), | 22 : url_loader_(std::move(url_loader)), |
21 file_(file.Pass()), | 23 file_(std::move(file)), |
22 status_cb_(status_cb), | 24 status_cb_(status_cb), |
23 progress_cb_(progress_cb), | 25 progress_cb_(progress_cb), |
24 http_status_code_(-1), | 26 http_status_code_(-1), |
25 total_bytes_received_(0), | 27 total_bytes_received_(0), |
26 total_bytes_to_be_received_(-1), | 28 total_bytes_to_be_received_(-1), |
27 status_(SUCCESS) { | 29 status_(SUCCESS) { |
28 CHECK(!status_cb.is_null()); | 30 CHECK(!status_cb.is_null()); |
29 } | 31 } |
30 | 32 |
31 FileDownloader::~FileDownloader() { | 33 FileDownloader::~FileDownloader() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void FileDownloader::didFinishLoading( | 69 void FileDownloader::didFinishLoading( |
68 blink::WebURLLoader* loader, | 70 blink::WebURLLoader* loader, |
69 double finish_time, | 71 double finish_time, |
70 int64_t total_encoded_data_length) { | 72 int64_t total_encoded_data_length) { |
71 if (status_ == SUCCESS) { | 73 if (status_ == SUCCESS) { |
72 // Seek back to the beginning of the file that was just written so it's | 74 // Seek back to the beginning of the file that was just written so it's |
73 // easy for consumers to use. | 75 // easy for consumers to use. |
74 if (file_.Seek(base::File::FROM_BEGIN, 0) != 0) | 76 if (file_.Seek(base::File::FROM_BEGIN, 0) != 0) |
75 status_ = FAILED; | 77 status_ = FAILED; |
76 } | 78 } |
77 status_cb_.Run(status_, file_.Pass(), http_status_code_); | 79 status_cb_.Run(status_, std::move(file_), http_status_code_); |
78 delete this; | 80 delete this; |
79 } | 81 } |
80 | 82 |
81 void FileDownloader::didFail( | 83 void FileDownloader::didFail( |
82 blink::WebURLLoader* loader, | 84 blink::WebURLLoader* loader, |
83 const blink::WebURLError& error) { | 85 const blink::WebURLError& error) { |
84 status_ = FAILED; | 86 status_ = FAILED; |
85 if (error.domain.equals(blink::WebString::fromUTF8(net::kErrorDomain))) { | 87 if (error.domain.equals(blink::WebString::fromUTF8(net::kErrorDomain))) { |
86 switch (error.reason) { | 88 switch (error.reason) { |
87 case net::ERR_ACCESS_DENIED: | 89 case net::ERR_ACCESS_DENIED: |
88 case net::ERR_NETWORK_ACCESS_DENIED: | 90 case net::ERR_NETWORK_ACCESS_DENIED: |
89 status_ = ACCESS_DENIED; | 91 status_ = ACCESS_DENIED; |
90 break; | 92 break; |
91 } | 93 } |
92 } else { | 94 } else { |
93 // It's a WebKit error. | 95 // It's a WebKit error. |
94 status_ = ACCESS_DENIED; | 96 status_ = ACCESS_DENIED; |
95 } | 97 } |
96 | 98 |
97 // Delete url_loader to prevent didFinishLoading from being called, which | 99 // Delete url_loader to prevent didFinishLoading from being called, which |
98 // some implementations of blink::WebURLLoader will do after calling didFail. | 100 // some implementations of blink::WebURLLoader will do after calling didFail. |
99 url_loader_.reset(); | 101 url_loader_.reset(); |
100 | 102 |
101 status_cb_.Run(status_, file_.Pass(), http_status_code_); | 103 status_cb_.Run(status_, std::move(file_), http_status_code_); |
102 delete this; | 104 delete this; |
103 } | 105 } |
104 | 106 |
105 } // namespace nacl | 107 } // namespace nacl |
OLD | NEW |