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

Side by Side Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 249183004: Implement open_resource in non-SFI mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private_impl.h" 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/containers/scoped_ptr_hash_map.h" 10 #include "base/containers/scoped_ptr_hash_map.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 147 }
148 148
149 private: 149 private:
150 int num_remaining_calls_; 150 int num_remaining_calls_;
151 PP_CompletionCallback callback_; 151 PP_CompletionCallback callback_;
152 int32_t result_; 152 int32_t result_;
153 153
154 DISALLOW_COPY_AND_ASSIGN(ChannelConnectedCallback); 154 DISALLOW_COPY_AND_ASSIGN(ChannelConnectedCallback);
155 }; 155 };
156 156
157 // Thin adapter from PP_ManifestService to ManifestServiceChannel::Delegate. 157 // Thin adapter from PPP_ManifestService to ManifestServiceChannel::Delegate.
158 // Note that user_data is managed by the caller of LaunchSelLdr. Please see 158 // Note that user_data is managed by the caller of LaunchSelLdr. Please see
159 // also PP_ManifestService's comment for more details about resource 159 // also PP_ManifestService's comment for more details about resource
160 // management. 160 // management.
161 class ManifestServiceProxy : public ManifestServiceChannel::Delegate { 161 class ManifestServiceProxy : public ManifestServiceChannel::Delegate {
162 public: 162 public:
163 ManifestServiceProxy(const PP_ManifestService* manifest_service, 163 ManifestServiceProxy(const PPP_ManifestService* manifest_service,
164 void* user_data) 164 void* user_data)
165 : manifest_service_(*manifest_service), 165 : manifest_service_(*manifest_service),
166 user_data_(user_data) { 166 user_data_(user_data) {
167 } 167 }
168 168
169 virtual ~ManifestServiceProxy() { 169 virtual ~ManifestServiceProxy() {
170 Quit(); 170 Quit();
171 } 171 }
172 172
173 virtual void StartupInitializationComplete() OVERRIDE { 173 virtual void StartupInitializationComplete() OVERRIDE {
174 if (!user_data_) 174 if (!user_data_)
175 return; 175 return;
176 176
177 if (!PP_ToBool( 177 if (!PP_ToBool(
178 manifest_service_.StartupInitializationComplete(user_data_))) { 178 manifest_service_.StartupInitializationComplete(user_data_))) {
179 user_data_ = NULL; 179 user_data_ = NULL;
180 } 180 }
181 } 181 }
182 182
183 virtual void OpenResource(
184 const std::string& key,
185 const ManifestServiceChannel::OpenResourceCallback& callback) OVERRIDE {
186 if (!user_data_)
187 return;
188
189 OpenResourceCallbackData* data = new OpenResourceCallbackData(callback);
190 if (!PP_ToBool(manifest_service_.OpenResource(
191 user_data_,
192 key.c_str(),
193 &data->platform_file,
dmichael (off chromium) 2014/04/25 21:06:58 nit: I think parens around data->platform_file wou
hidehiko 2014/04/28 08:44:27 Acknowledged.
194 PP_MakeCompletionCallback(DidOpenResource, data)))) {
195 // When failed, callback won't be invoked, so it is necessary to free
196 // the data.
197 delete data;
198 user_data_ = NULL;
199 }
200
201 // When succeeded, the callback will be called, and the data will be freed
teravest 2014/04/25 20:44:02 Would it be simpler to always invoke the callback?
hidehiko 2014/04/28 08:44:27 Done.
202 // in the callback.
203 }
204
183 private: 205 private:
206 struct OpenResourceCallbackData {
207 explicit OpenResourceCallbackData(
208 const ManifestServiceChannel::OpenResourceCallback& callback)
209 : platform_file(base::kInvalidPlatformFileValue), callback(callback) {
210 }
211
212 base::PlatformFile platform_file;
213 ManifestServiceChannel::OpenResourceCallback callback;
214 };
215
216 static void DidOpenResource(void* user_data, int32_t pp_error) {
217 scoped_ptr<OpenResourceCallbackData> data(
218 static_cast<OpenResourceCallbackData*>(user_data));
219 data->callback.Run(pp_error, data->platform_file);
220 }
221
184 void Quit() { 222 void Quit() {
185 if (!user_data_) 223 if (!user_data_)
186 return; 224 return;
187 225
188 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); 226 bool result = PP_ToBool(manifest_service_.Quit(user_data_));
189 DCHECK(!result); 227 DCHECK(!result);
190 user_data_ = NULL; 228 user_data_ = NULL;
191 } 229 }
192 230
193 PP_ManifestService manifest_service_; 231 PPP_ManifestService manifest_service_;
194 void* user_data_; 232 void* user_data_;
195 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); 233 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy);
196 }; 234 };
197 235
198 // Launch NaCl's sel_ldr process. 236 // Launch NaCl's sel_ldr process.
199 void LaunchSelLdr(PP_Instance instance, 237 void LaunchSelLdr(PP_Instance instance,
200 const char* alleged_url, 238 const char* alleged_url,
201 PP_Bool uses_irt, 239 PP_Bool uses_irt,
202 PP_Bool uses_ppapi, 240 PP_Bool uses_ppapi,
203 PP_Bool uses_nonsfi_mode, 241 PP_Bool uses_nonsfi_mode,
204 PP_Bool enable_ppapi_dev, 242 PP_Bool enable_ppapi_dev,
205 PP_Bool enable_dyncode_syscalls, 243 PP_Bool enable_dyncode_syscalls,
206 PP_Bool enable_exception_handling, 244 PP_Bool enable_exception_handling,
207 PP_Bool enable_crash_throttling, 245 PP_Bool enable_crash_throttling,
208 const PP_ManifestService* manifest_service_interface, 246 const PPP_ManifestService* manifest_service_interface,
209 void* manifest_service_user_data, 247 void* manifest_service_user_data,
210 void* imc_handle, 248 void* imc_handle,
211 struct PP_Var* error_message, 249 struct PP_Var* error_message,
212 PP_CompletionCallback callback) { 250 PP_CompletionCallback callback) {
213 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> 251 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->
214 BelongsToCurrentThread()); 252 BelongsToCurrentThread());
215 253
216 // Create the manifest service proxy here, so on error case, it will be 254 // Create the manifest service proxy here, so on error case, it will be
217 // destructed (without passing it to ManifestServiceChannel), and QUIT 255 // destructed (without passing it to ManifestServiceChannel), and QUIT
218 // will be called in its destructor so that the caller of this function 256 // will be called in its destructor so that the caller of this function
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 &ProcessNaClManifest 889 &ProcessNaClManifest
852 }; 890 };
853 891
854 } // namespace 892 } // namespace
855 893
856 const PPB_NaCl_Private* GetNaClPrivateInterface() { 894 const PPB_NaCl_Private* GetNaClPrivateInterface() {
857 return &nacl_interface; 895 return &nacl_interface;
858 } 896 }
859 897
860 } // namespace nacl 898 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698