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_API_TYPE_REFERENCE_MAP_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_TYPE_REFERENCE_MAP_H_ |
6 #define EXTENSIONS_RENDERER_API_TYPE_REFERENCE_MAP_H_ | 6 #define EXTENSIONS_RENDERER_API_TYPE_REFERENCE_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
| 16 class APISignature; |
16 class ArgumentSpec; | 17 class ArgumentSpec; |
17 | 18 |
18 // A map from type name -> ArgumentSpec for API type definitions. This is used | 19 // A map storing type specifications and method signatures for API definitions. |
19 // when an argument is declared to be a reference to a type defined elsewhere. | |
20 class APITypeReferenceMap { | 20 class APITypeReferenceMap { |
21 public: | 21 public: |
22 // A callback used to initialize an unknown type, so that these can be | 22 // A callback used to initialize an unknown type, so that these can be |
23 // created lazily. | 23 // created lazily. |
24 using InitializeTypeCallback = base::Callback<void(const std::string& name)>; | 24 using InitializeTypeCallback = base::Callback<void(const std::string& name)>; |
25 | 25 |
26 explicit APITypeReferenceMap(const InitializeTypeCallback& initialize_type); | 26 explicit APITypeReferenceMap(const InitializeTypeCallback& initialize_type); |
27 ~APITypeReferenceMap(); | 27 ~APITypeReferenceMap(); |
28 | 28 |
29 // Adds the |spec| to the map under the given |name|. | 29 // Adds the |spec| to the map under the given |name|. |
30 void AddSpec(const std::string& name, std::unique_ptr<ArgumentSpec> spec); | 30 void AddSpec(const std::string& name, std::unique_ptr<ArgumentSpec> spec); |
31 | 31 |
32 // Returns the spec for the given |name|. | 32 // Returns the spec for the given |name|. |
33 const ArgumentSpec* GetSpec(const std::string& name) const; | 33 const ArgumentSpec* GetSpec(const std::string& name) const; |
34 | 34 |
| 35 // Adds the |signature| to the map under the given |name|. |name| is expected |
| 36 // to be fully qualified with API, type, and method (e.g. |
| 37 // storage.StorageArea.get). |
| 38 void AddTypeMethodSignature(const std::string& name, |
| 39 std::unique_ptr<APISignature> signature); |
| 40 |
| 41 // Returns the signature for the given |name|. |name| is expected |
| 42 // to be fully qualified with API, type, and method (e.g. |
| 43 // storage.StorageArea.get). |
| 44 const APISignature* GetTypeMethodSignature(const std::string& name) const; |
| 45 |
35 bool empty() const { return type_refs_.empty(); } | 46 bool empty() const { return type_refs_.empty(); } |
36 size_t size() const { return type_refs_.size(); } | 47 size_t size() const { return type_refs_.size(); } |
37 | 48 |
38 private: | 49 private: |
39 InitializeTypeCallback initialize_type_; | 50 InitializeTypeCallback initialize_type_; |
40 | 51 |
41 std::map<std::string, std::unique_ptr<ArgumentSpec>> type_refs_; | 52 std::map<std::string, std::unique_ptr<ArgumentSpec>> type_refs_; |
42 | 53 |
| 54 std::map<std::string, std::unique_ptr<APISignature>> type_methods_; |
| 55 |
43 DISALLOW_COPY_AND_ASSIGN(APITypeReferenceMap); | 56 DISALLOW_COPY_AND_ASSIGN(APITypeReferenceMap); |
44 }; | 57 }; |
45 | 58 |
46 } // namespace extensions | 59 } // namespace extensions |
47 | 60 |
48 #endif // EXTENSIONS_RENDERER_API_TYPE_REFERENCE_MAP_H_ | 61 #endif // EXTENSIONS_RENDERER_API_TYPE_REFERENCE_MAP_H_ |
OLD | NEW |