Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: services/catalog/catalog.cc

Issue 2573283002: Use a static catalog manifest for the standalone Mash runner (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/catalog/catalog.h ('k') | services/catalog/instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macros.h" 10 #include "base/macros.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 registry->AddInterface<service_manager::mojom::Resolver>(catalog_); 79 registry->AddInterface<service_manager::mojom::Resolver>(catalog_);
80 return true; 80 return true;
81 } 81 }
82 82
83 private: 83 private:
84 Catalog* const catalog_; 84 Catalog* const catalog_;
85 85
86 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); 86 DISALLOW_COPY_AND_ASSIGN(ServiceImpl);
87 }; 87 };
88 88
89 Catalog::Catalog(std::unique_ptr<base::Value> static_manifest) : Catalog() {
90 system_reader_.reset(new Reader(std::move(static_manifest), &system_cache_));
91 loaded_ = true;
92 }
93
89 Catalog::Catalog(base::SequencedWorkerPool* worker_pool, 94 Catalog::Catalog(base::SequencedWorkerPool* worker_pool,
90 std::unique_ptr<Store> store, 95 ManifestProvider* manifest_provider) : Catalog() {
91 ManifestProvider* manifest_provider)
92 : Catalog(std::move(store)) {
93 system_reader_.reset(new Reader(worker_pool, manifest_provider)); 96 system_reader_.reset(new Reader(worker_pool, manifest_provider));
94 ScanSystemPackageDir(); 97 ScanSystemPackageDir();
95 } 98 }
96 99
97 Catalog::Catalog(base::SingleThreadTaskRunner* task_runner, 100 Catalog::Catalog(base::SingleThreadTaskRunner* task_runner,
98 std::unique_ptr<Store> store, 101 ManifestProvider* manifest_provider) : Catalog() {
99 ManifestProvider* manifest_provider)
100 : Catalog(std::move(store)) {
101 system_reader_.reset(new Reader(task_runner, manifest_provider)); 102 system_reader_.reset(new Reader(task_runner, manifest_provider));
102 ScanSystemPackageDir(); 103 ScanSystemPackageDir();
103 } 104 }
104 105
105 Catalog::~Catalog() {} 106 Catalog::~Catalog() {}
106 107
107 void Catalog::OverridePackageName(const std::string& service_name, 108 void Catalog::OverridePackageName(const std::string& service_name,
108 const std::string& package_name) { 109 const std::string& package_name) {
109 system_reader_->OverridePackageName(service_name, package_name); 110 system_reader_->OverridePackageName(service_name, package_name);
110 } 111 }
111 112
112 service_manager::mojom::ServicePtr Catalog::TakeService() { 113 service_manager::mojom::ServicePtr Catalog::TakeService() {
113 return std::move(service_); 114 return std::move(service_);
114 } 115 }
115 116
116 Catalog::Catalog(std::unique_ptr<Store> store) 117 Catalog::Catalog() : weak_factory_(this) {
117 : store_(std::move(store)), weak_factory_(this) {
118 service_manager::mojom::ServiceRequest request(&service_);
119 service_context_.reset(new service_manager::ServiceContext( 118 service_context_.reset(new service_manager::ServiceContext(
120 base::MakeUnique<ServiceImpl>(this), std::move(request))); 119 base::MakeUnique<ServiceImpl>(this),
120 service_manager::mojom::ServiceRequest(&service_)));
121 } 121 }
122 122
123 void Catalog::ScanSystemPackageDir() { 123 void Catalog::ScanSystemPackageDir() {
124 base::FilePath system_package_dir; 124 base::FilePath system_package_dir;
125 PathService::Get(base::DIR_MODULE, &system_package_dir); 125 PathService::Get(base::DIR_MODULE, &system_package_dir);
126 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName); 126 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName);
127 system_reader_->Read(system_package_dir, &system_cache_, 127 system_reader_->Read(system_package_dir, &system_cache_,
128 base::Bind(&Catalog::SystemPackageDirScanned, 128 base::Bind(&Catalog::SystemPackageDirScanned,
129 weak_factory_.GetWeakPtr())); 129 weak_factory_.GetWeakPtr()));
130 } 130 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 const OverrideManifestPathCallback& callback) { 165 const OverrideManifestPathCallback& callback) {
166 system_reader_->OverrideManifestPath(service_name, path); 166 system_reader_->OverrideManifestPath(service_name, path);
167 callback.Run(); 167 callback.Run();
168 } 168 }
169 169
170 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) { 170 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) {
171 auto it = instances_.find(user_id); 171 auto it = instances_.find(user_id);
172 if (it != instances_.end()) 172 if (it != instances_.end())
173 return it->second.get(); 173 return it->second.get();
174 174
175 // TODO(beng): There needs to be a way to load the store from different users. 175 Instance* instance = new Instance(system_reader_.get());
176 Instance* instance = new Instance(std::move(store_), system_reader_.get());
177 instances_[user_id] = base::WrapUnique(instance); 176 instances_[user_id] = base::WrapUnique(instance);
178 if (loaded_) 177 if (loaded_)
179 instance->CacheReady(&system_cache_); 178 instance->CacheReady(&system_cache_);
180 179
181 return instance; 180 return instance;
182 } 181 }
183 182
184 void Catalog::SystemPackageDirScanned() { 183 void Catalog::SystemPackageDirScanned() {
185 loaded_ = true; 184 loaded_ = true;
186 for (auto& instance : instances_) 185 for (auto& instance : instances_)
187 instance.second->CacheReady(&system_cache_); 186 instance.second->CacheReady(&system_cache_);
188 } 187 }
189 188
190 } // namespace catalog 189 } // namespace catalog
OLDNEW
« no previous file with comments | « services/catalog/catalog.h ('k') | services/catalog/instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698