| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cpp/url_loader.h" | 5 #include "ppapi/cpp/url_loader.h" |
| 6 | 6 |
| 7 #include "ppapi/c/ppb_url_loader.h" | 7 #include "ppapi/c/ppb_url_loader.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/cpp/common.h" | 9 #include "ppapi/cpp/common.h" |
| 10 #include "ppapi/cpp/completion_callback.h" | 10 #include "ppapi/cpp/completion_callback.h" |
| 11 #include "ppapi/cpp/dev/file_ref_dev.h" | 11 #include "ppapi/cpp/dev/file_ref_dev.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 42 PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create( | 42 PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create( |
| 43 instance->pp_instance())); | 43 instance->pp_instance())); |
| 44 } | 44 } |
| 45 | 45 |
| 46 URLLoader::URLLoader(const URLLoader& other) : Resource(other) { | 46 URLLoader::URLLoader(const URLLoader& other) : Resource(other) { |
| 47 } | 47 } |
| 48 | 48 |
| 49 int32_t URLLoader::Open(const URLRequestInfo& request_info, | 49 int32_t URLLoader::Open(const URLRequestInfo& request_info, |
| 50 const CompletionCallback& cc) { | 50 const CompletionCallback& cc) { |
| 51 if (!has_interface<PPB_URLLoader>()) | 51 if (!has_interface<PPB_URLLoader>()) |
| 52 return PP_ERROR_NOINTERFACE; | 52 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 53 return get_interface<PPB_URLLoader>()->Open(pp_resource(), | 53 return get_interface<PPB_URLLoader>()->Open(pp_resource(), |
| 54 request_info.pp_resource(), | 54 request_info.pp_resource(), |
| 55 cc.pp_completion_callback()); | 55 cc.pp_completion_callback()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 int32_t URLLoader::FollowRedirect(const CompletionCallback& cc) { | 58 int32_t URLLoader::FollowRedirect(const CompletionCallback& cc) { |
| 59 if (!has_interface<PPB_URLLoader>()) | 59 if (!has_interface<PPB_URLLoader>()) |
| 60 return PP_ERROR_NOINTERFACE; | 60 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 61 return get_interface<PPB_URLLoader>()->FollowRedirect( | 61 return get_interface<PPB_URLLoader>()->FollowRedirect( |
| 62 pp_resource(), cc.pp_completion_callback()); | 62 pp_resource(), cc.pp_completion_callback()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool URLLoader::GetUploadProgress(int64_t* bytes_sent, | 65 bool URLLoader::GetUploadProgress(int64_t* bytes_sent, |
| 66 int64_t* total_bytes_to_be_sent) const { | 66 int64_t* total_bytes_to_be_sent) const { |
| 67 if (!has_interface<PPB_URLLoader>()) | 67 if (!has_interface<PPB_URLLoader>()) |
| 68 return false; | 68 return false; |
| 69 return PPBoolToBool(get_interface<PPB_URLLoader>()->GetUploadProgress( | 69 return PPBoolToBool(get_interface<PPB_URLLoader>()->GetUploadProgress( |
| 70 pp_resource(), bytes_sent, total_bytes_to_be_sent)); | 70 pp_resource(), bytes_sent, total_bytes_to_be_sent)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 85 return URLResponseInfo(); | 85 return URLResponseInfo(); |
| 86 return URLResponseInfo(URLResponseInfo::PassRef(), | 86 return URLResponseInfo(URLResponseInfo::PassRef(), |
| 87 get_interface<PPB_URLLoader>()->GetResponseInfo( | 87 get_interface<PPB_URLLoader>()->GetResponseInfo( |
| 88 pp_resource())); | 88 pp_resource())); |
| 89 } | 89 } |
| 90 | 90 |
| 91 int32_t URLLoader::ReadResponseBody(void* buffer, | 91 int32_t URLLoader::ReadResponseBody(void* buffer, |
| 92 int32_t bytes_to_read, | 92 int32_t bytes_to_read, |
| 93 const CompletionCallback& cc) { | 93 const CompletionCallback& cc) { |
| 94 if (!has_interface<PPB_URLLoader>()) | 94 if (!has_interface<PPB_URLLoader>()) |
| 95 return PP_ERROR_NOINTERFACE; | 95 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 96 return get_interface<PPB_URLLoader>()->ReadResponseBody( | 96 return get_interface<PPB_URLLoader>()->ReadResponseBody( |
| 97 pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback()); | 97 pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 int32_t URLLoader::FinishStreamingToFile(const CompletionCallback& cc) { | 100 int32_t URLLoader::FinishStreamingToFile(const CompletionCallback& cc) { |
| 101 if (!has_interface<PPB_URLLoader>()) | 101 if (!has_interface<PPB_URLLoader>()) |
| 102 return PP_ERROR_NOINTERFACE; | 102 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 103 return get_interface<PPB_URLLoader>()->FinishStreamingToFile( | 103 return get_interface<PPB_URLLoader>()->FinishStreamingToFile( |
| 104 pp_resource(), cc.pp_completion_callback()); | 104 pp_resource(), cc.pp_completion_callback()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void URLLoader::Close() { | 107 void URLLoader::Close() { |
| 108 if (!has_interface<PPB_URLLoader>()) | 108 if (!has_interface<PPB_URLLoader>()) |
| 109 return; | 109 return; |
| 110 get_interface<PPB_URLLoader>()->Close(pp_resource()); | 110 get_interface<PPB_URLLoader>()->Close(pp_resource()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace pp | 113 } // namespace pp |
| OLD | NEW |