OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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/preferences/public/cpp/pref_service_factory.h" | 5 #include "services/preferences/public/cpp/pref_service_factory.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/test/sequenced_worker_pool_owner.h" | 10 #include "base/test/sequenced_worker_pool_owner.h" |
11 #include "components/prefs/pref_change_registrar.h" | 11 #include "components/prefs/pref_change_registrar.h" |
12 #include "components/prefs/pref_registry_simple.h" | 12 #include "components/prefs/pref_registry_simple.h" |
13 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
14 #include "components/prefs/value_map_pref_store.h" | 14 #include "components/prefs/value_map_pref_store.h" |
15 #include "components/prefs/writeable_pref_store.h" | 15 #include "components/prefs/writeable_pref_store.h" |
16 #include "mojo/public/cpp/bindings/binding_set.h" | 16 #include "mojo/public/cpp/bindings/binding_set.h" |
17 #include "services/preferences/public/cpp/pref_service_main.h" | 17 #include "services/preferences/public/cpp/pref_service_main.h" |
18 #include "services/preferences/public/cpp/pref_store_impl.h" | 18 #include "services/preferences/public/cpp/pref_store_impl.h" |
19 #include "services/preferences/public/interfaces/preferences.mojom.h" | 19 #include "services/preferences/public/interfaces/preferences.mojom.h" |
| 20 #include "services/service_manager/public/cpp/binder_registry.h" |
20 #include "services/service_manager/public/cpp/interface_factory.h" | 21 #include "services/service_manager/public/cpp/interface_factory.h" |
21 #include "services/service_manager/public/cpp/interface_registry.h" | |
22 #include "services/service_manager/public/cpp/service_context.h" | 22 #include "services/service_manager/public/cpp/service_context.h" |
23 #include "services/service_manager/public/cpp/service_test.h" | 23 #include "services/service_manager/public/cpp/service_test.h" |
24 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 24 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
25 | 25 |
26 namespace prefs { | 26 namespace prefs { |
27 namespace { | 27 namespace { |
28 | 28 |
29 class ServiceTestClient : public service_manager::test::ServiceTestClient, | 29 class ServiceTestClient : public service_manager::test::ServiceTestClient, |
30 public service_manager::mojom::ServiceFactory, | 30 public service_manager::mojom::ServiceFactory, |
31 public service_manager::InterfaceFactory< | 31 public service_manager::InterfaceFactory< |
32 service_manager::mojom::ServiceFactory> { | 32 service_manager::mojom::ServiceFactory> { |
33 public: | 33 public: |
34 ServiceTestClient(service_manager::test::ServiceTest* test, | 34 ServiceTestClient(service_manager::test::ServiceTest* test, |
35 scoped_refptr<base::SequencedWorkerPool> worker_pool) | 35 scoped_refptr<base::SequencedWorkerPool> worker_pool) |
36 : service_manager::test::ServiceTestClient(test), | 36 : service_manager::test::ServiceTestClient(test), |
37 worker_pool_(std::move(worker_pool)) {} | 37 worker_pool_(std::move(worker_pool)) { |
| 38 registry_.AddInterface<service_manager::mojom::ServiceFactory>(this); |
| 39 } |
38 | 40 |
39 protected: | 41 protected: |
40 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 42 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
41 service_manager::InterfaceRegistry* registry) override { | 43 const std::string& interface_name, |
42 registry->AddInterface<service_manager::mojom::ServiceFactory>(this); | 44 mojo::ScopedMessagePipeHandle interface_pipe) override { |
43 return true; | 45 registry_.BindInterface(source_info.identity, interface_name, |
| 46 std::move(interface_pipe)); |
44 } | 47 } |
45 | 48 |
46 void CreateService(service_manager::mojom::ServiceRequest request, | 49 void CreateService(service_manager::mojom::ServiceRequest request, |
47 const std::string& name) override { | 50 const std::string& name) override { |
48 if (name == prefs::mojom::kServiceName) { | 51 if (name == prefs::mojom::kServiceName) { |
49 pref_service_context_.reset(new service_manager::ServiceContext( | 52 pref_service_context_.reset(new service_manager::ServiceContext( |
50 CreatePrefService( | 53 CreatePrefService( |
51 {PrefValueStore::COMMAND_LINE_STORE, | 54 {PrefValueStore::COMMAND_LINE_STORE, |
52 PrefValueStore::RECOMMENDED_STORE, PrefValueStore::USER_STORE, | 55 PrefValueStore::RECOMMENDED_STORE, PrefValueStore::USER_STORE, |
53 PrefValueStore::DEFAULT_STORE}, | 56 PrefValueStore::DEFAULT_STORE}, |
54 worker_pool_), | 57 worker_pool_), |
55 std::move(request))); | 58 std::move(request))); |
56 } | 59 } |
57 } | 60 } |
58 | 61 |
59 void Create(const service_manager::Identity& remote_identity, | 62 void Create(const service_manager::Identity& remote_identity, |
60 service_manager::mojom::ServiceFactoryRequest request) override { | 63 service_manager::mojom::ServiceFactoryRequest request) override { |
61 service_factory_bindings_.AddBinding(this, std::move(request)); | 64 service_factory_bindings_.AddBinding(this, std::move(request)); |
62 } | 65 } |
63 | 66 |
64 private: | 67 private: |
65 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 68 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 69 service_manager::BinderRegistry registry_; |
66 mojo::BindingSet<service_manager::mojom::ServiceFactory> | 70 mojo::BindingSet<service_manager::mojom::ServiceFactory> |
67 service_factory_bindings_; | 71 service_factory_bindings_; |
68 std::unique_ptr<service_manager::ServiceContext> pref_service_context_; | 72 std::unique_ptr<service_manager::ServiceContext> pref_service_context_; |
69 }; | 73 }; |
70 | 74 |
71 constexpr int kInitialValue = 1; | 75 constexpr int kInitialValue = 1; |
72 constexpr int kUpdatedValue = 2; | 76 constexpr int kUpdatedValue = 2; |
73 constexpr char kKey[] = "some_key"; | 77 constexpr char kKey[] = "some_key"; |
74 constexpr char kOtherKey[] = "some_other_key"; | 78 constexpr char kOtherKey[] = "some_other_key"; |
75 | 79 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 base::MakeUnique<base::Value>(2), 0); | 260 base::MakeUnique<base::Value>(2), 0); |
257 WaitForPrefChange(pref_service.get(), kKey); | 261 WaitForPrefChange(pref_service.get(), kKey); |
258 EXPECT_EQ(2, pref_service->GetInteger(kKey)); | 262 EXPECT_EQ(2, pref_service->GetInteger(kKey)); |
259 | 263 |
260 pref_service->SetInteger(kKey, 3); | 264 pref_service->SetInteger(kKey, 3); |
261 EXPECT_EQ(2, pref_service->GetInteger(kKey)); | 265 EXPECT_EQ(2, pref_service->GetInteger(kKey)); |
262 } | 266 } |
263 | 267 |
264 } // namespace | 268 } // namespace |
265 } // namespace prefs | 269 } // namespace prefs |
OLD | NEW |