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 #include "services/catalog/catalog.h" | 5 #include "services/catalog/catalog.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 base::StartsWith(path, "service:", base::CompareCase::INSENSITIVE_ASCII); | 43 base::StartsWith(path, "service:", base::CompareCase::INSENSITIVE_ASCII); |
44 const bool is_exe = | 44 const bool is_exe = |
45 !is_service && | 45 !is_service && |
46 base::StartsWith(path, "exe:", base::CompareCase::INSENSITIVE_ASCII); | 46 base::StartsWith(path, "exe:", base::CompareCase::INSENSITIVE_ASCII); |
47 if (!is_service && !is_exe) | 47 if (!is_service && !is_exe) |
48 return base::FilePath(); | 48 return base::FilePath(); |
49 if (path.find('.') != std::string::npos) | 49 if (path.find('.') != std::string::npos) |
50 return base::FilePath(); | 50 return base::FilePath(); |
51 if (is_service) { | 51 if (is_service) { |
52 path.erase(path.begin(), | 52 path.erase(path.begin(), |
53 path.begin() + strlen(shell::kNameType_Service) + 1); | 53 path.begin() + strlen(service_manager::kNameType_Service) + 1); |
54 } else { | 54 } else { |
55 path.erase(path.begin(), path.begin() + strlen(shell::kNameType_Exe) + 1); | 55 path.erase(path.begin(), |
| 56 path.begin() + strlen(service_manager::kNameType_Exe) + 1); |
56 } | 57 } |
57 base::TrimString(path, "/", &path); | 58 base::TrimString(path, "/", &path); |
58 size_t end_of_name = path.find('/'); | 59 size_t end_of_name = path.find('/'); |
59 if (end_of_name != std::string::npos) | 60 if (end_of_name != std::string::npos) |
60 path.erase(path.begin() + end_of_name, path.end()); | 61 path.erase(path.begin() + end_of_name, path.end()); |
61 | 62 |
62 if (!IsPathNameValid(path)) | 63 if (!IsPathNameValid(path)) |
63 return base::FilePath(); | 64 return base::FilePath(); |
64 | 65 |
65 base::FilePath base_path; | 66 base::FilePath base_path; |
(...skipping 21 matching lines...) Expand all Loading... |
87 ScanSystemPackageDir(); | 88 ScanSystemPackageDir(); |
88 } | 89 } |
89 | 90 |
90 Catalog::~Catalog() {} | 91 Catalog::~Catalog() {} |
91 | 92 |
92 void Catalog::OverridePackageName(const std::string& service_name, | 93 void Catalog::OverridePackageName(const std::string& service_name, |
93 const std::string& package_name) { | 94 const std::string& package_name) { |
94 system_reader_->OverridePackageName(service_name, package_name); | 95 system_reader_->OverridePackageName(service_name, package_name); |
95 } | 96 } |
96 | 97 |
97 shell::mojom::ServicePtr Catalog::TakeService() { | 98 service_manager::mojom::ServicePtr Catalog::TakeService() { |
98 return std::move(service_); | 99 return std::move(service_); |
99 } | 100 } |
100 | 101 |
101 Catalog::Catalog(std::unique_ptr<Store> store) | 102 Catalog::Catalog(std::unique_ptr<Store> store) |
102 : store_(std::move(store)), weak_factory_(this) { | 103 : store_(std::move(store)), weak_factory_(this) { |
103 shell::mojom::ServiceRequest request = GetProxy(&service_); | 104 service_manager::mojom::ServiceRequest request = GetProxy(&service_); |
104 shell_connection_.reset(new shell::ServiceContext(this, std::move(request))); | 105 service_manager_connection_.reset( |
| 106 new service_manager::ServiceContext(this, std::move(request))); |
105 } | 107 } |
106 | 108 |
107 void Catalog::ScanSystemPackageDir() { | 109 void Catalog::ScanSystemPackageDir() { |
108 base::FilePath system_package_dir; | 110 base::FilePath system_package_dir; |
109 PathService::Get(base::DIR_MODULE, &system_package_dir); | 111 PathService::Get(base::DIR_MODULE, &system_package_dir); |
110 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName); | 112 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName); |
111 system_reader_->Read(system_package_dir, &system_cache_, | 113 system_reader_->Read(system_package_dir, &system_cache_, |
112 base::Bind(&Catalog::SystemPackageDirScanned, | 114 base::Bind(&Catalog::SystemPackageDirScanned, |
113 weak_factory_.GetWeakPtr())); | 115 weak_factory_.GetWeakPtr())); |
114 } | 116 } |
115 | 117 |
116 bool Catalog::OnConnect(const shell::Identity& remote_identity, | 118 bool Catalog::OnConnect(const service_manager::Identity& remote_identity, |
117 shell::InterfaceRegistry* registry) { | 119 service_manager::InterfaceRegistry* registry) { |
118 registry->AddInterface<mojom::Catalog>(this); | 120 registry->AddInterface<mojom::Catalog>(this); |
119 registry->AddInterface<mojom::CatalogControl>(this); | 121 registry->AddInterface<mojom::CatalogControl>(this); |
120 registry->AddInterface<filesystem::mojom::Directory>(this); | 122 registry->AddInterface<filesystem::mojom::Directory>(this); |
121 registry->AddInterface<shell::mojom::Resolver>(this); | 123 registry->AddInterface<service_manager::mojom::Resolver>(this); |
122 return true; | 124 return true; |
123 } | 125 } |
124 | 126 |
125 void Catalog::Create(const shell::Identity& remote_identity, | 127 void Catalog::Create(const service_manager::Identity& remote_identity, |
126 shell::mojom::ResolverRequest request) { | 128 service_manager::mojom::ResolverRequest request) { |
127 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); | 129 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
128 instance->BindResolver(std::move(request)); | 130 instance->BindResolver(std::move(request)); |
129 } | 131 } |
130 | 132 |
131 void Catalog::Create(const shell::Identity& remote_identity, | 133 void Catalog::Create(const service_manager::Identity& remote_identity, |
132 mojom::CatalogRequest request) { | 134 mojom::CatalogRequest request) { |
133 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); | 135 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
134 instance->BindCatalog(std::move(request)); | 136 instance->BindCatalog(std::move(request)); |
135 } | 137 } |
136 | 138 |
137 void Catalog::Create(const shell::Identity& remote_identity, | 139 void Catalog::Create(const service_manager::Identity& remote_identity, |
138 filesystem::mojom::DirectoryRequest request) { | 140 filesystem::mojom::DirectoryRequest request) { |
139 if (!lock_table_) | 141 if (!lock_table_) |
140 lock_table_ = new filesystem::LockTable; | 142 lock_table_ = new filesystem::LockTable; |
141 base::FilePath resources_path = | 143 base::FilePath resources_path = |
142 GetPathForApplicationName(remote_identity.name()); | 144 GetPathForApplicationName(remote_identity.name()); |
143 mojo::MakeStrongBinding( | 145 mojo::MakeStrongBinding( |
144 base::MakeUnique<filesystem::DirectoryImpl>( | 146 base::MakeUnique<filesystem::DirectoryImpl>( |
145 resources_path, scoped_refptr<filesystem::SharedTempDir>(), | 147 resources_path, scoped_refptr<filesystem::SharedTempDir>(), |
146 lock_table_), | 148 lock_table_), |
147 std::move(request)); | 149 std::move(request)); |
148 } | 150 } |
149 | 151 |
150 void Catalog::Create(const shell::Identity& remote_identity, | 152 void Catalog::Create(const service_manager::Identity& remote_identity, |
151 mojom::CatalogControlRequest request) { | 153 mojom::CatalogControlRequest request) { |
152 control_bindings_.AddBinding(this, std::move(request)); | 154 control_bindings_.AddBinding(this, std::move(request)); |
153 } | 155 } |
154 | 156 |
155 void Catalog::OverrideManifestPath( | 157 void Catalog::OverrideManifestPath( |
156 const std::string& service_name, | 158 const std::string& service_name, |
157 const base::FilePath& path, | 159 const base::FilePath& path, |
158 const OverrideManifestPathCallback& callback) { | 160 const OverrideManifestPathCallback& callback) { |
159 system_reader_->OverrideManifestPath(service_name, path); | 161 system_reader_->OverrideManifestPath(service_name, path); |
160 callback.Run(); | 162 callback.Run(); |
(...skipping 13 matching lines...) Expand all Loading... |
174 return instance; | 176 return instance; |
175 } | 177 } |
176 | 178 |
177 void Catalog::SystemPackageDirScanned() { | 179 void Catalog::SystemPackageDirScanned() { |
178 loaded_ = true; | 180 loaded_ = true; |
179 for (auto& instance : instances_) | 181 for (auto& instance : instances_) |
180 instance.second->CacheReady(&system_cache_); | 182 instance.second->CacheReady(&system_cache_); |
181 } | 183 } |
182 | 184 |
183 } // namespace catalog | 185 } // namespace catalog |
OLD | NEW |