| OLD | NEW |
| 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> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 // A registry for the v8::Value representations of extension API schemas. | 17 // A registry for the v8::Value representations of extension API schemas. |
| 18 // In a way, the v8 counterpart to ExtensionAPI. | 18 // In a way, the v8 counterpart to ExtensionAPI. |
| 19 class V8SchemaRegistry { | 19 class V8SchemaRegistry { |
| 20 public: | 20 public: |
| 21 V8SchemaRegistry(); | 21 V8SchemaRegistry(); |
| 22 ~V8SchemaRegistry(); | 22 ~V8SchemaRegistry(); |
| 23 | 23 |
| 24 // Returns a v8::Array with all the schemas for the APIs in |apis|. | 24 // Returns a v8::Array with all the schemas for the APIs in |apis|. |
| 25 v8::Handle<v8::Array> GetSchemas(const std::set<std::string>& apis); | 25 v8::Handle<v8::Array> GetSchemas(const std::set<std::string>& apis); |
| 26 | 26 |
| 27 private: |
| 27 // Returns a v8::Object for the schema for |api|, possibly from the cache. | 28 // Returns a v8::Object for the schema for |api|, possibly from the cache. |
| 28 v8::Handle<v8::Object> GetSchema(const std::string& api); | 29 v8::Handle<v8::Object> GetSchema(const std::string& api); |
| 29 | 30 |
| 30 private: | |
| 31 // Cache of schemas. | 31 // Cache of schemas. |
| 32 typedef std::map<std::string, v8::Persistent<v8::Object> > SchemaCache; | 32 typedef std::map<std::string, v8::Persistent<v8::Object> > SchemaCache; |
| 33 SchemaCache schema_cache_; | 33 SchemaCache schema_cache_; |
| 34 | 34 |
| 35 // Single per-instance v8::Context to create v8::Values. | 35 // Single per-instance v8::Context to create v8::Values. |
| 36 v8::Persistent<v8::Context> context_; | 36 v8::Persistent<v8::Context> context_; |
| 37 | 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry); | 38 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 } // namespace extensions | 41 } // namespace extensions |
| 42 | 42 |
| 43 #endif // CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ | 43 #endif // CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ |
| OLD | NEW |