| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 void Catalog::Create(const shell::Identity& remote_identity, | 122 void Catalog::Create(const shell::Identity& remote_identity, |
| 123 mojom::CatalogRequest request) { | 123 mojom::CatalogRequest request) { |
| 124 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); | 124 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
| 125 instance->BindCatalog(std::move(request)); | 125 instance->BindCatalog(std::move(request)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void Catalog::Create(const shell::Identity& remote_identity, | 128 void Catalog::Create(const shell::Identity& remote_identity, |
| 129 filesystem::mojom::DirectoryRequest request) { | 129 filesystem::mojom::DirectoryRequest request) { |
| 130 if (!lock_table_) | 130 if (!lock_table_) |
| 131 lock_table_ = new filesystem::LockTable; | 131 lock_table_ = new filesystem::LockTable; |
| 132 base::FilePath resources_path = | 132 base::FilePath resources_path(override_resource_path_); |
| 133 GetPathForApplicationName(remote_identity.name()); | 133 if (resources_path.empty()) |
| 134 resources_path = GetPathForApplicationName(remote_identity.name()); |
| 134 mojo::MakeStrongBinding( | 135 mojo::MakeStrongBinding( |
| 135 base::MakeUnique<filesystem::DirectoryImpl>( | 136 base::MakeUnique<filesystem::DirectoryImpl>( |
| 136 resources_path, scoped_refptr<filesystem::SharedTempDir>(), | 137 resources_path, scoped_refptr<filesystem::SharedTempDir>(), |
| 137 lock_table_), | 138 lock_table_), |
| 138 std::move(request)); | 139 std::move(request)); |
| 139 } | 140 } |
| 140 | 141 |
| 141 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) { | 142 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) { |
| 142 auto it = instances_.find(user_id); | 143 auto it = instances_.find(user_id); |
| 143 if (it != instances_.end()) | 144 if (it != instances_.end()) |
| 144 return it->second.get(); | 145 return it->second.get(); |
| 145 | 146 |
| 146 // TODO(beng): There needs to be a way to load the store from different users. | 147 // TODO(beng): There needs to be a way to load the store from different users. |
| 147 Instance* instance = new Instance(std::move(store_), system_reader_.get()); | 148 Instance* instance = new Instance(std::move(store_), system_reader_.get()); |
| 148 instances_[user_id] = base::WrapUnique(instance); | 149 instances_[user_id] = base::WrapUnique(instance); |
| 149 if (loaded_) | 150 if (loaded_) |
| 150 instance->CacheReady(&system_cache_); | 151 instance->CacheReady(&system_cache_); |
| 151 | 152 |
| 152 return instance; | 153 return instance; |
| 153 } | 154 } |
| 154 | 155 |
| 155 void Catalog::SystemPackageDirScanned() { | 156 void Catalog::SystemPackageDirScanned() { |
| 156 loaded_ = true; | 157 loaded_ = true; |
| 157 for (auto& instance : instances_) | 158 for (auto& instance : instances_) |
| 158 instance.second->CacheReady(&system_cache_); | 159 instance.second->CacheReady(&system_cache_); |
| 159 } | 160 } |
| 160 | 161 |
| 161 } // namespace catalog | 162 } // namespace catalog |
| OLD | NEW |