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

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

Issue 484303002: Pepper: Move NexeLoadManager map inside that class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 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
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
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 weak_factory_(this) { 98 weak_factory_(this) {
93 SetLastError(""); 99 SetLastError("");
94 HistogramEnumerateOsArch(GetSandboxArch()); 100 HistogramEnumerateOsArch(GetSandboxArch());
95 if (plugin_instance_) { 101 if (plugin_instance_) {
96 plugin_base_url_ = 102 plugin_base_url_ =
97 plugin_instance_->GetContainer()->element().document().url(); 103 plugin_instance_->GetContainer()->element().document().url();
98 } 104 }
99 } 105 }
100 106
101 NexeLoadManager::~NexeLoadManager() { 107 NexeLoadManager::~NexeLoadManager() {
102 if (!nexe_error_reported_) { 108 if (!nexe_error_reported_) {
103 base::TimeDelta uptime = base::Time::Now() - ready_time_; 109 base::TimeDelta uptime = base::Time::Now() - ready_time_;
104 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds()); 110 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds());
105 } 111 }
106 } 112 }
107 113
114 void NexeLoadManager::Create(PP_Instance instance) {
115 scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance));
116 NexeLoadManagerMap& map = g_load_manager_map.Get();
117 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0";
118 map.add(instance, new_load_manager.Pass());
119 }
120
121 NexeLoadManager* NexeLoadManager::Get(PP_Instance instance) {
122 NexeLoadManagerMap& map = g_load_manager_map.Get();
123 NexeLoadManagerMap::iterator iter = map.find(instance);
124 if (iter != map.end())
125 return iter->second;
126 return NULL;
127 }
128
129 void NexeLoadManager::Delete(PP_Instance instance) {
130 NexeLoadManagerMap& map = g_load_manager_map.Get();
131 scoped_ptr<NexeLoadManager> temp(map.take(instance));
dmichael (off chromium) 2014/08/20 21:03:56 we lost the comment here about deleting it before
teravest 2014/08/20 21:08:15 Okay, I've added it back.
132 map.erase(instance);
133 }
134
108 void NexeLoadManager::NexeFileDidOpen(int32_t pp_error, 135 void NexeLoadManager::NexeFileDidOpen(int32_t pp_error,
109 const base::File& file, 136 const base::File& file,
110 int32_t http_status, 137 int32_t http_status,
111 int64_t nexe_bytes_read, 138 int64_t nexe_bytes_read,
112 const std::string& url, 139 const std::string& url,
113 base::TimeDelta time_since_open) { 140 base::TimeDelta time_since_open) {
114 // Check that we are on the main renderer thread. 141 // Check that we are on the main renderer thread.
115 DCHECK(content::RenderThread::Get()); 142 DCHECK(content::RenderThread::Get());
116 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")"; 143 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")";
117 HistogramHTTPStatusCode( 144 HistogramHTTPStatusCode(
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // to provide error handling. 444 // to provide error handling.
418 } 445 }
419 446
420 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { 447 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) {
421 base::StringTokenizer t(crash_log, "\n"); 448 base::StringTokenizer t(crash_log, "\n");
422 while (t.GetNext()) 449 while (t.GetNext())
423 LogToConsole(t.token()); 450 LogToConsole(t.token());
424 } 451 }
425 452
426 } // namespace nacl 453 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/renderer/nexe_load_manager.h ('k') | components/nacl/renderer/ppb_nacl_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698