| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "components/filesystem/directory_impl.h" | 14 #include "components/filesystem/directory_impl.h" |
| 15 #include "components/filesystem/lock_table.h" | 15 #include "components/filesystem/lock_table.h" |
| 16 #include "components/filesystem/public/interfaces/types.mojom.h" | 16 #include "components/filesystem/public/interfaces/types.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/strong_binding.h" | 17 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 18 #include "services/catalog/constants.h" | 18 #include "services/catalog/constants.h" |
| 19 #include "services/catalog/instance.h" | 19 #include "services/catalog/instance.h" |
| 20 #include "services/catalog/reader.h" | 20 #include "services/catalog/reader.h" |
| 21 #include "services/shell/public/cpp/connection.h" | 21 #include "services/shell/public/cpp/connection.h" |
| 22 #include "services/shell/public/cpp/names.h" |
| 22 #include "services/shell/public/cpp/service_context.h" | 23 #include "services/shell/public/cpp/service_context.h" |
| 23 | 24 |
| 24 namespace catalog { | 25 namespace catalog { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 bool IsPathNameValid(const std::string& name) { | 28 bool IsPathNameValid(const std::string& name) { |
| 28 if (name.empty() || name == "." || name == "..") | 29 if (name.empty() || name == "." || name == "..") |
| 29 return false; | 30 return false; |
| 30 | 31 |
| 31 for (auto c : name) { | 32 for (auto c : name) { |
| 32 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c) && | 33 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c) && |
| 33 c != '_' && c != '.') | 34 c != '_' && c != '.') |
| 34 return false; | 35 return false; |
| 35 } | 36 } |
| 36 return true; | 37 return true; |
| 37 } | 38 } |
| 38 | 39 |
| 39 base::FilePath GetPathForApplicationName(const std::string& application_name) { | 40 base::FilePath GetPathForApplicationName(const std::string& application_name) { |
| 40 std::string path = application_name; | 41 std::string path = application_name; |
| 41 const bool is_mojo = | 42 const bool is_service = |
| 42 base::StartsWith(path, "mojo:", base::CompareCase::INSENSITIVE_ASCII); | 43 base::StartsWith(path, "service:", base::CompareCase::INSENSITIVE_ASCII); |
| 43 const bool is_exe = | 44 const bool is_exe = |
| 44 !is_mojo && | 45 !is_service && |
| 45 base::StartsWith(path, "exe:", base::CompareCase::INSENSITIVE_ASCII); | 46 base::StartsWith(path, "exe:", base::CompareCase::INSENSITIVE_ASCII); |
| 46 if (!is_mojo && !is_exe) | 47 if (!is_service && !is_exe) |
| 47 return base::FilePath(); | 48 return base::FilePath(); |
| 48 if (path.find('.') != std::string::npos) | 49 if (path.find('.') != std::string::npos) |
| 49 return base::FilePath(); | 50 return base::FilePath(); |
| 50 if (is_mojo) | 51 if (is_service) { |
| 51 path.erase(path.begin(), path.begin() + 5); | 52 path.erase(path.begin(), |
| 52 else | 53 path.begin() + strlen(shell::kNameType_Service) + 1); |
| 53 path.erase(path.begin(), path.begin() + 4); | 54 } else { |
| 55 path.erase(path.begin(), path.begin() + strlen(shell::kNameType_Exe) + 1); |
| 56 } |
| 54 base::TrimString(path, "/", &path); | 57 base::TrimString(path, "/", &path); |
| 55 size_t end_of_name = path.find('/'); | 58 size_t end_of_name = path.find('/'); |
| 56 if (end_of_name != std::string::npos) | 59 if (end_of_name != std::string::npos) |
| 57 path.erase(path.begin() + end_of_name, path.end()); | 60 path.erase(path.begin() + end_of_name, path.end()); |
| 58 | 61 |
| 59 if (!IsPathNameValid(path)) | 62 if (!IsPathNameValid(path)) |
| 60 return base::FilePath(); | 63 return base::FilePath(); |
| 61 | 64 |
| 62 base::FilePath base_path; | 65 base::FilePath base_path; |
| 63 PathService::Get(base::DIR_EXE, &base_path); | 66 PathService::Get(base::DIR_EXE, &base_path); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return instance; | 155 return instance; |
| 153 } | 156 } |
| 154 | 157 |
| 155 void Catalog::SystemPackageDirScanned() { | 158 void Catalog::SystemPackageDirScanned() { |
| 156 loaded_ = true; | 159 loaded_ = true; |
| 157 for (auto& instance : instances_) | 160 for (auto& instance : instances_) |
| 158 instance.second->CacheReady(&system_cache_); | 161 instance.second->CacheReady(&system_cache_); |
| 159 } | 162 } |
| 160 | 163 |
| 161 } // namespace catalog | 164 } // namespace catalog |
| OLD | NEW |