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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/v8_schema_registry.h ('k') | 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/extensions/v8_schema_registry.h"
6
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chrome/common/extensions/api/extension_api.h"
10 #include "content/public/renderer/v8_value_converter.h"
11
12 using content::V8ValueConverter;
13
14 namespace extensions {
15
16 V8SchemaRegistry::V8SchemaRegistry() : context_(v8::Context::New()) {}
17
18 V8SchemaRegistry::~V8SchemaRegistry() {
19 for (SchemaCache::iterator i = schema_cache_.begin();
20 i != schema_cache_.end(); ++i) {
21 i->second.Dispose();
22 }
23 context_.Dispose();
24 }
25
26 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas(
27 const std::set<std::string>& apis) {
28 v8::Context::Scope context_scope(context_);
29 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size()));
30 size_t api_index = 0;
31 for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end();
32 ++i) {
33 v8_apis->Set(api_index++, GetSchema(*i));
34 }
35 return v8_apis;
36 }
37
38 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) {
39 SchemaCache::iterator maybe_schema = schema_cache_.find(api);
40 if (maybe_schema != schema_cache_.end())
41 return maybe_schema->second;
42
43 const base::DictionaryValue* schema =
44 ExtensionAPI::GetInstance()->GetSchema(api);
45 CHECK(schema) << api;
46
47 scoped_ptr<V8ValueConverter> v8_value_converter(V8ValueConverter::create());
48 v8::Persistent<v8::Object> v8_schema =
49 v8::Persistent<v8::Object>::New(v8::Handle<v8::Object>::Cast(
50 v8_value_converter->ToV8Value(schema, context_)));
51 CHECK(!v8_schema.IsEmpty());
52 schema_cache_[api] = v8_schema;
53 return v8_schema;
54 }
55
56 } // namespace extensions
OLDNEW
« 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