OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/cpp/dev/url_loader_dev.h" | |
6 | |
7 #include "ppapi/c/dev/ppb_url_loader_dev.h" | |
8 #include "ppapi/c/pp_errors.h" | |
9 #include "ppapi/cpp/common.h" | |
10 #include "ppapi/cpp/completion_callback.h" | |
11 #include "ppapi/cpp/dev/file_ref_dev.h" | |
12 #include "ppapi/cpp/dev/url_request_info_dev.h" | |
13 #include "ppapi/cpp/dev/url_response_info_dev.h" | |
14 #include "ppapi/cpp/instance.h" | |
15 #include "ppapi/cpp/module.h" | |
16 #include "ppapi/cpp/module_impl.h" | |
17 | |
18 namespace { | |
19 | |
20 DeviceFuncs<PPB_URLLoader_Dev> url_loader_f(PPB_URLLOADER_DEV_INTERFACE); | |
21 | |
22 } // namespace | |
23 | |
24 namespace pp { | |
25 | |
26 URLLoader_Dev::URLLoader_Dev(PP_Resource resource) : Resource(resource) { | |
27 } | |
28 | |
29 URLLoader_Dev::URLLoader_Dev(const Instance& instance) { | |
30 if (!url_loader_f) | |
31 return; | |
32 PassRefFromConstructor(url_loader_f->Create(instance.pp_instance())); | |
33 } | |
34 | |
35 URLLoader_Dev::URLLoader_Dev(const URLLoader_Dev& other) | |
36 : Resource(other) { | |
37 } | |
38 | |
39 URLLoader_Dev& URLLoader_Dev::operator=(const URLLoader_Dev& other) { | |
40 URLLoader_Dev copy(other); | |
41 swap(copy); | |
42 return *this; | |
43 } | |
44 | |
45 void URLLoader_Dev::swap(URLLoader_Dev& other) { | |
46 Resource::swap(other); | |
47 } | |
48 | |
49 int32_t URLLoader_Dev::Open(const URLRequestInfo_Dev& request_info, | |
50 const CompletionCallback& cc) { | |
51 if (!url_loader_f) | |
52 return PP_ERROR_NOINTERFACE; | |
53 return url_loader_f->Open(pp_resource(), request_info.pp_resource(), | |
54 cc.pp_completion_callback()); | |
55 } | |
56 | |
57 int32_t URLLoader_Dev::FollowRedirect(const CompletionCallback& cc) { | |
58 if (!url_loader_f) | |
59 return PP_ERROR_NOINTERFACE; | |
60 return url_loader_f->FollowRedirect(pp_resource(), | |
61 cc.pp_completion_callback()); | |
62 } | |
63 | |
64 bool URLLoader_Dev::GetUploadProgress(int64_t* bytes_sent, | |
65 int64_t* total_bytes_to_be_sent) const { | |
66 if (!url_loader_f) | |
67 return false; | |
68 return PPBoolToBool(url_loader_f->GetUploadProgress(pp_resource(), | |
69 bytes_sent, | |
70 total_bytes_to_be_sent)); | |
71 } | |
72 | |
73 bool URLLoader_Dev::GetDownloadProgress( | |
74 int64_t* bytes_received, | |
75 int64_t* total_bytes_to_be_received) const { | |
76 if (!url_loader_f) | |
77 return false; | |
78 return PPBoolToBool( | |
79 url_loader_f->GetDownloadProgress(pp_resource(), | |
80 bytes_received, | |
81 total_bytes_to_be_received)); | |
82 } | |
83 | |
84 URLResponseInfo_Dev URLLoader_Dev::GetResponseInfo() const { | |
85 if (!url_loader_f) | |
86 return URLResponseInfo_Dev(); | |
87 return URLResponseInfo_Dev(URLResponseInfo_Dev::PassRef(), | |
88 url_loader_f->GetResponseInfo(pp_resource())); | |
89 } | |
90 | |
91 int32_t URLLoader_Dev::ReadResponseBody(char* buffer, | |
92 int32_t bytes_to_read, | |
93 const CompletionCallback& cc) { | |
94 if (!url_loader_f) | |
95 return PP_ERROR_NOINTERFACE; | |
96 return url_loader_f->ReadResponseBody(pp_resource(), | |
97 buffer, | |
98 bytes_to_read, | |
99 cc.pp_completion_callback()); | |
100 } | |
101 | |
102 int32_t URLLoader_Dev::FinishStreamingToFile(const CompletionCallback& cc) { | |
103 if (!url_loader_f) | |
104 return PP_ERROR_NOINTERFACE; | |
105 return url_loader_f->FinishStreamingToFile(pp_resource(), | |
106 cc.pp_completion_callback()); | |
107 } | |
108 | |
109 void URLLoader_Dev::Close() { | |
110 if (!url_loader_f) | |
111 return; | |
112 url_loader_f->Close(pp_resource()); | |
113 } | |
114 | |
115 } // namespace pp | |
OLD | NEW |