OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/catalog/factory.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "mojo/services/catalog/catalog.h" |
| 9 #include "mojo/shell/public/cpp/connection.h" |
| 10 #include "mojo/shell/public/cpp/shell_connection.h" |
| 11 |
| 12 namespace catalog { |
| 13 |
| 14 Factory::Factory(base::TaskRunner* file_task_runner, scoped_ptr<Store> store) |
| 15 : file_task_runner_(file_task_runner), |
| 16 store_(std::move(store)), |
| 17 weak_factory_(this) { |
| 18 mojo::shell::mojom::ShellClientRequest request = GetProxy(&shell_client_); |
| 19 shell_connection_.reset(new mojo::ShellConnection(this, std::move(request))); |
| 20 } |
| 21 Factory::~Factory() {} |
| 22 |
| 23 mojo::shell::mojom::ShellClientPtr Factory::TakeShellClient() { |
| 24 return std::move(shell_client_); |
| 25 } |
| 26 |
| 27 bool Factory::AcceptConnection(mojo::Connection* connection) { |
| 28 connection->AddInterface<mojom::Catalog>(this); |
| 29 connection->AddInterface<mojom::Resolver>(this); |
| 30 connection->AddInterface<mojo::shell::mojom::ShellResolver>(this); |
| 31 return true; |
| 32 } |
| 33 |
| 34 void Factory::Create(mojo::Connection* connection, |
| 35 mojom::ResolverRequest request) { |
| 36 Catalog* instance = |
| 37 GetCatalogForUserId(connection->GetRemoteIdentity().user_id()); |
| 38 instance->BindResolver(std::move(request)); |
| 39 } |
| 40 |
| 41 void Factory::Create(mojo::Connection* connection, |
| 42 mojo::shell::mojom::ShellResolverRequest request) { |
| 43 Catalog* instance = |
| 44 GetCatalogForUserId(connection->GetRemoteIdentity().user_id()); |
| 45 instance->BindShellResolver(std::move(request)); |
| 46 } |
| 47 |
| 48 void Factory::Create(mojo::Connection* connection, |
| 49 mojom::CatalogRequest request) { |
| 50 Catalog* instance = |
| 51 GetCatalogForUserId(connection->GetRemoteIdentity().user_id()); |
| 52 instance->BindCatalog(std::move(request)); |
| 53 } |
| 54 |
| 55 Catalog* Factory::GetCatalogForUserId(const std::string& user_id) { |
| 56 auto it = catalogs_.find(user_id); |
| 57 if (it != catalogs_.end()) |
| 58 return it->second.get(); |
| 59 |
| 60 // TODO(beng): There needs to be a way to load the store from different users. |
| 61 Catalog* instance = new Catalog(file_task_runner_, std::move(store_)); |
| 62 catalogs_[user_id] = make_scoped_ptr(instance); |
| 63 return instance; |
| 64 } |
| 65 |
| 66 } // namespace catalog |
OLD | NEW |