OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/nexe_load_manager.h" | 5 #include "components/nacl/renderer/nexe_load_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_tokenizer.h" | 12 #include "base/strings/string_tokenizer.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "components/nacl/common/nacl_host_messages.h" | 14 #include "components/nacl/common/nacl_host_messages.h" |
13 #include "components/nacl/common/nacl_types.h" | 15 #include "components/nacl/common/nacl_types.h" |
14 #include "components/nacl/renderer/histogram.h" | 16 #include "components/nacl/renderer/histogram.h" |
15 #include "components/nacl/renderer/manifest_service_channel.h" | 17 #include "components/nacl/renderer/manifest_service_channel.h" |
16 #include "components/nacl/renderer/platform_info.h" | 18 #include "components/nacl/renderer/platform_info.h" |
17 #include "components/nacl/renderer/pnacl_translation_resource_host.h" | 19 #include "components/nacl/renderer/pnacl_translation_resource_host.h" |
(...skipping 14 matching lines...) Expand all Loading... |
32 #include "ppapi/shared_impl/scoped_pp_var.h" | 34 #include "ppapi/shared_impl/scoped_pp_var.h" |
33 #include "ppapi/shared_impl/var.h" | 35 #include "ppapi/shared_impl/var.h" |
34 #include "ppapi/shared_impl/var_tracker.h" | 36 #include "ppapi/shared_impl/var_tracker.h" |
35 #include "ppapi/thunk/enter.h" | 37 #include "ppapi/thunk/enter.h" |
36 #include "third_party/WebKit/public/web/WebDocument.h" | 38 #include "third_party/WebKit/public/web/WebDocument.h" |
37 #include "third_party/WebKit/public/web/WebElement.h" | 39 #include "third_party/WebKit/public/web/WebElement.h" |
38 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 40 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
39 #include "third_party/WebKit/public/web/WebView.h" | 41 #include "third_party/WebKit/public/web/WebView.h" |
40 #include "v8/include/v8.h" | 42 #include "v8/include/v8.h" |
41 | 43 |
| 44 namespace nacl { |
| 45 |
42 namespace { | 46 namespace { |
43 | 47 |
44 const char* const kTypeAttribute = "type"; | 48 const char* const kTypeAttribute = "type"; |
45 // The "src" attribute of the <embed> tag. The value is expected to be either | 49 // The "src" attribute of the <embed> tag. The value is expected to be either |
46 // a URL or URI pointing to the manifest file (which is expected to contain | 50 // a URL or URI pointing to the manifest file (which is expected to contain |
47 // JSON matching ISAs with .nexe URLs). | 51 // JSON matching ISAs with .nexe URLs). |
48 const char* const kSrcManifestAttribute = "src"; | 52 const char* const kSrcManifestAttribute = "src"; |
49 // The "nacl" attribute of the <embed> tag. We use the value of this attribute | 53 // The "nacl" attribute of the <embed> tag. We use the value of this attribute |
50 // to find the manifest file when NaCl is registered as a plug-in for another | 54 // to find the manifest file when NaCl is registered as a plug-in for another |
51 // MIME type because the "src" attribute is used to supply us with the resource | 55 // MIME type because the "src" attribute is used to supply us with the resource |
(...skipping 17 matching lines...) Expand all Loading... |
69 } | 73 } |
70 | 74 |
71 std::string LookupAttribute(const std::map<std::string, std::string>& args, | 75 std::string LookupAttribute(const std::map<std::string, std::string>& args, |
72 const std::string& key) { | 76 const std::string& key) { |
73 std::map<std::string, std::string>::const_iterator it = args.find(key); | 77 std::map<std::string, std::string>::const_iterator it = args.find(key); |
74 if (it != args.end()) | 78 if (it != args.end()) |
75 return it->second; | 79 return it->second; |
76 return std::string(); | 80 return std::string(); |
77 } | 81 } |
78 | 82 |
| 83 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> NexeLoadManagerMap; |
| 84 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = |
| 85 LAZY_INSTANCE_INITIALIZER; |
| 86 |
79 } // namespace | 87 } // namespace |
80 | 88 |
81 namespace nacl { | |
82 | |
83 NexeLoadManager::NexeLoadManager( | 89 NexeLoadManager::NexeLoadManager( |
84 PP_Instance pp_instance) | 90 PP_Instance pp_instance) |
85 : pp_instance_(pp_instance), | 91 : pp_instance_(pp_instance), |
86 nacl_ready_state_(PP_NACL_READY_STATE_UNSENT), | 92 nacl_ready_state_(PP_NACL_READY_STATE_UNSENT), |
87 nexe_error_reported_(false), | 93 nexe_error_reported_(false), |
88 is_installed_(false), | 94 is_installed_(false), |
89 exit_status_(-1), | 95 exit_status_(-1), |
90 nexe_size_(0), | 96 nexe_size_(0), |
91 plugin_instance_(content::PepperPluginInstance::Get(pp_instance)), | 97 plugin_instance_(content::PepperPluginInstance::Get(pp_instance)), |
92 crash_info_shmem_handle_(base::SharedMemory::NULLHandle()), | 98 crash_info_shmem_handle_(base::SharedMemory::NULLHandle()), |
93 weak_factory_(this) { | 99 weak_factory_(this) { |
94 SetLastError(""); | 100 SetLastError(""); |
95 HistogramEnumerateOsArch(GetSandboxArch()); | 101 HistogramEnumerateOsArch(GetSandboxArch()); |
96 if (plugin_instance_) { | 102 if (plugin_instance_) { |
97 plugin_base_url_ = | 103 plugin_base_url_ = |
98 plugin_instance_->GetContainer()->element().document().url(); | 104 plugin_instance_->GetContainer()->element().document().url(); |
99 } | 105 } |
100 } | 106 } |
101 | 107 |
102 NexeLoadManager::~NexeLoadManager() { | 108 NexeLoadManager::~NexeLoadManager() { |
103 if (!nexe_error_reported_) { | 109 if (!nexe_error_reported_) { |
104 base::TimeDelta uptime = base::Time::Now() - ready_time_; | 110 base::TimeDelta uptime = base::Time::Now() - ready_time_; |
105 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds()); | 111 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds()); |
106 } | 112 } |
107 if (base::SharedMemory::IsHandleValid(crash_info_shmem_handle_)) | 113 if (base::SharedMemory::IsHandleValid(crash_info_shmem_handle_)) |
108 base::SharedMemory::CloseHandle(crash_info_shmem_handle_); | 114 base::SharedMemory::CloseHandle(crash_info_shmem_handle_); |
109 } | 115 } |
110 | 116 |
| 117 void NexeLoadManager::Create(PP_Instance instance) { |
| 118 scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance)); |
| 119 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
| 120 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; |
| 121 map.add(instance, new_load_manager.Pass()); |
| 122 } |
| 123 |
| 124 NexeLoadManager* NexeLoadManager::Get(PP_Instance instance) { |
| 125 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
| 126 NexeLoadManagerMap::iterator iter = map.find(instance); |
| 127 if (iter != map.end()) |
| 128 return iter->second; |
| 129 return NULL; |
| 130 } |
| 131 |
| 132 void NexeLoadManager::Delete(PP_Instance instance) { |
| 133 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
| 134 // The erase may call NexeLoadManager's destructor prior to removing it from |
| 135 // the map. In that case, it is possible for the trusted Plugin to re-enter |
| 136 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the |
| 137 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone |
| 138 // from the map prior to the destructor being invoked. |
| 139 scoped_ptr<NexeLoadManager> temp(map.take(instance)); |
| 140 map.erase(instance); |
| 141 } |
| 142 |
111 void NexeLoadManager::NexeFileDidOpen(int32_t pp_error, | 143 void NexeLoadManager::NexeFileDidOpen(int32_t pp_error, |
112 const base::File& file, | 144 const base::File& file, |
113 int32_t http_status, | 145 int32_t http_status, |
114 int64_t nexe_bytes_read, | 146 int64_t nexe_bytes_read, |
115 const std::string& url, | 147 const std::string& url, |
116 base::TimeDelta time_since_open) { | 148 base::TimeDelta time_since_open) { |
117 // Check that we are on the main renderer thread. | 149 // Check that we are on the main renderer thread. |
118 DCHECK(content::RenderThread::Get()); | 150 DCHECK(content::RenderThread::Get()); |
119 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")"; | 151 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")"; |
120 HistogramHTTPStatusCode( | 152 HistogramHTTPStatusCode( |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // to provide error handling. | 468 // to provide error handling. |
437 } | 469 } |
438 | 470 |
439 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { | 471 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { |
440 base::StringTokenizer t(crash_log, "\n"); | 472 base::StringTokenizer t(crash_log, "\n"); |
441 while (t.GetNext()) | 473 while (t.GetNext()) |
442 LogToConsole(t.token()); | 474 LogToConsole(t.token()); |
443 } | 475 } |
444 | 476 |
445 } // namespace nacl | 477 } // namespace nacl |
OLD | NEW |