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

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

Issue 7330027: Add an example for using the URLLoader in streaming mode. This also avoids the (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 5 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 #ifndef PPAPI_CPP_URL_LOADER_H_ 5 #ifndef PPAPI_CPP_URL_LOADER_H_
6 #define PPAPI_CPP_URL_LOADER_H_ 6 #define PPAPI_CPP_URL_LOADER_H_
7 7
8 #include "ppapi/c/pp_stdint.h" 8 #include "ppapi/c/pp_stdint.h"
9 #include "ppapi/cpp/resource.h" 9 #include "ppapi/cpp/resource.h"
10 10
11 namespace pp { 11 namespace pp {
12 12
13 class CompletionCallback; 13 class CompletionCallback;
14 class Instance; 14 class Instance;
15 class URLRequestInfo; 15 class URLRequestInfo;
16 class URLResponseInfo; 16 class URLResponseInfo;
17 17
18 // URLLoader provides an API to download URLs. 18 // URLLoader provides an API to download URLs.
19 // 19 //
20 // EXAMPLE USAGE: 20 // Please see the example in ppapi/examples/url_loader/url_loader.cc.
21 //
22 // class MyHandler {
23 // public:
24 // MyHandler(Instance* instance)
25 // : factory_(this),
26 // loader_(instance),
27 // did_open_(false) {
28 // }
29 // void ProcessURL(const char* url) {
30 // CompletionCallback* cc = NewCallback();
31 // int32_t rv = loader_.Open(MakeRequest(url), cc);
32 // if (rv != PP_Error_WouldBlock)
33 // cc->Run(rv);
34 // }
35 // private:
36 // CompletionCallback* NewCallback() {
37 // return factory_.NewOptionalCallback(&MyHandler::DidCompleteIO);
38 // }
39 // URLRequestInfo MakeRequest(const char* url) {
40 // URLRequestInfo request;
41 // request.SetURL(url);
42 // request.SetMethod("GET");
43 // request.SetFollowRedirects(true);
44 // return request;
45 // }
46 // void DidCompleteIO(int32_t result) {
47 // if (result > 0) {
48 // // buf_ now contains 'result' number of bytes from the URL.
49 // ProcessBytes(buf_, result);
50 // ReadMore();
51 // } else if (result == PP_OK && !did_open_) {
52 // // Headers are available, and we can start reading the body.
53 // did_open_ = true;
54 // ProcessResponseInfo(loader_.GetResponseInfo());
55 // ReadMore();
56 // } else {
57 // // Done reading (possibly with an error given by 'result').
58 // }
59 // }
60 // void ReadMore() {
61 // CompletionCallback* cc = NewCallback();
62 // int32_t rv = fio_.Read(offset_, buf_, sizeof(buf_), cc);
63 // if (rv != PP_Error_WouldBlock)
64 // cc->Run(rv);
65 // }
66 // void ProcessResponseInfo(const URLResponseInfo& response_info) {
67 // // Read response headers, etc.
68 // }
69 // void ProcessBytes(const char* bytes, int32_t length) {
70 // // Do work ...
71 // }
72 // pp::CompletionCallbackFactory<MyHandler> factory_;
73 // pp::URLLoader loader_;
74 // char buf_[4096];
75 // bool did_open_;
76 // };
77 //
78 class URLLoader : public Resource { 21 class URLLoader : public Resource {
79 public: 22 public:
80 // Creates an is_null() URLLoader object. 23 // Creates an is_null() URLLoader object.
81 URLLoader() {} 24 URLLoader() {}
82 25
83 // TODO(brettw) remove this when NaCl is updated to use the new version 26 // TODO(brettw) remove this when NaCl is updated to use the new version
84 // that takes a pointer. 27 // that takes a pointer.
85 explicit URLLoader(const Instance& instance); 28 explicit URLLoader(const Instance& instance);
86 29
87 explicit URLLoader(PP_Resource resource); 30 explicit URLLoader(PP_Resource resource);
(...skipping 12 matching lines...) Expand all
100 int32_t ReadResponseBody(void* buffer, 43 int32_t ReadResponseBody(void* buffer,
101 int32_t bytes_to_read, 44 int32_t bytes_to_read,
102 const CompletionCallback& cc); 45 const CompletionCallback& cc);
103 int32_t FinishStreamingToFile(const CompletionCallback& cc); 46 int32_t FinishStreamingToFile(const CompletionCallback& cc);
104 void Close(); 47 void Close();
105 }; 48 };
106 49
107 } // namespace pp 50 } // namespace pp
108 51
109 #endif // PPAPI_CPP_URL_LOADER_H_ 52 #endif // PPAPI_CPP_URL_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | ppapi/examples/url_loader/README_chrome_developer.txt » ('j') | ppapi/examples/url_loader/streaming.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698