OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 EXTENSIONS_RENDERER_STORAGE_AREA_H_ | 5 #ifndef EXTENSIONS_RENDERER_STORAGE_AREA_H_ |
6 #define EXTENSIONS_RENDERER_STORAGE_AREA_H_ | 6 #define EXTENSIONS_RENDERER_STORAGE_AREA_H_ |
7 | 7 |
8 #include <map> | |
9 #include <string> | 8 #include <string> |
10 | 9 |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
13 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
14 | 13 |
15 namespace gin { | 14 namespace gin { |
16 class Arguments; | 15 class Arguments; |
17 } | 16 } |
18 | 17 |
19 namespace extensions { | 18 namespace extensions { |
20 class APIRequestHandler; | 19 class APIRequestHandler; |
21 class APISignature; | |
22 class APITypeReferenceMap; | 20 class APITypeReferenceMap; |
23 | 21 |
24 // Implementation of the storage.StorageArea custom type used in the | 22 // Implementation of the storage.StorageArea custom type used in the |
25 // chrome.storage API. | 23 // chrome.storage API. |
26 class StorageArea { | 24 class StorageArea { |
27 public: | 25 public: |
28 StorageArea(APIRequestHandler* request_handler, | 26 StorageArea(APIRequestHandler* request_handler, |
29 const APITypeReferenceMap* type_refs, | 27 const APITypeReferenceMap* type_refs, |
30 const std::string& name); | 28 const std::string& name); |
31 ~StorageArea(); | 29 ~StorageArea(); |
32 | 30 |
33 // Creates a StorageArea object for the given context and property name. | 31 // Creates a StorageArea object for the given context and property name. |
34 static v8::Local<v8::Object> CreateStorageArea( | 32 static v8::Local<v8::Object> CreateStorageArea( |
35 v8::Local<v8::Context> context, | 33 v8::Local<v8::Context> context, |
36 const std::string& property_name, | 34 const std::string& property_name, |
37 APIRequestHandler* request_handler, | 35 APIRequestHandler* request_handler, |
38 APITypeReferenceMap* type_refs); | 36 APITypeReferenceMap* type_refs); |
39 | 37 |
40 void HandleFunctionCall(const std::string& method_name, | 38 void HandleFunctionCall(const std::string& method_name, |
41 gin::Arguments* arguments); | 39 gin::Arguments* arguments); |
42 | 40 |
43 private: | 41 private: |
44 // Returns the schema associated with the specified function. | |
45 // TODO(devlin): Other custom types will need this, too; move it out of here | |
46 // when more exist. | |
47 const APISignature& GetFunctionSchema(base::StringPiece api_name, | |
48 base::StringPiece type_name, | |
49 base::StringPiece function_name); | |
50 | |
51 APIRequestHandler* request_handler_; | 42 APIRequestHandler* request_handler_; |
52 | 43 |
53 const APITypeReferenceMap* type_refs_; | 44 const APITypeReferenceMap* type_refs_; |
54 | 45 |
55 std::string name_; | 46 std::string name_; |
56 | 47 |
57 // TODO(devlin): See GetFunctionSchema. | |
58 std::map<std::string, std::unique_ptr<APISignature>> signatures_; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(StorageArea); | 48 DISALLOW_COPY_AND_ASSIGN(StorageArea); |
61 }; | 49 }; |
62 | 50 |
63 } // namespace extensions | 51 } // namespace extensions |
64 | 52 |
65 #endif // EXTENSIONS_RENDERER_STORAGE_AREA_H_ | 53 #endif // EXTENSIONS_RENDERER_STORAGE_AREA_H_ |
OLD | NEW |