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

Unified Diff: extensions/renderer/resource_bundle_source_map.cc

Issue 1880473003: Make ModuleSystem have a const view of ResourceBundleSourceMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove double lookups Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/resource_bundle_source_map.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/resource_bundle_source_map.cc
diff --git a/extensions/renderer/resource_bundle_source_map.cc b/extensions/renderer/resource_bundle_source_map.cc
index 88fc5372185d0ebd511fc7c8cd716914701480e3..a260b543f341693e63358994f4cb13e95b88582d 100644
--- a/extensions/renderer/resource_bundle_source_map.cc
+++ b/extensions/renderer/resource_bundle_source_map.cc
@@ -5,10 +5,24 @@
#include "extensions/renderer/resource_bundle_source_map.h"
#include "base/logging.h"
+#include "base/strings/string_piece.h"
+#include "extensions/renderer/static_v8_external_one_byte_string_resource.h"
#include "ui/base/resource/resource_bundle.h"
namespace extensions {
+namespace {
+
+v8::Local<v8::String> ConvertString(v8::Isolate* isolate,
+ const base::StringPiece& string) {
+ // v8 takes ownership of the StaticV8ExternalOneByteStringResource (see
+ // v8::String::NewExternal()).
+ return v8::String::NewExternal(
+ isolate, new StaticV8ExternalOneByteStringResource(string));
+}
+
+} // namespace
+
ResourceBundleSourceMap::ResourceBundleSourceMap(
const ui::ResourceBundle* resource_bundle)
: resource_bundle_(resource_bundle) {
@@ -24,13 +38,14 @@ void ResourceBundleSourceMap::RegisterSource(const std::string& name,
v8::Local<v8::Value> ResourceBundleSourceMap::GetSource(
v8::Isolate* isolate,
- const std::string& name) {
- if (!Contains(name)) {
+ const std::string& name) const {
+ const auto& resource_id_iter = resource_id_map_.find(name);
+ if (resource_id_iter == resource_id_map_.end()) {
NOTREACHED() << "No module is registered with name \"" << name << "\"";
return v8::Undefined(isolate);
}
base::StringPiece resource =
- resource_bundle_->GetRawDataResource(resource_id_map_[name]);
+ resource_bundle_->GetRawDataResource(resource_id_iter->second);
if (resource.empty()) {
NOTREACHED()
<< "Module resource registered as \"" << name << "\" not found";
@@ -39,17 +54,8 @@ v8::Local<v8::Value> ResourceBundleSourceMap::GetSource(
return ConvertString(isolate, resource);
}
-bool ResourceBundleSourceMap::Contains(const std::string& name) {
+bool ResourceBundleSourceMap::Contains(const std::string& name) const {
return !!resource_id_map_.count(name);
}
-v8::Local<v8::String> ResourceBundleSourceMap::ConvertString(
- v8::Isolate* isolate,
- const base::StringPiece& string) {
- // v8 takes ownership of the StaticV8ExternalOneByteStringResource (see
- // v8::String::NewExternal()).
- return v8::String::NewExternal(
- isolate, new StaticV8ExternalOneByteStringResource(string));
-}
-
} // namespace extensions
« no previous file with comments | « extensions/renderer/resource_bundle_source_map.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698