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" | |
10 #include "base/logging.h" | 8 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
12 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
13 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
14 #include "components/nacl/common/nacl_host_messages.h" | 12 #include "components/nacl/common/nacl_host_messages.h" |
15 #include "components/nacl/common/nacl_types.h" | 13 #include "components/nacl/common/nacl_types.h" |
16 #include "components/nacl/renderer/histogram.h" | 14 #include "components/nacl/renderer/histogram.h" |
17 #include "components/nacl/renderer/manifest_service_channel.h" | 15 #include "components/nacl/renderer/manifest_service_channel.h" |
18 #include "components/nacl/renderer/platform_info.h" | 16 #include "components/nacl/renderer/platform_info.h" |
19 #include "components/nacl/renderer/pnacl_translation_resource_host.h" | 17 #include "components/nacl/renderer/pnacl_translation_resource_host.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 71 } |
74 | 72 |
75 std::string LookupAttribute(const std::map<std::string, std::string>& args, | 73 std::string LookupAttribute(const std::map<std::string, std::string>& args, |
76 const std::string& key) { | 74 const std::string& key) { |
77 std::map<std::string, std::string>::const_iterator it = args.find(key); | 75 std::map<std::string, std::string>::const_iterator it = args.find(key); |
78 if (it != args.end()) | 76 if (it != args.end()) |
79 return it->second; | 77 return it->second; |
80 return std::string(); | 78 return std::string(); |
81 } | 79 } |
82 | 80 |
83 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> NexeLoadManagerMap; | |
84 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = | |
85 LAZY_INSTANCE_INITIALIZER; | |
86 | |
87 } // namespace | 81 } // namespace |
88 | 82 |
89 NexeLoadManager::NexeLoadManager( | 83 NexeLoadManager::NexeLoadManager( |
90 PP_Instance pp_instance) | 84 PP_Instance pp_instance) |
91 : pp_instance_(pp_instance), | 85 : pp_instance_(pp_instance), |
92 nacl_ready_state_(PP_NACL_READY_STATE_UNSENT), | 86 nacl_ready_state_(PP_NACL_READY_STATE_UNSENT), |
93 nexe_error_reported_(false), | 87 nexe_error_reported_(false), |
94 is_installed_(false), | 88 is_installed_(false), |
95 exit_status_(-1), | 89 exit_status_(-1), |
96 nexe_size_(0), | 90 nexe_size_(0), |
(...skipping 12 matching lines...) Expand all Loading... |
109 | 103 |
110 NexeLoadManager::~NexeLoadManager() { | 104 NexeLoadManager::~NexeLoadManager() { |
111 if (!nexe_error_reported_) { | 105 if (!nexe_error_reported_) { |
112 base::TimeDelta uptime = base::Time::Now() - ready_time_; | 106 base::TimeDelta uptime = base::Time::Now() - ready_time_; |
113 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds()); | 107 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds()); |
114 } | 108 } |
115 if (base::SharedMemory::IsHandleValid(crash_info_shmem_handle_)) | 109 if (base::SharedMemory::IsHandleValid(crash_info_shmem_handle_)) |
116 base::SharedMemory::CloseHandle(crash_info_shmem_handle_); | 110 base::SharedMemory::CloseHandle(crash_info_shmem_handle_); |
117 } | 111 } |
118 | 112 |
119 void NexeLoadManager::Create(PP_Instance instance) { | |
120 scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance)); | |
121 NexeLoadManagerMap& map = g_load_manager_map.Get(); | |
122 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; | |
123 map.add(instance, new_load_manager.Pass()); | |
124 } | |
125 | |
126 NexeLoadManager* NexeLoadManager::Get(PP_Instance instance) { | |
127 NexeLoadManagerMap& map = g_load_manager_map.Get(); | |
128 NexeLoadManagerMap::iterator iter = map.find(instance); | |
129 if (iter != map.end()) | |
130 return iter->second; | |
131 return NULL; | |
132 } | |
133 | |
134 void NexeLoadManager::Delete(PP_Instance instance) { | |
135 NexeLoadManagerMap& map = g_load_manager_map.Get(); | |
136 // The erase may call NexeLoadManager's destructor prior to removing it from | |
137 // the map. In that case, it is possible for the trusted Plugin to re-enter | |
138 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the | |
139 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone | |
140 // from the map prior to the destructor being invoked. | |
141 scoped_ptr<NexeLoadManager> temp(map.take(instance)); | |
142 map.erase(instance); | |
143 } | |
144 | |
145 void NexeLoadManager::NexeFileDidOpen(int32_t pp_error, | 113 void NexeLoadManager::NexeFileDidOpen(int32_t pp_error, |
146 const base::File& file, | 114 const base::File& file, |
147 int32_t http_status, | 115 int32_t http_status, |
148 int64_t nexe_bytes_read, | 116 int64_t nexe_bytes_read, |
149 const std::string& url, | 117 const std::string& url, |
150 base::TimeDelta time_since_open) { | 118 base::TimeDelta time_since_open) { |
151 // Check that we are on the main renderer thread. | 119 // Check that we are on the main renderer thread. |
152 DCHECK(content::RenderThread::Get()); | 120 DCHECK(content::RenderThread::Get()); |
153 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")"; | 121 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")"; |
154 HistogramHTTPStatusCode( | 122 HistogramHTTPStatusCode( |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 // to provide error handling. | 438 // to provide error handling. |
471 } | 439 } |
472 | 440 |
473 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { | 441 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { |
474 base::StringTokenizer t(crash_log, "\n"); | 442 base::StringTokenizer t(crash_log, "\n"); |
475 while (t.GetNext()) | 443 while (t.GetNext()) |
476 LogToConsole(t.token()); | 444 LogToConsole(t.token()); |
477 } | 445 } |
478 | 446 |
479 } // namespace nacl | 447 } // namespace nacl |
OLD | NEW |