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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 weak_factory_.GetWeakPtr())); | 104 weak_factory_.GetWeakPtr())); |
105 } | 105 } |
106 | 106 |
107 bool Catalog::OnConnect(shell::Connection* connection) { | 107 bool Catalog::OnConnect(shell::Connection* connection) { |
108 connection->AddInterface<mojom::Catalog>(this); | 108 connection->AddInterface<mojom::Catalog>(this); |
109 connection->AddInterface<filesystem::mojom::Directory>(this); | 109 connection->AddInterface<filesystem::mojom::Directory>(this); |
110 connection->AddInterface<shell::mojom::Resolver>(this); | 110 connection->AddInterface<shell::mojom::Resolver>(this); |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 void Catalog::Create(shell::Connection* connection, | 114 void Catalog::Create(const shell::Identity& remote_identity, |
115 shell::mojom::ResolverRequest request) { | 115 shell::mojom::ResolverRequest request) { |
116 Instance* instance = | 116 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
117 GetInstanceForUserId(connection->GetRemoteIdentity().user_id()); | |
118 instance->BindResolver(std::move(request)); | 117 instance->BindResolver(std::move(request)); |
119 } | 118 } |
120 | 119 |
121 void Catalog::Create(shell::Connection* connection, | 120 void Catalog::Create(const shell::Identity& remote_identity, |
122 mojom::CatalogRequest request) { | 121 mojom::CatalogRequest request) { |
123 Instance* instance = | 122 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
124 GetInstanceForUserId(connection->GetRemoteIdentity().user_id()); | |
125 instance->BindCatalog(std::move(request)); | 123 instance->BindCatalog(std::move(request)); |
126 } | 124 } |
127 | 125 |
128 void Catalog::Create(shell::Connection* connection, | 126 void Catalog::Create(const shell::Identity& remote_identity, |
129 filesystem::mojom::DirectoryRequest request) { | 127 filesystem::mojom::DirectoryRequest request) { |
130 if (!lock_table_) | 128 if (!lock_table_) |
131 lock_table_ = new filesystem::LockTable; | 129 lock_table_ = new filesystem::LockTable; |
132 base::FilePath resources_path = | 130 base::FilePath resources_path = |
133 GetPathForApplicationName(connection->GetRemoteIdentity().name()); | 131 GetPathForApplicationName(remote_identity.name()); |
134 new filesystem::DirectoryImpl(std::move(request), resources_path, | 132 new filesystem::DirectoryImpl(std::move(request), resources_path, |
135 scoped_refptr<filesystem::SharedTempDir>(), | 133 scoped_refptr<filesystem::SharedTempDir>(), |
136 lock_table_); | 134 lock_table_); |
137 } | 135 } |
138 | 136 |
139 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) { | 137 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) { |
140 auto it = instances_.find(user_id); | 138 auto it = instances_.find(user_id); |
141 if (it != instances_.end()) | 139 if (it != instances_.end()) |
142 return it->second.get(); | 140 return it->second.get(); |
143 | 141 |
144 // TODO(beng): There needs to be a way to load the store from different users. | 142 // TODO(beng): There needs to be a way to load the store from different users. |
145 Instance* instance = new Instance(std::move(store_), system_reader_.get()); | 143 Instance* instance = new Instance(std::move(store_), system_reader_.get()); |
146 instances_[user_id] = base::WrapUnique(instance); | 144 instances_[user_id] = base::WrapUnique(instance); |
147 if (loaded_) | 145 if (loaded_) |
148 instance->CacheReady(&system_cache_); | 146 instance->CacheReady(&system_cache_); |
149 | 147 |
150 return instance; | 148 return instance; |
151 } | 149 } |
152 | 150 |
153 void Catalog::SystemPackageDirScanned() { | 151 void Catalog::SystemPackageDirScanned() { |
154 loaded_ = true; | 152 loaded_ = true; |
155 for (auto& instance : instances_) | 153 for (auto& instance : instances_) |
156 instance.second->CacheReady(&system_cache_); | 154 instance.second->CacheReady(&system_cache_); |
157 } | 155 } |
158 | 156 |
159 } // namespace catalog | 157 } // namespace catalog |
OLD | NEW |