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

Side by Side Diff: chrome/renderer/extensions/v8_schema_registry.h

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos tests Created 7 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_
6 #define CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ 6 #define CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set>
10 #include <string> 9 #include <string>
10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/renderer/extensions/scoped_persistent.h" 14 #include "chrome/renderer/extensions/scoped_persistent.h"
15 #include "chrome/renderer/extensions/unsafe_persistent.h" 15 #include "chrome/renderer/extensions/unsafe_persistent.h"
16 #include "v8/include/v8.h" 16 #include "v8/include/v8.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 class NativeHandler; 19 class NativeHandler;
20 20
21 // A registry for the v8::Value representations of extension API schemas. 21 // A registry for the v8::Value representations of extension API schemas.
22 // In a way, the v8 counterpart to ExtensionAPI. 22 // In a way, the v8 counterpart to ExtensionAPI.
23 class V8SchemaRegistry { 23 class V8SchemaRegistry {
24 public: 24 public:
25 V8SchemaRegistry(); 25 V8SchemaRegistry();
26 ~V8SchemaRegistry(); 26 ~V8SchemaRegistry();
27 27
28 // Creates a NativeHandler wrapper |this|. Supports GetSchema. 28 // Creates a NativeHandler wrapper |this|. Supports GetSchema.
29 scoped_ptr<NativeHandler> AsNativeHandler(); 29 scoped_ptr<NativeHandler> AsNativeHandler();
30 30
31 // Returns a v8::Array with all the schemas for the APIs in |apis|. 31 // Returns a v8::Array with all the schemas for the APIs in |apis|.
32 v8::Handle<v8::Array> GetSchemas(const std::set<std::string>& apis); 32 v8::Handle<v8::Array> GetSchemas(const std::vector<std::string>& apis);
33 33
34 // Returns a v8::Object for the schema for |api|, possibly from the cache. 34 // Returns a v8::Object for the schema for |api|, possibly from the cache.
35 v8::Handle<v8::Object> GetSchema(const std::string& api); 35 v8::Handle<v8::Object> GetSchema(const std::string& api);
36 36
37 private: 37 private:
38 // Gets the separate context that backs the registry, creating a new one if 38 // Gets the separate context that backs the registry, creating a new one if
39 // if necessary. 39 // if necessary.
40 v8::Handle<v8::Context> GetOrCreateContext(v8::Isolate* isolate); 40 v8::Handle<v8::Context> GetOrCreateContext(v8::Isolate* isolate);
41 41
42 // Cache of schemas. 42 // Cache of schemas.
43 // 43 //
44 // Storing UnsafePersistents is safe here, because the corresponding 44 // Storing UnsafePersistents is safe here, because the corresponding
45 // Persistent handle is created in GetSchema(), and it keeps the data pointed 45 // Persistent handle is created in GetSchema(), and it keeps the data pointed
46 // by the UnsafePersistent alive. It's not made weak or disposed, and nobody 46 // by the UnsafePersistent alive. It's not made weak or disposed, and nobody
47 // else has access to it. The Persistent is then disposed in the dtor. 47 // else has access to it. The Persistent is then disposed in the dtor.
48 typedef std::map<std::string, UnsafePersistent<v8::Object> > SchemaCache; 48 typedef std::map<std::string, UnsafePersistent<v8::Object> > SchemaCache;
49 SchemaCache schema_cache_; 49 SchemaCache schema_cache_;
50 50
51 // Single per-instance v8::Context to create v8::Values. 51 // Single per-instance v8::Context to create v8::Values.
52 // Created lazily via GetOrCreateContext. 52 // Created lazily via GetOrCreateContext.
53 ScopedPersistent<v8::Context> context_; 53 ScopedPersistent<v8::Context> context_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry); 55 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry);
56 }; 56 };
57 57
58 } // namespace extensions 58 } // namespace extensions
59 59
60 #endif // CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ 60 #endif // CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/runtime_custom_bindings.cc ('k') | chrome/renderer/extensions/v8_schema_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698