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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc

Issue 264943003: Pepper: Move manifest logic to components/nacl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 6 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "native_client/src/include/checked_cast.h" 10 #include "native_client/src/include/checked_cast.h"
11 #include "native_client/src/include/portability_io.h" 11 #include "native_client/src/include/portability_io.h"
12 #include "native_client/src/shared/platform/nacl_check.h" 12 #include "native_client/src/shared/platform/nacl_check.h"
13 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" 13 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
14 14
15 #include "ppapi/c/pp_bool.h" 15 #include "ppapi/c/pp_bool.h"
16 #include "ppapi/c/pp_errors.h" 16 #include "ppapi/c/pp_errors.h"
17 #include "ppapi/c/private/ppb_uma_private.h" 17 #include "ppapi/c/private/ppb_uma_private.h"
18 18
19 #include "ppapi/native_client/src/trusted/plugin/manifest.h"
20 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 19 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
21 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" 20 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
22 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h" 21 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h"
23 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" 22 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h"
24 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h" 23 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h"
25 24
26 namespace plugin { 25 namespace plugin {
27 26
28 ////////////////////////////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////
29 // Pnacl-specific manifest support.
30 //////////////////////////////////////////////////////////////////////
31
32 // The PNaCl linker gets file descriptors via the service runtime's
33 // reverse service lookup. The reverse service lookup requires a manifest.
34 // Normally, that manifest is an NMF containing mappings for shared libraries.
35 // Here, we provide a manifest that redirects to PNaCl component files
36 // that are part of Chrome.
37 class PnaclManifest : public Manifest {
38 public:
39 PnaclManifest(const nacl::string& sandbox_arch)
40 : sandbox_arch_(sandbox_arch) { }
41
42 virtual ~PnaclManifest() { }
43
44 virtual bool GetProgramURL(nacl::string* full_url,
45 PP_PNaClOptions* pnacl_options,
46 bool* uses_nonsfi_mode,
47 ErrorInfo* error_info) const {
48 // Does not contain program urls.
49 UNREFERENCED_PARAMETER(full_url);
50 UNREFERENCED_PARAMETER(pnacl_options);
51 UNREFERENCED_PARAMETER(uses_nonsfi_mode);
52 UNREFERENCED_PARAMETER(error_info);
53 PLUGIN_PRINTF(("PnaclManifest does not contain a program\n"));
54 error_info->SetReport(PP_NACL_ERROR_MANIFEST_GET_NEXE_URL,
55 "pnacl manifest does not contain a program.");
56 return false;
57 }
58
59 virtual bool ResolveKey(const nacl::string& key,
60 nacl::string* full_url,
61 PP_PNaClOptions* pnacl_options) const {
62 // All of the component files are native (do not require pnacl translate).
63 pnacl_options->translate = PP_FALSE;
64 // We can only resolve keys in the files/ namespace.
65 const nacl::string kFilesPrefix = "files/";
66 size_t files_prefix_pos = key.find(kFilesPrefix);
67 if (files_prefix_pos == nacl::string::npos) {
68 PLUGIN_PRINTF(("key did not start with files/"));
69 return false;
70 }
71 // Resolve the full URL to the file. Provide it with a platform-specific
72 // prefix.
73 nacl::string key_basename = key.substr(kFilesPrefix.length());
74 *full_url = PnaclUrls::GetBaseUrl() + sandbox_arch_ + "/" + key_basename;
75 return true;
76 }
77
78 private:
79 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclManifest);
80
81 nacl::string sandbox_arch_;
82 };
83
84 //////////////////////////////////////////////////////////////////////
85 // UMA stat helpers. 28 // UMA stat helpers.
86 ////////////////////////////////////////////////////////////////////// 29 //////////////////////////////////////////////////////////////////////
87 30
88 namespace { 31 namespace {
89 32
90 // Assume translation time metrics *can be* large. 33 // Assume translation time metrics *can be* large.
91 // Up to 12 minutes. 34 // Up to 12 minutes.
92 const int64_t kTimeLargeMin = 10; // in ms 35 const int64_t kTimeLargeMin = 10; // in ms
93 const int64_t kTimeLargeMax = 720000; // in ms 36 const int64_t kTimeLargeMax = 720000; // in ms
94 const uint32_t kTimeLargeBuckets = 100; 37 const uint32_t kTimeLargeBuckets = 100;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 Plugin* plugin, 116 Plugin* plugin,
174 const nacl::string& pexe_url, 117 const nacl::string& pexe_url,
175 const PP_PNaClOptions& pnacl_options, 118 const PP_PNaClOptions& pnacl_options,
176 const pp::CompletionCallback& translate_notify_callback) { 119 const pp::CompletionCallback& translate_notify_callback) {
177 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", 120 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n",
178 static_cast<void*>(plugin), pexe_url.c_str())); 121 static_cast<void*>(plugin), pexe_url.c_str()));
179 PnaclCoordinator* coordinator = 122 PnaclCoordinator* coordinator =
180 new PnaclCoordinator(plugin, pexe_url, 123 new PnaclCoordinator(plugin, pexe_url,
181 pnacl_options, 124 pnacl_options,
182 translate_notify_callback); 125 translate_notify_callback);
126 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest_id=%d)\n",
127 coordinator->manifest_id_));
128
183 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); 129 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds();
184 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, ",
185 reinterpret_cast<const void*>(coordinator->manifest_.get())));
186
187 int cpus = plugin->nacl_interface()->GetNumberOfProcessors(); 130 int cpus = plugin->nacl_interface()->GetNumberOfProcessors();
188 coordinator->split_module_count_ = std::min(4, std::max(1, cpus)); 131 coordinator->split_module_count_ = std::min(4, std::max(1, cpus));
189 132
190 // First start a network request for the pexe, to tickle the component 133 // First start a network request for the pexe, to tickle the component
191 // updater's On-Demand resource throttler, and to get Last-Modified/ETag 134 // updater's On-Demand resource throttler, and to get Last-Modified/ETag
192 // cache information. We can cancel the request later if there's 135 // cache information. We can cancel the request later if there's
193 // a bitcode->nexe cache hit. 136 // a bitcode->nexe cache hit.
194 coordinator->OpenBitcodeStream(); 137 coordinator->OpenBitcodeStream();
195 return coordinator; 138 return coordinator;
196 } 139 }
197 140
198 PnaclCoordinator::PnaclCoordinator( 141 PnaclCoordinator::PnaclCoordinator(
199 Plugin* plugin, 142 Plugin* plugin,
200 const nacl::string& pexe_url, 143 const nacl::string& pexe_url,
201 const PP_PNaClOptions& pnacl_options, 144 const PP_PNaClOptions& pnacl_options,
202 const pp::CompletionCallback& translate_notify_callback) 145 const pp::CompletionCallback& translate_notify_callback)
203 : translate_finish_error_(PP_OK), 146 : translate_finish_error_(PP_OK),
204 plugin_(plugin), 147 plugin_(plugin),
205 translate_notify_callback_(translate_notify_callback), 148 translate_notify_callback_(translate_notify_callback),
206 translation_finished_reported_(false), 149 translation_finished_reported_(false),
207 manifest_(new PnaclManifest(plugin->nacl_interface()->GetSandboxArch())), 150 manifest_id_(
151 GetNaClInterface()->CreatePnaclManifest(plugin->pp_instance())),
208 pexe_url_(pexe_url), 152 pexe_url_(pexe_url),
209 pnacl_options_(pnacl_options), 153 pnacl_options_(pnacl_options),
210 split_module_count_(1), 154 split_module_count_(1),
211 num_object_files_opened_(0), 155 num_object_files_opened_(0),
212 is_cache_hit_(PP_FALSE), 156 is_cache_hit_(PP_FALSE),
213 error_already_reported_(false), 157 error_already_reported_(false),
214 pnacl_init_time_(0), 158 pnacl_init_time_(0),
215 pexe_size_(0), 159 pexe_size_(0),
216 pexe_bytes_compiled_(0), 160 pexe_bytes_compiled_(0),
217 expected_pexe_size_(-1) { 161 expected_pexe_size_(-1) {
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 605 void PnaclCoordinator::RunTranslate(int32_t pp_error) {
662 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 606 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%"
663 NACL_PRId32 ")\n", pp_error)); 607 NACL_PRId32 ")\n", pp_error));
664 // Invoke llc followed by ld off the main thread. This allows use of 608 // Invoke llc followed by ld off the main thread. This allows use of
665 // blocking RPCs that would otherwise block the JavaScript main thread. 609 // blocking RPCs that would otherwise block the JavaScript main thread.
666 pp::CompletionCallback report_translate_finished = 610 pp::CompletionCallback report_translate_finished =
667 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 611 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
668 612
669 CHECK(translate_thread_ != NULL); 613 CHECK(translate_thread_ != NULL);
670 translate_thread_->RunTranslate(report_translate_finished, 614 translate_thread_->RunTranslate(report_translate_finished,
671 manifest_.get(), 615 manifest_id_,
672 &obj_files_, 616 &obj_files_,
673 temp_nexe_file_.get(), 617 temp_nexe_file_.get(),
674 invalid_desc_wrapper_.get(), 618 invalid_desc_wrapper_.get(),
675 &error_info_, 619 &error_info_,
676 resources_.get(), 620 resources_.get(),
677 &pnacl_options_, 621 &pnacl_options_,
678 this, 622 this,
679 plugin_); 623 plugin_);
680 } 624 }
681 625
682 } // namespace plugin 626 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h ('k') | ppapi/native_client/src/trusted/plugin/pnacl_resources.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698