kMaxBlockSize -> kMaxHeaderBlockSize to avoid shadowing warning on VS2015
[chromium-blink-merge.git] / extensions / renderer / v8_schema_registry.h
blob5a3b20c31af544835c3230811f243ca5cb93327f
1 // Copyright 2014 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.
5 #ifndef EXTENSIONS_RENDERER_V8_SCHEMA_REGISTRY_H_
6 #define EXTENSIONS_RENDERER_V8_SCHEMA_REGISTRY_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "gin/public/context_holder.h"
15 #include "v8/include/v8-util.h"
16 #include "v8/include/v8.h"
18 namespace extensions {
19 class NativeHandler;
21 // A registry for the v8::Value representations of extension API schemas.
22 // In a way, the v8 counterpart to ExtensionAPI.
23 class V8SchemaRegistry {
24 public:
25 V8SchemaRegistry();
26 ~V8SchemaRegistry();
28 // Creates a NativeHandler wrapper |this|. Supports GetSchema.
29 scoped_ptr<NativeHandler> AsNativeHandler();
31 // Returns a v8::Array with all the schemas for the APIs in |apis|.
32 v8::Handle<v8::Array> GetSchemas(const std::vector<std::string>& apis);
34 // Returns a v8::Object for the schema for |api|, possibly from the cache.
35 v8::Handle<v8::Object> GetSchema(const std::string& api);
37 private:
38 // Gets the separate context that backs the registry, creating a new one if
39 // if necessary. Will also initialize schema_cache_.
40 v8::Handle<v8::Context> GetOrCreateContext(v8::Isolate* isolate);
42 // Cache of schemas. Created lazily by GetOrCreateContext.
43 typedef v8::StdPersistentValueMap<std::string, v8::Object> SchemaCache;
44 scoped_ptr<SchemaCache> schema_cache_;
46 // Single per-instance gin::ContextHolder to create v8::Values.
47 // Created lazily via GetOrCreateContext.
48 scoped_ptr<gin::ContextHolder> context_holder_;
50 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry);
53 } // namespace extensions
55 #endif // EXTENSIONS_RENDERER_V8_SCHEMA_REGISTRY_H_