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

Side by Side Diff: plugin/cross/async_loading.cc

Issue 149784: Add RawData request in preparation for manual loading of... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: Created 11 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
« no previous file with comments | « plugin/cross/async_loading.h ('k') | plugin/idl/file_request.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 23 matching lines...) Expand all
34 #include <algorithm> 34 #include <algorithm>
35 35
36 #include "plugin/cross/async_loading.h" 36 #include "plugin/cross/async_loading.h"
37 #include "plugin/cross/o3d_glue.h" 37 #include "plugin/cross/o3d_glue.h"
38 #include "plugin/cross/stream_manager.h" 38 #include "plugin/cross/stream_manager.h"
39 #include "core/cross/bitmap.h" 39 #include "core/cross/bitmap.h"
40 #include "core/cross/error_status.h" 40 #include "core/cross/error_status.h"
41 #include "core/cross/file_request.h" 41 #include "core/cross/file_request.h"
42 #include "core/cross/pack.h" 42 #include "core/cross/pack.h"
43 #include "core/cross/texture.h" 43 #include "core/cross/texture.h"
44 #include "import/cross/raw_data.h"
44 45
45 namespace glue { 46 namespace glue {
46 namespace namespace_o3d { 47 namespace namespace_o3d {
47 namespace class_FileRequest { 48 namespace class_FileRequest {
48 49
49 using _o3d::PluginObject; 50 using _o3d::PluginObject;
50 using o3d::Bitmap; 51 using o3d::Bitmap;
51 using o3d::Pack; 52 using o3d::Pack;
53 using o3d::RawData;
52 using o3d::Texture; 54 using o3d::Texture;
53 55
54 // StreamManager::FinishedCallback 56 // StreamManager::FinishedCallback
55 // implementation that imports the file as a texture once downloaded. 57 // implementation that imports the file as a texture once downloaded.
56 // When the download completes, LoadTextureURLCallback::Run() will be called, 58 // When the download completes, LoadTextureURLCallback::Run() will be called,
57 // which will parse and load the downloaded file. After that load is complete, 59 // which will parse and load the downloaded file. After that load is complete,
58 // onreadystatechange will be run to notify the user. 60 // onreadystatechange will be run to notify the user.
59 class LoadTextureURLCallback : public StreamManager::FinishedCallback { 61 class LoadTextureURLCallback : public StreamManager::FinishedCallback {
60 public: 62 public:
61 // Creates a new LoadTextureURLCallback. 63 // Creates a new LoadTextureURLCallback.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 119 }
118 120
119 private: 121 private:
120 FileRequest::Ref request_; 122 FileRequest::Ref request_;
121 123
122 explicit LoadTextureURLCallback(FileRequest *request) 124 explicit LoadTextureURLCallback(FileRequest *request)
123 : request_(request) { 125 : request_(request) {
124 } 126 }
125 }; 127 };
126 128
129 // StreamManager::FinishedCallback
130 // implementation that imports the file as a RawData once downloaded. When the
131 // download completes, LoadRawDataURLCallback::Run() will be called, which will
132 // parse and load the downloaded file. After that load is complete,
133 // onreadystatechange will be run to notify the user.
134 class LoadRawDataURLCallback : public StreamManager::FinishedCallback {
135 public:
136 // Creates a new LoadRawDataURLCallback.
137 static LoadRawDataURLCallback *Create(FileRequest *request) {
138 return new LoadRawDataURLCallback(request);
139 }
140
141 virtual ~LoadRawDataURLCallback() {
142 // If the file request was interrupted (for example we moved to a new page
143 // before the file transfer was completed) then we tell the FileRequest
144 // object that the request failed. It's important to call this here since
145 // set_success() will release the pack reference that the FileRequest holds
146 // which will allow the pack to be garbage collected.
147 if (!request_->done()) {
148 request_->set_success(false);
149 }
150 }
151
152 // Loads the RawData file, calls the JS callback to pass back the RawData
153 // object.
154 virtual void Run(DownloadStream*,
155 bool success,
156 const std::string &filename,
157 const std::string &mime_type) {
158 RawData::Ref data;
159 if (success) {
160 o3d::ErrorCollector error_collector(request_->service_locator());
161 request_->set_ready_state(FileRequest::STATE_LOADED);
162 data = RawData::Ref(RawData::CreateFromFile(request_->service_locator(),
163 request_->uri(),
164 filename));
165 if (data) {
166 request_->set_data(data);
167 } else {
168 success = false;
169 }
170 request_->set_error(error_collector.errors());
171 } else {
172 // No error is passed in from the stream but we MUST have an error
173 // for the request to work on the javascript side.
174 request_->set_error("Could not download texture: " + request_->uri());
Chris Rogers 2009/07/17 18:47:16 should be: "Could not download raw data"
175 }
176 request_->set_success(success);
177 // Since the standard codes only go far enough to tell us that the download
178 // succeeded, we set the success [and implicitly the done] flags to give the
179 // rest of the story.
180 if (request_->onreadystatechange())
181 request_->onreadystatechange()->Run();
182 }
183
184 private:
185 FileRequest::Ref request_;
186
187 explicit LoadRawDataURLCallback(FileRequest *request)
188 : request_(request) {
189 }
190 };
191
127 // Sets up the parameters required for all FileRequests. 192 // Sets up the parameters required for all FileRequests.
128 void userglue_method_open(void *plugin_data, 193 void userglue_method_open(void *plugin_data,
129 FileRequest *request, 194 FileRequest *request,
130 const String &method, 195 const String &method,
131 const String &uri, 196 const String &uri,
132 bool async) { 197 bool async) {
133 if (!async) { 198 if (!async) {
134 request->set_success(false); 199 request->set_success(false);
135 O3D_ERROR(request->service_locator()) 200 O3D_ERROR(request->service_locator())
136 << ("synchronous request not supported"); 201 << ("synchronous request not supported");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 O3D_ERROR(request->service_locator()) 241 O3D_ERROR(request->service_locator())
177 << "open must be called before send"; 242 << "open must be called before send";
178 return; 243 return;
179 } 244 }
180 CHECK(request->pack()); 245 CHECK(request->pack());
181 246
182 switch (request->type()) { 247 switch (request->type()) {
183 case FileRequest::TYPE_TEXTURE: 248 case FileRequest::TYPE_TEXTURE:
184 callback = LoadTextureURLCallback::Create(request); 249 callback = LoadTextureURLCallback::Create(request);
185 break; 250 break;
251 case FileRequest::TYPE_RAWDATA:
252 callback = LoadRawDataURLCallback::Create(request);
253 break;
186 default: 254 default:
187 CHECK(false); 255 CHECK(false);
188 } 256 }
189 if (callback) { 257 if (callback) {
190 DownloadStream *stream = 258 DownloadStream *stream =
191 stream_manager->LoadURL(request->uri(), 259 stream_manager->LoadURL(request->uri(),
192 NULL, // new stream callback 260 NULL, // new stream callback
193 NULL, // write ready callback 261 NULL, // write ready callback
194 NULL, // write callback 262 NULL, // write callback
195 callback, // finished callback 263 callback, // finished callback
(...skipping 16 matching lines...) Expand all
212 280
213 // If stream is not NULL request may not exist as LoadURL may already have 281 // If stream is not NULL request may not exist as LoadURL may already have
214 // completed and therefore called the callback which may have freed the 282 // completed and therefore called the callback which may have freed the
215 // request so we can't set anything on the request here. 283 // request so we can't set anything on the request here.
216 } 284 }
217 } 285 }
218 286
219 } // namespace class_FileRequest 287 } // namespace class_FileRequest
220 } // namespace namespace_o3d 288 } // namespace namespace_o3d
221 } // namespace glue 289 } // namespace glue
OLDNEW
« no previous file with comments | « plugin/cross/async_loading.h ('k') | plugin/idl/file_request.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698