| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/native_client/src/trusted/plugin/file_downloader.h" | 5 #include "ppapi/native_client/src/trusted/plugin/file_downloader.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 else | 143 else |
| 144 start_notify = &FileDownloader::URLBufferStartNotify; | 144 start_notify = &FileDownloader::URLBufferStartNotify; |
| 145 | 145 |
| 146 // Request asynchronous download of the url providing an on-load callback. | 146 // Request asynchronous download of the url providing an on-load callback. |
| 147 // As long as this step is guaranteed to be asynchronous, we can call | 147 // As long as this step is guaranteed to be asynchronous, we can call |
| 148 // synchronously all other internal callbacks that eventually result in the | 148 // synchronously all other internal callbacks that eventually result in the |
| 149 // invocation of the user callback. The user code will not be reentered. | 149 // invocation of the user callback. The user code will not be reentered. |
| 150 pp::CompletionCallback onload_callback = | 150 pp::CompletionCallback onload_callback = |
| 151 callback_factory_.NewCallback(start_notify); | 151 callback_factory_.NewCallback(start_notify); |
| 152 int32_t pp_error = url_loader_.Open(url_request, onload_callback); | 152 int32_t pp_error = url_loader_.Open(url_request, onload_callback); |
| 153 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=%"NACL_PRId32")\n", pp_error)); | 153 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=%" NACL_PRId32 ")\n", |
| 154 pp_error)); |
| 154 CHECK(pp_error == PP_OK_COMPLETIONPENDING); | 155 CHECK(pp_error == PP_OK_COMPLETIONPENDING); |
| 155 return true; | 156 return true; |
| 156 } | 157 } |
| 157 | 158 |
| 158 void FileDownloader::OpenFast(const nacl::string& url, | 159 void FileDownloader::OpenFast(const nacl::string& url, |
| 159 PP_FileHandle file_handle, | 160 PP_FileHandle file_handle, |
| 160 uint64_t file_token_lo, uint64_t file_token_hi) { | 161 uint64_t file_token_lo, uint64_t file_token_hi) { |
| 161 PLUGIN_PRINTF(("FileDownloader::OpenFast (url=%s)\n", url.c_str())); | 162 PLUGIN_PRINTF(("FileDownloader::OpenFast (url=%s)\n", url.c_str())); |
| 162 CHECK(instance_ != NULL); | 163 CHECK(instance_ != NULL); |
| 163 open_time_ = NaClGetTimeOfDayMicroseconds(); | 164 open_time_ = NaClGetTimeOfDayMicroseconds(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 244 |
| 244 // Note that URLs in the data-URI scheme produce different error | 245 // Note that URLs in the data-URI scheme produce different error |
| 245 // codes than other schemes. This is because data-URI are really a | 246 // codes than other schemes. This is because data-URI are really a |
| 246 // special kind of file scheme, and therefore do not produce HTTP | 247 // special kind of file scheme, and therefore do not produce HTTP |
| 247 // status codes. | 248 // status codes. |
| 248 bool status_ok = false; | 249 bool status_ok = false; |
| 249 status_code_ = url_response_.GetStatusCode(); | 250 status_code_ = url_response_.GetStatusCode(); |
| 250 switch (url_scheme_) { | 251 switch (url_scheme_) { |
| 251 case SCHEME_CHROME_EXTENSION: | 252 case SCHEME_CHROME_EXTENSION: |
| 252 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (chrome-extension " | 253 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (chrome-extension " |
| 253 "response status_code=%"NACL_PRId32")\n", status_code_)); | 254 "response status_code=%" NACL_PRId32 ")\n", status_code_)); |
| 254 status_ok = (status_code_ == kExtensionUrlRequestStatusOk); | 255 status_ok = (status_code_ == kExtensionUrlRequestStatusOk); |
| 255 break; | 256 break; |
| 256 case SCHEME_DATA: | 257 case SCHEME_DATA: |
| 257 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (data URI " | 258 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (data URI " |
| 258 "response status_code=%"NACL_PRId32")\n", status_code_)); | 259 "response status_code=%" NACL_PRId32 ")\n", status_code_)); |
| 259 status_ok = (status_code_ == kDataUriRequestStatusOk); | 260 status_ok = (status_code_ == kDataUriRequestStatusOk); |
| 260 break; | 261 break; |
| 261 case SCHEME_OTHER: | 262 case SCHEME_OTHER: |
| 262 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (HTTP response " | 263 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (HTTP response " |
| 263 "status_code=%"NACL_PRId32")\n", status_code_)); | 264 "status_code=%" NACL_PRId32 ")\n", status_code_)); |
| 264 status_ok = (status_code_ == NACL_HTTP_STATUS_OK); | 265 status_ok = (status_code_ == NACL_HTTP_STATUS_OK); |
| 265 break; | 266 break; |
| 266 } | 267 } |
| 267 | 268 |
| 268 if (!status_ok) { | 269 if (!status_ok) { |
| 269 file_open_notify_callback_.RunAndClear(PP_ERROR_FAILED); | 270 file_open_notify_callback_.RunAndClear(PP_ERROR_FAILED); |
| 270 return false; | 271 return false; |
| 271 } | 272 } |
| 272 | 273 |
| 273 return true; | 274 return true; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 if (!headers.is_string()) { | 433 if (!headers.is_string()) { |
| 433 PLUGIN_PRINTF(( | 434 PLUGIN_PRINTF(( |
| 434 "FileDownloader::GetResponseHeaders (headers are not a string)\n")); | 435 "FileDownloader::GetResponseHeaders (headers are not a string)\n")); |
| 435 return nacl::string(); | 436 return nacl::string(); |
| 436 } | 437 } |
| 437 return headers.AsString(); | 438 return headers.AsString(); |
| 438 } | 439 } |
| 439 | 440 |
| 440 void FileDownloader::StreamFinishNotify(int32_t pp_error) { | 441 void FileDownloader::StreamFinishNotify(int32_t pp_error) { |
| 441 PLUGIN_PRINTF(( | 442 PLUGIN_PRINTF(( |
| 442 "FileDownloader::StreamFinishNotify (pp_error=%"NACL_PRId32")\n", | 443 "FileDownloader::StreamFinishNotify (pp_error=%" NACL_PRId32 ")\n", |
| 443 pp_error)); | 444 pp_error)); |
| 444 stream_finish_callback_.RunAndClear(pp_error); | 445 stream_finish_callback_.RunAndClear(pp_error); |
| 445 } | 446 } |
| 446 | 447 |
| 447 bool FileDownloader::streaming_to_file() const { | 448 bool FileDownloader::streaming_to_file() const { |
| 448 return mode_ == DOWNLOAD_TO_FILE; | 449 return mode_ == DOWNLOAD_TO_FILE; |
| 449 } | 450 } |
| 450 | 451 |
| 451 bool FileDownloader::streaming_to_buffer() const { | 452 bool FileDownloader::streaming_to_buffer() const { |
| 452 return mode_ == DOWNLOAD_TO_BUFFER; | 453 return mode_ == DOWNLOAD_TO_BUFFER; |
| 453 } | 454 } |
| 454 | 455 |
| 455 bool FileDownloader::streaming_to_user() const { | 456 bool FileDownloader::streaming_to_user() const { |
| 456 return mode_ == DOWNLOAD_STREAM; | 457 return mode_ == DOWNLOAD_STREAM; |
| 457 } | 458 } |
| 458 | 459 |
| 459 bool FileDownloader::not_streaming() const { | 460 bool FileDownloader::not_streaming() const { |
| 460 return mode_ == DOWNLOAD_NONE; | 461 return mode_ == DOWNLOAD_NONE; |
| 461 } | 462 } |
| 462 | 463 |
| 463 } // namespace plugin | 464 } // namespace plugin |
| OLD | NEW |