| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SERVICES_CATALOG_ENTRY_H_ | 5 #ifndef SERVICES_CATALOG_ENTRY_H_ |
| 6 #define SERVICES_CATALOG_ENTRY_H_ | 6 #define SERVICES_CATALOG_ENTRY_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/macros.h" |
| 13 #include "services/catalog/public/interfaces/catalog.mojom.h" | 14 #include "services/catalog/public/interfaces/catalog.mojom.h" |
| 14 #include "services/service_manager/public/cpp/interface_provider_spec.h" | 15 #include "services/service_manager/public/cpp/interface_provider_spec.h" |
| 15 #include "services/service_manager/public/interfaces/resolver.mojom.h" | 16 #include "services/service_manager/public/interfaces/resolver.mojom.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class DictionaryValue; | 19 class DictionaryValue; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace catalog { | 22 namespace catalog { |
| 22 | 23 |
| 23 // Static information about a service package known to the Catalog. | 24 // Static information about a service package known to the Catalog. |
| 24 class Entry { | 25 class Entry { |
| 25 public: | 26 public: |
| 26 Entry(); | 27 Entry(); |
| 27 explicit Entry(const std::string& name); | 28 explicit Entry(const std::string& name); |
| 28 ~Entry(); | 29 ~Entry(); |
| 29 | 30 |
| 30 std::unique_ptr<base::DictionaryValue> Serialize() const; | 31 std::unique_ptr<base::DictionaryValue> Serialize() const; |
| 31 | 32 |
| 32 // If the constructed Entry is a package that provides other Entrys, the | |
| 33 // caller must assume ownership of the tree of Entrys by enumerating | |
| 34 // services(). | |
| 35 static std::unique_ptr<Entry> Deserialize(const base::DictionaryValue& value); | 33 static std::unique_ptr<Entry> Deserialize(const base::DictionaryValue& value); |
| 36 | 34 |
| 37 bool ProvidesCapability(const std::string& capability) const; | 35 bool ProvidesCapability(const std::string& capability) const; |
| 38 | 36 |
| 39 bool operator==(const Entry& other) const; | 37 bool operator==(const Entry& other) const; |
| 40 | 38 |
| 41 const std::string& name() const { return name_; } | 39 const std::string& name() const { return name_; } |
| 42 void set_name(const std::string& name) { name_ = name; } | 40 void set_name(const std::string& name) { name_ = name; } |
| 41 |
| 43 const base::FilePath& path() const { return path_; } | 42 const base::FilePath& path() const { return path_; } |
| 44 void set_path(const base::FilePath& path) { path_ = path; } | 43 void set_path(const base::FilePath& path) { path_ = path; } |
| 44 |
| 45 const std::string& display_name() const { return display_name_; } | 45 const std::string& display_name() const { return display_name_; } |
| 46 void set_display_name(const std::string& display_name) { | 46 void set_display_name(const std::string& display_name) { |
| 47 display_name_ = display_name; | 47 display_name_ = display_name; |
| 48 } | 48 } |
| 49 |
| 50 const Entry* parent() const { return parent_; } |
| 51 void set_parent(const Entry* parent) { parent_ = parent; } |
| 52 |
| 53 const std::vector<std::unique_ptr<Entry>>& children() const { |
| 54 return children_; |
| 55 } |
| 56 std::vector<std::unique_ptr<Entry>>& children() { return children_; } |
| 57 void set_children(std::vector<std::unique_ptr<Entry>>&& children) { |
| 58 children_ = std::move(children); |
| 59 } |
| 60 |
| 49 void AddInterfaceProviderSpec( | 61 void AddInterfaceProviderSpec( |
| 50 const std::string& name, | 62 const std::string& name, |
| 51 const service_manager::InterfaceProviderSpec& spec); | 63 const service_manager::InterfaceProviderSpec& spec); |
| 52 const service_manager::InterfaceProviderSpecMap& | 64 const service_manager::InterfaceProviderSpecMap& |
| 53 interface_provider_specs() const { | 65 interface_provider_specs() const { |
| 54 return interface_provider_specs_; | 66 return interface_provider_specs_; |
| 55 } | 67 } |
| 56 const Entry* package() const { return package_; } | |
| 57 void set_package(Entry* package) { package_ = package; } | |
| 58 | |
| 59 std::vector<std::unique_ptr<Entry>> TakeChildren() { | |
| 60 return std::move(children_); | |
| 61 } | |
| 62 | 68 |
| 63 private: | 69 private: |
| 64 std::string name_; | 70 std::string name_; |
| 65 base::FilePath path_; | 71 base::FilePath path_; |
| 66 std::string display_name_; | 72 std::string display_name_; |
| 67 service_manager::InterfaceProviderSpecMap interface_provider_specs_; | 73 service_manager::InterfaceProviderSpecMap interface_provider_specs_; |
| 68 Entry* package_ = nullptr; | 74 const Entry* parent_ = nullptr; |
| 69 std::vector<std::unique_ptr<Entry>> children_; | 75 std::vector<std::unique_ptr<Entry>> children_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(Entry); |
| 70 }; | 78 }; |
| 71 | 79 |
| 72 } // namespace catalog | 80 } // namespace catalog |
| 73 | 81 |
| 74 namespace mojo { | 82 namespace mojo { |
| 75 template <> | 83 template <> |
| 76 struct TypeConverter<service_manager::mojom::ResolveResultPtr, catalog::Entry> { | 84 struct TypeConverter<service_manager::mojom::ResolveResultPtr, |
| 85 const catalog::Entry*> { |
| 77 static service_manager::mojom::ResolveResultPtr Convert( | 86 static service_manager::mojom::ResolveResultPtr Convert( |
| 78 const catalog::Entry& input); | 87 const catalog::Entry* input); |
| 79 }; | 88 }; |
| 80 | 89 |
| 81 template<> | 90 template<> |
| 82 struct TypeConverter<catalog::mojom::EntryPtr, catalog::Entry> { | 91 struct TypeConverter<catalog::mojom::EntryPtr, catalog::Entry> { |
| 83 static catalog::mojom::EntryPtr Convert(const catalog::Entry& input); | 92 static catalog::mojom::EntryPtr Convert(const catalog::Entry& input); |
| 84 }; | 93 }; |
| 85 | 94 |
| 86 } // namespace mojo | 95 } // namespace mojo |
| 87 | 96 |
| 88 #endif // SERVICES_CATALOG_ENTRY_H_ | 97 #endif // SERVICES_CATALOG_ENTRY_H_ |
| OLD | NEW |