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

Side by Side Diff: core/cross/file_request.h

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
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 24 matching lines...) Expand all
35 #ifndef O3D_CORE_CROSS_FILE_REQUEST_H_ 35 #ifndef O3D_CORE_CROSS_FILE_REQUEST_H_
36 #define O3D_CORE_CROSS_FILE_REQUEST_H_ 36 #define O3D_CORE_CROSS_FILE_REQUEST_H_
37 37
38 #include <algorithm> 38 #include <algorithm>
39 #include <string> 39 #include <string>
40 40
41 #include "base/scoped_ptr.h" 41 #include "base/scoped_ptr.h"
42 #include "core/cross/callback.h" 42 #include "core/cross/callback.h"
43 #include "core/cross/object_base.h" 43 #include "core/cross/object_base.h"
44 #include "core/cross/pack.h" 44 #include "core/cross/pack.h"
45 #include "import/cross/raw_data.h"
45 46
46 namespace o3d { 47 namespace o3d {
47 48
48 typedef Closure FileRequestCallback; 49 typedef Closure FileRequestCallback;
49 50
50 // A FileRequest object is used to carry out an asynchronous request for a file 51 // A FileRequest object is used to carry out an asynchronous request for a file
51 // to be loaded. 52 // to be loaded.
52 class FileRequest : public ObjectBase { 53 class FileRequest : public ObjectBase {
53 public: 54 public:
54 enum Type { 55 enum Type {
55 TYPE_INVALID, 56 TYPE_INVALID,
56 TYPE_TEXTURE, 57 TYPE_TEXTURE,
57 TYPE_MAX = TYPE_TEXTURE, 58 TYPE_RAWDATA,
59 TYPE_MAX = TYPE_RAWDATA,
58 }; 60 };
59 61
60 enum ReadyState { // These are copied from XMLHttpRequest. 62 enum ReadyState { // These are copied from XMLHttpRequest.
61 STATE_INIT = 0, 63 STATE_INIT = 0,
62 STATE_OPEN = 1, 64 STATE_OPEN = 1,
63 STATE_SENT = 2, 65 STATE_SENT = 2,
64 STATE_RECEIVING = 3, 66 STATE_RECEIVING = 3,
65 STATE_LOADED = 4, 67 STATE_LOADED = 4,
66 }; 68 };
67 69
68 public: 70 public:
69 typedef SmartPointer<FileRequest> Ref; 71 typedef SmartPointer<FileRequest> Ref;
70 72
71 virtual ~FileRequest() { } 73 virtual ~FileRequest() { }
72 74
73 static FileRequest *Create(ServiceLocator* service_locator, 75 static FileRequest *Create(ServiceLocator* service_locator,
74 Pack *pack, 76 Pack *pack,
75 Type type); 77 Type type);
76 78
77 static Type TypeFromString(String type) { 79 static Type TypeFromString(String type) {
78 std::transform(type.begin(), 80 std::transform(type.begin(),
79 type.end(), 81 type.end(),
80 type.begin(), 82 type.begin(),
81 ::tolower); 83 ::tolower);
82 if (type == "texture") { 84 if (type == "texture") {
83 return TYPE_TEXTURE; 85 return TYPE_TEXTURE;
84 } 86 }
87 if (type == "rawdata") {
88 return TYPE_RAWDATA;
89 }
85 return TYPE_INVALID; 90 return TYPE_INVALID;
86 } 91 }
87 92
88 static bool IsValidType(Type type) { 93 static bool IsValidType(Type type) {
89 return type > TYPE_INVALID && type <= TYPE_MAX; 94 return type > TYPE_INVALID && type <= TYPE_MAX;
90 } 95 }
91 Pack *pack() const { 96 Pack *pack() const {
92 return pack_.Get(); // Set at creation time and never changed. 97 return pack_.Get(); // Set at creation time and never changed.
93 } 98 }
94 FileRequestCallback *onreadystatechange() const { 99 FileRequestCallback *onreadystatechange() const {
95 return onreadystatechange_.get(); 100 return onreadystatechange_.get();
96 } 101 }
97 void set_onreadystatechange(FileRequestCallback *onreadystatechange) { 102 void set_onreadystatechange(FileRequestCallback *onreadystatechange) {
98 onreadystatechange_.reset(onreadystatechange); 103 onreadystatechange_.reset(onreadystatechange);
99 } 104 }
100 const String& uri() const { 105 const String& uri() const {
101 return uri_; 106 return uri_;
102 } 107 }
103 void set_uri(const String& uri) { 108 void set_uri(const String& uri) {
104 uri_ = uri; 109 uri_ = uri;
105 } 110 }
106 Type type() const { 111 Type type() const {
107 return type_; // Set at creation time and never changed. 112 return type_; // Set at creation time and never changed.
108 } 113 }
109 Texture *texture() const { 114 Texture *texture() const {
110 return texture_.Get(); 115 return texture_.Get();
111 } 116 }
117 RawData *data() const {
118 return data_.Get();
119 }
112 bool generate_mipmaps() const { return generate_mipmaps_; } 120 bool generate_mipmaps() const { return generate_mipmaps_; }
113 void set_generate_mipmaps(bool value) { 121 void set_generate_mipmaps(bool value) {
114 generate_mipmaps_ = value; 122 generate_mipmaps_ = value;
115 } 123 }
116 void set_texture(Texture *texture) { 124 void set_texture(Texture *texture) {
117 CHECK(type_ == TYPE_TEXTURE); 125 CHECK(type_ == TYPE_TEXTURE);
118 texture_ = Texture::Ref(texture); 126 texture_ = Texture::Ref(texture);
119 } 127 }
128 void set_data(RawData *data) {
129 CHECK(type_ == TYPE_RAWDATA);
130 data_ = RawData::Ref(data);
131 }
120 bool done() const { 132 bool done() const {
121 return done_; 133 return done_;
122 } 134 }
123 bool success() const { 135 bool success() const {
124 return success_; 136 return success_;
125 } 137 }
126 void set_success(bool success) { 138 void set_success(bool success) {
127 success_ = success; 139 success_ = success;
128 done_ = true; 140 done_ = true;
129 pack_.Reset(); // Removes pack reference, allowing pack garbage collection. 141 pack_.Reset(); // Removes pack reference, allowing pack garbage collection.
(...skipping 16 matching lines...) Expand all
146 private: 158 private:
147 FileRequest(ServiceLocator* service_locator, 159 FileRequest(ServiceLocator* service_locator,
148 Pack *pack, 160 Pack *pack,
149 Type type); 161 Type type);
150 162
151 Pack::Ref pack_; 163 Pack::Ref pack_;
152 scoped_ptr<FileRequestCallback> onreadystatechange_; 164 scoped_ptr<FileRequestCallback> onreadystatechange_;
153 String uri_; 165 String uri_;
154 Type type_; 166 Type type_;
155 Texture::Ref texture_; // Only used on a successful texture load. 167 Texture::Ref texture_; // Only used on a successful texture load.
168 RawData::Ref data_; // Only used on a successful RawData load.
156 bool generate_mipmaps_; 169 bool generate_mipmaps_;
157 bool done_; // Set after completion/failure to indicate success_ is valid. 170 bool done_; // Set after completion/failure to indicate success_ is valid.
158 bool success_; // Set after completion/failure to indicate which it is. 171 bool success_; // Set after completion/failure to indicate which it is.
159 int ready_state_; // Like the XMLHttpRequest variable of the same name. 172 int ready_state_; // Like the XMLHttpRequest variable of the same name.
160 String error_; 173 String error_;
161 174
162 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRequest); 175 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRequest);
163 }; // FileRequest 176 }; // FileRequest
164 177
165 } // namespace o3d 178 } // namespace o3d
166 179
167 #endif // O3D_CORE_CROSS_FILE_REQUEST_H_ 180 #endif // O3D_CORE_CROSS_FILE_REQUEST_H_
OLDNEW
« no previous file with comments | « core/cross/bitmap.cc ('k') | import/cross/raw_data.h » ('j') | plugin/cross/async_loading.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698