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

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

Issue 2605463002: Remove base::ScopedPtrHashMap from components/nacl/. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "components/nacl/renderer/ppb_nacl_private.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <numeric> 11 #include <numeric>
12 #include <string> 12 #include <string>
13 #include <unordered_map>
13 #include <utility> 14 #include <utility>
14 #include <vector> 15 #include <vector>
15 16
16 #include "base/bind.h" 17 #include "base/bind.h"
17 #include "base/bind_helpers.h" 18 #include "base/bind_helpers.h"
18 #include "base/command_line.h" 19 #include "base/command_line.h"
19 #include "base/containers/scoped_ptr_hash_map.h"
20 #include "base/cpu.h" 20 #include "base/cpu.h"
21 #include "base/files/file.h" 21 #include "base/files/file.h"
22 #include "base/json/json_reader.h" 22 #include "base/json/json_reader.h"
23 #include "base/lazy_instance.h" 23 #include "base/lazy_instance.h"
24 #include "base/location.h" 24 #include "base/location.h"
25 #include "base/logging.h" 25 #include "base/logging.h"
26 #include "base/macros.h" 26 #include "base/macros.h"
27 #include "base/process/process_handle.h" 27 #include "base/process/process_handle.h"
28 #include "base/single_thread_task_runner.h" 28 #include "base/single_thread_task_runner.h"
29 #include "base/strings/string_split.h" 29 #include "base/strings/string_split.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 NexeLoadManager nexe_load_manager; 142 NexeLoadManager nexe_load_manager;
143 std::unique_ptr<JsonManifest> json_manifest; 143 std::unique_ptr<JsonManifest> json_manifest;
144 std::unique_ptr<InstanceInfo> instance_info; 144 std::unique_ptr<InstanceInfo> instance_info;
145 145
146 // When translation is complete, this records the size of the pexe in 146 // When translation is complete, this records the size of the pexe in
147 // bytes so that it can be reported in a later load event. 147 // bytes so that it can be reported in a later load event.
148 uint64_t pexe_size; 148 uint64_t pexe_size;
149 }; 149 };
150 150
151 typedef base::ScopedPtrHashMap<PP_Instance, std::unique_ptr<NaClPluginInstance>> 151 typedef std::unordered_map<PP_Instance, std::unique_ptr<NaClPluginInstance>>
152 InstanceMap; 152 InstanceMap;
153 base::LazyInstance<InstanceMap> g_instance_map = LAZY_INSTANCE_INITIALIZER; 153 base::LazyInstance<InstanceMap> g_instance_map = LAZY_INSTANCE_INITIALIZER;
154 154
155 NaClPluginInstance* GetNaClPluginInstance(PP_Instance instance) { 155 NaClPluginInstance* GetNaClPluginInstance(PP_Instance instance) {
156 InstanceMap& map = g_instance_map.Get(); 156 InstanceMap& map = g_instance_map.Get();
157 InstanceMap::iterator iter = map.find(instance); 157 auto iter = map.find(instance);
158 if (iter == map.end()) 158 if (iter == map.end())
159 return NULL; 159 return NULL;
160 return iter->second; 160 return iter->second.get();
161 } 161 }
162 162
163 NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { 163 NexeLoadManager* GetNexeLoadManager(PP_Instance instance) {
164 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance); 164 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance);
165 if (!nacl_plugin_instance) 165 if (!nacl_plugin_instance)
166 return NULL; 166 return NULL;
167 return &nacl_plugin_instance->nexe_load_manager; 167 return &nacl_plugin_instance->nexe_load_manager;
168 } 168 }
169 169
170 JsonManifest* GetJsonManifest(PP_Instance instance) { 170 JsonManifest* GetJsonManifest(PP_Instance instance) {
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 PP_NaClError error, 860 PP_NaClError error,
861 const char* error_message) { 861 const char* error_message) {
862 NexeLoadManager* load_manager = GetNexeLoadManager(instance); 862 NexeLoadManager* load_manager = GetNexeLoadManager(instance);
863 if (load_manager) 863 if (load_manager)
864 load_manager->ReportLoadError(error, error_message); 864 load_manager->ReportLoadError(error, error_message);
865 } 865 }
866 866
867 // static 867 // static
868 void PPBNaClPrivate::InstanceCreated(PP_Instance instance) { 868 void PPBNaClPrivate::InstanceCreated(PP_Instance instance) {
869 InstanceMap& map = g_instance_map.Get(); 869 InstanceMap& map = g_instance_map.Get();
870 CHECK(!ContainsKey(map, instance)); // Sanity check. 870 CHECK(map.find(instance) == map.end()); // Sanity check.
871 std::unique_ptr<NaClPluginInstance> new_instance( 871 std::unique_ptr<NaClPluginInstance> new_instance(
872 new NaClPluginInstance(instance)); 872 new NaClPluginInstance(instance));
873 map.add(instance, std::move(new_instance)); 873 map[instance] = std::move(new_instance);
874 } 874 }
875 875
876 // static 876 // static
877 void PPBNaClPrivate::InstanceDestroyed(PP_Instance instance) { 877 void PPBNaClPrivate::InstanceDestroyed(PP_Instance instance) {
878 InstanceMap& map = g_instance_map.Get(); 878 InstanceMap& map = g_instance_map.Get();
879 InstanceMap::iterator iter = map.find(instance); 879 auto iter = map.find(instance);
880 CHECK(iter != map.end()); 880 CHECK(iter != map.end());
881 // The erase may call NexeLoadManager's destructor prior to removing it from 881 // The erase may call NexeLoadManager's destructor prior to removing it from
882 // the map. In that case, it is possible for the trusted Plugin to re-enter 882 // the map. In that case, it is possible for the trusted Plugin to re-enter
883 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the 883 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the
884 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone 884 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone
885 // from the map prior to the destructor being invoked. 885 // from the map prior to the destructor being invoked.
886 std::unique_ptr<NaClPluginInstance> temp(map.take(instance)); 886 std::unique_ptr<NaClPluginInstance> temp = std::move(iter->second);
887 map.erase(iter); 887 map.erase(iter);
888 } 888 }
889 889
890 // static 890 // static
891 void PPBNaClPrivate::TerminateNaClLoader(PP_Instance instance) { 891 void PPBNaClPrivate::TerminateNaClLoader(PP_Instance instance) {
892 auto* load_mgr = GetNexeLoadManager(instance); 892 auto* load_mgr = GetNexeLoadManager(instance);
893 if (load_mgr) 893 if (load_mgr)
894 load_mgr->CloseTrustedPluginChannel(); 894 load_mgr->CloseTrustedPluginChannel();
895 } 895 }
896 896
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 // Mark the request as requesting a PNaCl bitcode file, 1737 // Mark the request as requesting a PNaCl bitcode file,
1738 // so that component updater can detect this user action. 1738 // so that component updater can detect this user action.
1739 url_request.addHTTPHeaderField( 1739 url_request.addHTTPHeaderField(
1740 blink::WebString::fromUTF8("Accept"), 1740 blink::WebString::fromUTF8("Accept"),
1741 blink::WebString::fromUTF8("application/x-pnacl, */*")); 1741 blink::WebString::fromUTF8("application/x-pnacl, */*"));
1742 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); 1742 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject);
1743 downloader->Load(url_request); 1743 downloader->Load(url_request);
1744 } 1744 }
1745 1745
1746 } // namespace nacl 1746 } // namespace nacl
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698