OLD | NEW |
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 <math.h> | 5 #include <math.h> |
6 #include <stdio.h> // FIXME(brettw) erase me. | 6 #include <stdio.h> // FIXME(brettw) erase me. |
7 #ifndef _WIN32 | 7 #ifndef _WIN32 |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #else | 9 #else |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 const pp::Var& url, | 100 const pp::Var& url, |
101 MyFetcherClient* client) { | 101 MyFetcherClient* client) { |
102 pp::URLRequestInfo request; | 102 pp::URLRequestInfo request; |
103 request.SetURL(url); | 103 request.SetURL(url); |
104 request.SetMethod("GET"); | 104 request.SetMethod("GET"); |
105 | 105 |
106 loader_ = pp::URLLoader(instance); | 106 loader_ = pp::URLLoader(instance); |
107 client_ = client; | 107 client_ = client; |
108 | 108 |
109 pp::CompletionCallback callback = | 109 pp::CompletionCallback callback = |
110 callback_factory_.NewCallback(&MyFetcher::DidOpen); | 110 callback_factory_.NewOptionalCallback(&MyFetcher::DidOpen); |
111 int rv = loader_.Open(request, callback); | 111 int rv = loader_.Open(request, callback); |
112 if (rv != PP_OK_COMPLETIONPENDING) | 112 if (rv != PP_OK_COMPLETIONPENDING) |
113 callback.Run(rv); | 113 callback.Run(rv); |
114 } | 114 } |
115 | 115 |
116 void StartWithOpenedLoader(const pp::URLLoader& loader, | 116 void StartWithOpenedLoader(const pp::URLLoader& loader, |
117 MyFetcherClient* client) { | 117 MyFetcherClient* client) { |
118 loader_ = loader; | 118 loader_ = loader; |
119 client_ = client; | 119 client_ = client; |
120 | 120 |
121 ReadMore(); | 121 ReadMore(); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 void ReadMore() { | 125 void ReadMore() { |
126 pp::CompletionCallback callback = | 126 pp::CompletionCallback callback = |
127 callback_factory_.NewCallback(&MyFetcher::DidRead); | 127 callback_factory_.NewOptionalCallback(&MyFetcher::DidRead); |
128 int rv = loader_.ReadResponseBody(buf_, sizeof(buf_), callback); | 128 int rv = loader_.ReadResponseBody(buf_, sizeof(buf_), callback); |
129 if (rv != PP_OK_COMPLETIONPENDING) | 129 if (rv != PP_OK_COMPLETIONPENDING) |
130 callback.Run(rv); | 130 callback.Run(rv); |
131 } | 131 } |
132 | 132 |
133 void DidOpen(int32_t result) { | 133 void DidOpen(int32_t result) { |
134 if (result == PP_OK) { | 134 if (result == PP_OK) { |
135 ReadMore(); | 135 ReadMore(); |
136 } else { | 136 } else { |
137 DidFinish(result); | 137 DidFinish(result); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 }; | 482 }; |
483 | 483 |
484 namespace pp { | 484 namespace pp { |
485 | 485 |
486 // Factory function for your specialization of the Module object. | 486 // Factory function for your specialization of the Module object. |
487 Module* CreateModule() { | 487 Module* CreateModule() { |
488 return new MyModule(); | 488 return new MyModule(); |
489 } | 489 } |
490 | 490 |
491 } // namespace pp | 491 } // namespace pp |
OLD | NEW |