Roll src/third_party/skia d7c014f:95cc012
[chromium-blink-merge.git] / ppapi / thunk / ppb_url_loader_thunk.cc
blob4f19505e3931329f8e489446118a42796c94db1f
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
3 // found in the LICENSE file.
5 // From ppb_url_loader.idl modified Tue May 7 14:43:00 2013.
7 #include <string.h>
9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/ppb_url_loader.h"
12 #include "ppapi/shared_impl/tracked_callback.h"
13 #include "ppapi/thunk/enter.h"
14 #include "ppapi/thunk/ppapi_thunk_export.h"
15 #include "ppapi/thunk/ppb_url_loader_api.h"
17 namespace ppapi {
18 namespace thunk {
20 namespace {
22 PP_Resource Create(PP_Instance instance) {
23 VLOG(4) << "PPB_URLLoader::Create()";
24 EnterResourceCreation enter(instance);
25 if (enter.failed())
26 return 0;
27 return enter.functions()->CreateURLLoader(instance);
30 PP_Bool IsURLLoader(PP_Resource resource) {
31 VLOG(4) << "PPB_URLLoader::IsURLLoader()";
32 EnterResource<PPB_URLLoader_API> enter(resource, false);
33 return PP_FromBool(enter.succeeded());
36 int32_t Open(PP_Resource loader,
37 PP_Resource request_info,
38 struct PP_CompletionCallback callback) {
39 VLOG(4) << "PPB_URLLoader::Open()";
40 EnterResource<PPB_URLLoader_API> enter(loader, callback, true);
41 if (enter.failed())
42 return enter.retval();
43 return enter.SetResult(enter.object()->Open(request_info, enter.callback()));
46 int32_t FollowRedirect(PP_Resource loader,
47 struct PP_CompletionCallback callback) {
48 VLOG(4) << "PPB_URLLoader::FollowRedirect()";
49 EnterResource<PPB_URLLoader_API> enter(loader, callback, true);
50 if (enter.failed())
51 return enter.retval();
52 return enter.SetResult(enter.object()->FollowRedirect(enter.callback()));
55 PP_Bool GetUploadProgress(PP_Resource loader,
56 int64_t* bytes_sent,
57 int64_t* total_bytes_to_be_sent) {
58 VLOG(4) << "PPB_URLLoader::GetUploadProgress()";
59 EnterResource<PPB_URLLoader_API> enter(loader, true);
60 if (enter.failed()) {
61 memset(bytes_sent, 0, sizeof(*bytes_sent));
62 memset(total_bytes_to_be_sent, 0, sizeof(*total_bytes_to_be_sent));
63 return PP_FALSE;
65 return enter.object()->GetUploadProgress(bytes_sent, total_bytes_to_be_sent);
68 PP_Bool GetDownloadProgress(PP_Resource loader,
69 int64_t* bytes_received,
70 int64_t* total_bytes_to_be_received) {
71 VLOG(4) << "PPB_URLLoader::GetDownloadProgress()";
72 EnterResource<PPB_URLLoader_API> enter(loader, true);
73 if (enter.failed()) {
74 memset(bytes_received, 0, sizeof(*bytes_received));
75 memset(total_bytes_to_be_received, 0, sizeof(*total_bytes_to_be_received));
76 return PP_FALSE;
78 return enter.object()->GetDownloadProgress(bytes_received,
79 total_bytes_to_be_received);
82 PP_Resource GetResponseInfo(PP_Resource loader) {
83 VLOG(4) << "PPB_URLLoader::GetResponseInfo()";
84 EnterResource<PPB_URLLoader_API> enter(loader, true);
85 if (enter.failed())
86 return 0;
87 return enter.object()->GetResponseInfo();
90 int32_t ReadResponseBody(PP_Resource loader,
91 void* buffer,
92 int32_t bytes_to_read,
93 struct PP_CompletionCallback callback) {
94 VLOG(4) << "PPB_URLLoader::ReadResponseBody()";
95 EnterResource<PPB_URLLoader_API> enter(loader, callback, true);
96 if (enter.failed())
97 return enter.retval();
98 return enter.SetResult(enter.object()->ReadResponseBody(buffer, bytes_to_read,
99 enter.callback()));
102 int32_t FinishStreamingToFile(PP_Resource loader,
103 struct PP_CompletionCallback callback) {
104 VLOG(4) << "PPB_URLLoader::FinishStreamingToFile()";
105 EnterResource<PPB_URLLoader_API> enter(loader, callback, true);
106 if (enter.failed())
107 return enter.retval();
108 return enter.SetResult(
109 enter.object()->FinishStreamingToFile(enter.callback()));
112 void Close(PP_Resource loader) {
113 VLOG(4) << "PPB_URLLoader::Close()";
114 EnterResource<PPB_URLLoader_API> enter(loader, true);
115 if (enter.failed())
116 return;
117 enter.object()->Close();
120 const PPB_URLLoader_1_0 g_ppb_urlloader_thunk_1_0 = {&Create,
121 &IsURLLoader,
122 &Open,
123 &FollowRedirect,
124 &GetUploadProgress,
125 &GetDownloadProgress,
126 &GetResponseInfo,
127 &ReadResponseBody,
128 &FinishStreamingToFile,
129 &Close};
131 } // namespace
133 PPAPI_THUNK_EXPORT const PPB_URLLoader_1_0* GetPPB_URLLoader_1_0_Thunk() {
134 return &g_ppb_urlloader_thunk_1_0;
137 } // namespace thunk
138 } // namespace ppapi