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 "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "components/nacl/renderer/nexe_load_manager.h" | 9 #include "components/nacl/renderer/nexe_load_manager.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 total_bytes_received_ += data_length; | 63 total_bytes_received_ += data_length; |
64 if (!progress_cb_.is_null()) | 64 if (!progress_cb_.is_null()) |
65 progress_cb_.Run(total_bytes_received_, total_bytes_to_be_received_); | 65 progress_cb_.Run(total_bytes_received_, total_bytes_to_be_received_); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 void FileDownloader::didFinishLoading( | 69 void FileDownloader::didFinishLoading( |
70 blink::WebURLLoader* loader, | 70 blink::WebURLLoader* loader, |
71 double finish_time, | 71 double finish_time, |
72 int64_t total_encoded_data_length) { | 72 int64_t total_encoded_data_length) { |
| 73 if (status_ == SUCCESS) { |
| 74 // Seek back to the beginning of the file that was just written so it's |
| 75 // easy for consumers to use. |
| 76 if (base::SeekPlatformFile(file_, base::PLATFORM_FILE_FROM_BEGIN, 0) != 0) |
| 77 status_ = FAILED; |
| 78 } |
73 status_cb_.Run(status_, http_status_code_); | 79 status_cb_.Run(status_, http_status_code_); |
74 delete this; | 80 delete this; |
75 } | 81 } |
76 | 82 |
77 void FileDownloader::didFail( | 83 void FileDownloader::didFail( |
78 blink::WebURLLoader* loader, | 84 blink::WebURLLoader* loader, |
79 const blink::WebURLError& error) { | 85 const blink::WebURLError& error) { |
80 status_ = FAILED; | 86 status_ = FAILED; |
81 if (error.domain.equals(blink::WebString::fromUTF8(net::kErrorDomain))) { | 87 if (error.domain.equals(blink::WebString::fromUTF8(net::kErrorDomain))) { |
82 switch (error.reason) { | 88 switch (error.reason) { |
83 case net::ERR_ACCESS_DENIED: | 89 case net::ERR_ACCESS_DENIED: |
84 case net::ERR_NETWORK_ACCESS_DENIED: | 90 case net::ERR_NETWORK_ACCESS_DENIED: |
85 status_ = ACCESS_DENIED; | 91 status_ = ACCESS_DENIED; |
86 break; | 92 break; |
87 } | 93 } |
88 } else { | 94 } else { |
89 // It's a WebKit error. | 95 // It's a WebKit error. |
90 status_ = ACCESS_DENIED; | 96 status_ = ACCESS_DENIED; |
91 } | 97 } |
92 } | 98 } |
93 | 99 |
94 } // namespace nacl | 100 } // namespace nacl |
OLD | NEW |