Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: ppapi/cpp/url_loader.cc

Issue 9381010: Convert resources to take an instance key instead of an Instance*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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/completion_callback.h" 9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/file_ref.h" 10 #include "ppapi/cpp/file_ref.h"
11 #include "ppapi/cpp/instance.h" 11 #include "ppapi/cpp/instance_handle.h"
12 #include "ppapi/cpp/module.h" 12 #include "ppapi/cpp/module.h"
13 #include "ppapi/cpp/module_impl.h" 13 #include "ppapi/cpp/module_impl.h"
14 #include "ppapi/cpp/url_request_info.h" 14 #include "ppapi/cpp/url_request_info.h"
15 #include "ppapi/cpp/url_response_info.h" 15 #include "ppapi/cpp/url_response_info.h"
16 16
17 namespace pp { 17 namespace pp {
18 18
19 namespace { 19 namespace {
20 20
21 template <> const char* interface_name<PPB_URLLoader>() { 21 template <> const char* interface_name<PPB_URLLoader>() {
22 return PPB_URLLOADER_INTERFACE; 22 return PPB_URLLOADER_INTERFACE;
23 } 23 }
24 24
25 } // namespace 25 } // namespace
26 26
27 URLLoader::URLLoader(PP_Resource resource) : Resource(resource) { 27 URLLoader::URLLoader(PP_Resource resource) : Resource(resource) {
28 } 28 }
29 29
30 // TODO(brettw) remove this when NaCl is updated. 30 // TODO(brettw) remove this when NaCl is updated.
31 URLLoader::URLLoader(const Instance& instance) { 31 /*URLLoader::URLLoader(const Instance& instance) {
32 if (!has_interface<PPB_URLLoader>())
33 return;
34 PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create(
35 instance.pp_instance()));
36 }*/
dmichael (off chromium) 2012/02/21 23:38:02 So I guess we can delete this now...
37
38 URLLoader::URLLoader(const InstanceHandle& instance) {
32 if (!has_interface<PPB_URLLoader>()) 39 if (!has_interface<PPB_URLLoader>())
33 return; 40 return;
34 PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create( 41 PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create(
35 instance.pp_instance())); 42 instance.pp_instance()));
36 } 43 }
37 44
38 URLLoader::URLLoader(Instance* instance) {
39 if (!has_interface<PPB_URLLoader>())
40 return;
41 PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create(
42 instance->pp_instance()));
43 }
44
45 URLLoader::URLLoader(const URLLoader& other) : Resource(other) { 45 URLLoader::URLLoader(const URLLoader& other) : Resource(other) {
46 } 46 }
47 47
48 int32_t URLLoader::Open(const URLRequestInfo& request_info, 48 int32_t URLLoader::Open(const URLRequestInfo& request_info,
49 const CompletionCallback& cc) { 49 const CompletionCallback& cc) {
50 if (!has_interface<PPB_URLLoader>()) 50 if (!has_interface<PPB_URLLoader>())
51 return cc.MayForce(PP_ERROR_NOINTERFACE); 51 return cc.MayForce(PP_ERROR_NOINTERFACE);
52 return get_interface<PPB_URLLoader>()->Open(pp_resource(), 52 return get_interface<PPB_URLLoader>()->Open(pp_resource(),
53 request_info.pp_resource(), 53 request_info.pp_resource(),
54 cc.pp_completion_callback()); 54 cc.pp_completion_callback());
(...skipping 19 matching lines...) Expand all
74 int64_t* total_bytes_to_be_received) const { 74 int64_t* total_bytes_to_be_received) const {
75 if (!has_interface<PPB_URLLoader>()) 75 if (!has_interface<PPB_URLLoader>())
76 return false; 76 return false;
77 return PP_ToBool(get_interface<PPB_URLLoader>()->GetDownloadProgress( 77 return PP_ToBool(get_interface<PPB_URLLoader>()->GetDownloadProgress(
78 pp_resource(), bytes_received, total_bytes_to_be_received)); 78 pp_resource(), bytes_received, total_bytes_to_be_received));
79 } 79 }
80 80
81 URLResponseInfo URLLoader::GetResponseInfo() const { 81 URLResponseInfo URLLoader::GetResponseInfo() const {
82 if (!has_interface<PPB_URLLoader>()) 82 if (!has_interface<PPB_URLLoader>())
83 return URLResponseInfo(); 83 return URLResponseInfo();
84 return URLResponseInfo(URLResponseInfo::PassRef(), 84 return URLResponseInfo(PASS_REF,
85 get_interface<PPB_URLLoader>()->GetResponseInfo( 85 get_interface<PPB_URLLoader>()->GetResponseInfo(
86 pp_resource())); 86 pp_resource()));
87 } 87 }
88 88
89 int32_t URLLoader::ReadResponseBody(void* buffer, 89 int32_t URLLoader::ReadResponseBody(void* buffer,
90 int32_t bytes_to_read, 90 int32_t bytes_to_read,
91 const CompletionCallback& cc) { 91 const CompletionCallback& cc) {
92 if (!has_interface<PPB_URLLoader>()) 92 if (!has_interface<PPB_URLLoader>())
93 return cc.MayForce(PP_ERROR_NOINTERFACE); 93 return cc.MayForce(PP_ERROR_NOINTERFACE);
94 return get_interface<PPB_URLLoader>()->ReadResponseBody( 94 return get_interface<PPB_URLLoader>()->ReadResponseBody(
95 pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback()); 95 pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback());
96 } 96 }
97 97
98 int32_t URLLoader::FinishStreamingToFile(const CompletionCallback& cc) { 98 int32_t URLLoader::FinishStreamingToFile(const CompletionCallback& cc) {
99 if (!has_interface<PPB_URLLoader>()) 99 if (!has_interface<PPB_URLLoader>())
100 return cc.MayForce(PP_ERROR_NOINTERFACE); 100 return cc.MayForce(PP_ERROR_NOINTERFACE);
101 return get_interface<PPB_URLLoader>()->FinishStreamingToFile( 101 return get_interface<PPB_URLLoader>()->FinishStreamingToFile(
102 pp_resource(), cc.pp_completion_callback()); 102 pp_resource(), cc.pp_completion_callback());
103 } 103 }
104 104
105 void URLLoader::Close() { 105 void URLLoader::Close() {
106 if (!has_interface<PPB_URLLoader>()) 106 if (!has_interface<PPB_URLLoader>())
107 return; 107 return;
108 get_interface<PPB_URLLoader>()->Close(pp_resource()); 108 get_interface<PPB_URLLoader>()->Close(pp_resource());
109 } 109 }
110 110
111 } // namespace pp 111 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698