Remove Observer methods in RTCVideoEncoderFactory.
[chromium-blink-merge.git] / ppapi / thunk / ppb_url_loader_thunk.cc
blob22594298f5da305c636cca7172b9d0d0cf0993ea
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 Aug 20 08:13:36 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,
99 bytes_to_read,
100 enter.callback()));
103 int32_t FinishStreamingToFile(PP_Resource loader,
104 struct PP_CompletionCallback callback) {
105 VLOG(4) << "PPB_URLLoader::FinishStreamingToFile()";
106 EnterResource<PPB_URLLoader_API> enter(loader, callback, true);
107 if (enter.failed())
108 return enter.retval();
109 return enter.SetResult(enter.object()->FinishStreamingToFile(
110 enter.callback()));
113 void Close(PP_Resource loader) {
114 VLOG(4) << "PPB_URLLoader::Close()";
115 EnterResource<PPB_URLLoader_API> enter(loader, true);
116 if (enter.failed())
117 return;
118 enter.object()->Close();
121 const PPB_URLLoader_1_0 g_ppb_urlloader_thunk_1_0 = {
122 &Create,
123 &IsURLLoader,
124 &Open,
125 &FollowRedirect,
126 &GetUploadProgress,
127 &GetDownloadProgress,
128 &GetResponseInfo,
129 &ReadResponseBody,
130 &FinishStreamingToFile,
131 &Close
134 } // namespace
136 PPAPI_THUNK_EXPORT const PPB_URLLoader_1_0* GetPPB_URLLoader_1_0_Thunk() {
137 return &g_ppb_urlloader_thunk_1_0;
140 } // namespace thunk
141 } // namespace ppapi