OLD | NEW |
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 <numeric> | 7 #include <numeric> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/containers/scoped_ptr_hash_map.h" | 14 #include "base/containers/scoped_ptr_hash_map.h" |
15 #include "base/cpu.h" | 15 #include "base/cpu.h" |
| 16 #include "base/files/file.h" |
16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
19 #include "components/nacl/common/nacl_host_messages.h" | 20 #include "components/nacl/common/nacl_host_messages.h" |
20 #include "components/nacl/common/nacl_messages.h" | 21 #include "components/nacl/common/nacl_messages.h" |
21 #include "components/nacl/common/nacl_nonsfi_util.h" | 22 #include "components/nacl/common/nacl_nonsfi_util.h" |
22 #include "components/nacl/common/nacl_switches.h" | 23 #include "components/nacl/common/nacl_switches.h" |
23 #include "components/nacl/common/nacl_types.h" | 24 #include "components/nacl/common/nacl_types.h" |
24 #include "components/nacl/renderer/file_downloader.h" | 25 #include "components/nacl/renderer/file_downloader.h" |
25 #include "components/nacl/renderer/histogram.h" | 26 #include "components/nacl/renderer/histogram.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 std::string url; | 205 std::string url; |
205 // TODO(teravest): Clean up pnacl_options logic in JsonManifest so we don't | 206 // TODO(teravest): Clean up pnacl_options logic in JsonManifest so we don't |
206 // have to initialize it like this here. | 207 // have to initialize it like this here. |
207 PP_PNaClOptions pnacl_options; | 208 PP_PNaClOptions pnacl_options; |
208 pnacl_options.translate = PP_FALSE; | 209 pnacl_options.translate = PP_FALSE; |
209 pnacl_options.is_debug = PP_FALSE; | 210 pnacl_options.is_debug = PP_FALSE; |
210 pnacl_options.opt_level = 2; | 211 pnacl_options.opt_level = 2; |
211 if (!ManifestResolveKey(pp_instance_, false, key, &url, &pnacl_options)) { | 212 if (!ManifestResolveKey(pp_instance_, false, key, &url, &pnacl_options)) { |
212 base::MessageLoop::current()->PostTask( | 213 base::MessageLoop::current()->PostTask( |
213 FROM_HERE, | 214 FROM_HERE, |
214 base::Bind(callback, PP_kInvalidFileHandle)); | 215 base::Bind(callback, base::Passed(base::File()))); |
215 return; | 216 return; |
216 } | 217 } |
217 | 218 |
218 // We have to call DidDownloadFile, even if this object is destroyed, so | 219 // We have to call DidDownloadFile, even if this object is destroyed, so |
219 // that the handle inside PP_NaClFileInfo isn't leaked. This means that the | 220 // that the handle inside PP_NaClFileInfo isn't leaked. This means that the |
220 // callback passed to this function shouldn't have a weak pointer to an | 221 // callback passed to this function shouldn't have a weak pointer to an |
221 // object either. | 222 // object either. |
222 // | 223 // |
223 // TODO(teravest): Make a type like PP_NaClFileInfo to use for DownloadFile | 224 // TODO(teravest): Make a type like PP_NaClFileInfo to use for DownloadFile |
224 // that would close the file handle on destruction. | 225 // that would close the file handle on destruction. |
225 DownloadFile(pp_instance_, url.c_str(), | 226 DownloadFile(pp_instance_, url.c_str(), |
226 base::Bind(&ManifestServiceProxy::DidDownloadFile, callback)); | 227 base::Bind(&ManifestServiceProxy::DidDownloadFile, callback)); |
227 } | 228 } |
228 | 229 |
229 private: | 230 private: |
230 static void DidDownloadFile( | 231 static void DidDownloadFile( |
231 ManifestServiceChannel::OpenResourceCallback callback, | 232 ManifestServiceChannel::OpenResourceCallback callback, |
232 int32_t pp_error, | 233 int32_t pp_error, |
233 const PP_NaClFileInfo& file_info) { | 234 const PP_NaClFileInfo& file_info) { |
234 if (pp_error != PP_OK) { | 235 if (pp_error != PP_OK) { |
235 callback.Run(base::kInvalidPlatformFileValue); | 236 callback.Run(base::File()); |
236 return; | 237 return; |
237 } | 238 } |
238 callback.Run(file_info.handle); | 239 callback.Run(base::File(file_info.handle)); |
239 } | 240 } |
240 | 241 |
241 void Quit() { | 242 void Quit() { |
242 if (!user_data_) | 243 if (!user_data_) |
243 return; | 244 return; |
244 | 245 |
245 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); | 246 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); |
246 DCHECK(!result); | 247 DCHECK(!result); |
247 user_data_ = NULL; | 248 user_data_ = NULL; |
248 } | 249 } |
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 &LogTranslateTime | 1635 &LogTranslateTime |
1635 }; | 1636 }; |
1636 | 1637 |
1637 } // namespace | 1638 } // namespace |
1638 | 1639 |
1639 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1640 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1640 return &nacl_interface; | 1641 return &nacl_interface; |
1641 } | 1642 } |
1642 | 1643 |
1643 } // namespace nacl | 1644 } // namespace nacl |
OLD | NEW |