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

Unified Diff: chrome/renderer/extensions/v8_schema_registry.cc

Issue 9616055: Make a process-wide cache for the v8::Value representation of extension APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, go back to old method Created 8 years, 9 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 | « chrome/renderer/extensions/v8_schema_registry.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/v8_schema_registry.cc
diff --git a/chrome/renderer/extensions/v8_schema_registry.cc b/chrome/renderer/extensions/v8_schema_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35a22b29365d1ef7f07d65621d993df4427e0045
--- /dev/null
+++ b/chrome/renderer/extensions/v8_schema_registry.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/extensions/v8_schema_registry.h"
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "chrome/common/extensions/api/extension_api.h"
+#include "content/public/renderer/v8_value_converter.h"
+
+using content::V8ValueConverter;
+
+namespace extensions {
+
+V8SchemaRegistry::V8SchemaRegistry() : context_(v8::Context::New()) {}
+
+V8SchemaRegistry::~V8SchemaRegistry() {
+ for (SchemaCache::iterator i = schema_cache_.begin();
+ i != schema_cache_.end(); ++i) {
+ i->second.Dispose();
+ }
+ context_.Dispose();
+}
+
+v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas(
+ const std::set<std::string>& apis) {
+ v8::Context::Scope context_scope(context_);
+ v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size()));
+ size_t api_index = 0;
+ for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end();
+ ++i) {
+ v8_apis->Set(api_index++, GetSchema(*i));
+ }
+ return v8_apis;
+}
+
+v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) {
+ SchemaCache::iterator maybe_schema = schema_cache_.find(api);
+ if (maybe_schema != schema_cache_.end())
+ return maybe_schema->second;
+
+ const base::DictionaryValue* schema =
+ ExtensionAPI::GetInstance()->GetSchema(api);
+ CHECK(schema) << api;
+
+ scoped_ptr<V8ValueConverter> v8_value_converter(V8ValueConverter::create());
+ v8::Persistent<v8::Object> v8_schema =
+ v8::Persistent<v8::Object>::New(v8::Handle<v8::Object>::Cast(
+ v8_value_converter->ToV8Value(schema, context_)));
+ CHECK(!v8_schema.IsEmpty());
+ schema_cache_[api] = v8_schema;
+ return v8_schema;
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/renderer/extensions/v8_schema_registry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698