| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 | 7 |
| 8 #include <iostream> | 8 #include <iostream> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 if (result != PP_OK) { | 138 if (result != PP_OK) { |
| 139 reader->Message("Error: FileOpenCompleteCallback unexpected result"); | 139 reader->Message("Error: FileOpenCompleteCallback unexpected result"); |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 | 142 |
| 143 reader->ReadMore(); | 143 reader->ReadMore(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void OpenFile() { | 146 void OpenFile() { |
| 147 file_ref_ = new pp::FileRef(response_info_->GetBodyAsFileRef()); | 147 file_ref_ = new pp::FileRef(loader_.GetResponseInfo().GetBodyAsFileRef()); |
| 148 CHECK(!file_ref_->is_null()); | 148 CHECK(!file_ref_->is_null()); |
| 149 | 149 |
| 150 file_io_ = new pp::FileIO(instance_); | 150 file_io_ = new pp::FileIO(instance_); |
| 151 CHECK(!file_io_->is_null()); | 151 CHECK(!file_io_->is_null()); |
| 152 | 152 |
| 153 pp::CompletionCallback cc(OpenFileCompleteCallback, this); | 153 pp::CompletionCallback cc(OpenFileCompleteCallback, this); |
| 154 int32_t rv = file_io_->Open(*file_ref_, PP_FILEOPENFLAG_READ, cc); | 154 int32_t rv = file_io_->Open(*file_ref_, PP_FILEOPENFLAG_READ, cc); |
| 155 if (rv != PP_OK_COMPLETIONPENDING) { | 155 if (rv != PP_OK_COMPLETIONPENDING) { |
| 156 Message("Error: OpenFile unexpected rv"); | 156 Message("Error: OpenFile unexpected rv"); |
| 157 } | 157 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 176 } else if (rv != PP_OK_COMPLETIONPENDING) { | 176 } else if (rv != PP_OK_COMPLETIONPENDING) { |
| 177 Message("Error: Finish unexpected rv"); | 177 Message("Error: Finish unexpected rv"); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 // this callback handles both regular and "stream-to-file" mode | 181 // this callback handles both regular and "stream-to-file" mode |
| 182 // But control flow diverges afterwards | 182 // But control flow diverges afterwards |
| 183 static void OpenURLCompleteCallback(void* thiz, int32_t result) { | 183 static void OpenURLCompleteCallback(void* thiz, int32_t result) { |
| 184 ReaderStreamAsFile* reader = static_cast<ReaderStreamAsFile*>(thiz); | 184 ReaderStreamAsFile* reader = static_cast<ReaderStreamAsFile*>(thiz); |
| 185 | 185 |
| 186 reader->response_info_ = | 186 pp::URLResponseInfo response_info(reader->loader_.GetResponseInfo()); |
| 187 new pp::URLResponseInfo(reader->loader_.GetResponseInfo()); | 187 CHECK(!response_info.is_null()); |
| 188 CHECK(!reader->response_info_->is_null()); | 188 int32_t status_code = response_info.GetStatusCode(); |
| 189 int32_t status_code = reader->response_info_->GetStatusCode(); | |
| 190 if (status_code != 200) { | 189 if (status_code != 200) { |
| 191 reader->Message("Error: OpenURLCompleteCallback unexpected status code"); | 190 reader->Message("Error: OpenURLCompleteCallback unexpected status code"); |
| 192 return; | 191 return; |
| 193 } | 192 } |
| 194 | 193 |
| 195 reader->Finish(); | 194 reader->Finish(); |
| 196 } | 195 } |
| 197 | 196 |
| 198 void OpenURL(const string& url) { | 197 void OpenURL(const string& url) { |
| 199 pp::URLRequestInfo request(instance_); | 198 pp::URLRequestInfo request(instance_); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 315 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 317 return new MyInstance(instance); | 316 return new MyInstance(instance); |
| 318 } | 317 } |
| 319 }; | 318 }; |
| 320 | 319 |
| 321 namespace pp { | 320 namespace pp { |
| 322 Module* CreateModule() { | 321 Module* CreateModule() { |
| 323 return new MyModule(); | 322 return new MyModule(); |
| 324 } | 323 } |
| 325 } | 324 } |
| OLD | NEW |