OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/ash/ash_util.h" | 5 #include "chrome/browser/ui/ash/ash_util.h" |
6 | 6 |
7 #include "ash/common/accelerators/accelerator_controller.h" | 7 #include "ash/common/accelerators/accelerator_controller.h" |
| 8 #include "ash/common/mojo_interface_factory.h" |
8 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "base/macros.h" |
9 #include "build/build_config.h" | 11 #include "build/build_config.h" |
10 #include "chrome/browser/ui/ash/ash_init.h" | 12 #include "chrome/browser/ui/ash/ash_init.h" |
11 #include "content/public/common/service_names.mojom.h" | 13 #include "content/public/common/service_names.mojom.h" |
| 14 #include "services/service_manager/public/cpp/interface_registry.h" |
| 15 #include "services/service_manager/public/cpp/service.h" |
| 16 #include "services/service_manager/public/interfaces/interface_provider_spec.moj
om.h" |
12 #include "services/service_manager/runner/common/client_util.h" | 17 #include "services/service_manager/runner/common/client_util.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
14 | 19 |
15 namespace ash_util { | 20 namespace ash_util { |
16 | 21 |
| 22 namespace { |
| 23 |
| 24 class EmbeddedAshService : public service_manager::Service { |
| 25 public: |
| 26 explicit EmbeddedAshService( |
| 27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| 28 : task_runner_(task_runner), |
| 29 interfaces_(service_manager::mojom::kServiceManager_ConnectorSpec) {} |
| 30 ~EmbeddedAshService() override {} |
| 31 |
| 32 // service_manager::Service: |
| 33 void OnStart() override { |
| 34 ash::mojo_interface_factory::RegisterInterfaces(&interfaces_, task_runner_); |
| 35 } |
| 36 |
| 37 void OnBindInterface(const service_manager::ServiceInfo& remote_info, |
| 38 const std::string& interface_name, |
| 39 mojo::ScopedMessagePipeHandle handle) override { |
| 40 interfaces_.BindInterface(interface_name, std::move(handle)); |
| 41 } |
| 42 |
| 43 private: |
| 44 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 45 service_manager::InterfaceRegistry interfaces_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(EmbeddedAshService); |
| 48 }; |
| 49 |
| 50 } // namespace |
| 51 |
| 52 // TODO(rockot): Remove this. |
17 const char* GetAshServiceName() { | 53 const char* GetAshServiceName() { |
18 // Under mash the ash process provides the service. | 54 return "ash"; |
19 if (chrome::IsRunningInMash()) | 55 } |
20 return "ash"; | |
21 | 56 |
22 // Under classic ash the browser process provides the service. | 57 std::unique_ptr<service_manager::Service> CreateEmbeddedAshService( |
23 return content::mojom::kBrowserServiceName; | 58 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 59 return base::MakeUnique<EmbeddedAshService>(task_runner); |
24 } | 60 } |
25 | 61 |
26 } // namespace ash_util | 62 } // namespace ash_util |
27 | 63 |
28 namespace chrome { | 64 namespace chrome { |
29 | 65 |
30 bool ShouldOpenAshOnStartup() { | 66 bool ShouldOpenAshOnStartup() { |
31 return !IsRunningInMash(); | 67 return !IsRunningInMash(); |
32 } | 68 } |
33 | 69 |
34 bool IsRunningInMash() { | 70 bool IsRunningInMash() { |
35 return service_manager::ServiceManagerIsRemote(); | 71 return service_manager::ServiceManagerIsRemote(); |
36 } | 72 } |
37 | 73 |
38 bool IsAcceleratorDeprecated(const ui::Accelerator& accelerator) { | 74 bool IsAcceleratorDeprecated(const ui::Accelerator& accelerator) { |
39 // When running in mash the browser doesn't handle ash accelerators. | 75 // When running in mash the browser doesn't handle ash accelerators. |
40 if (chrome::IsRunningInMash()) | 76 if (chrome::IsRunningInMash()) |
41 return false; | 77 return false; |
42 | 78 |
43 return ash::WmShell::Get()->accelerator_controller()->IsDeprecated( | 79 return ash::WmShell::Get()->accelerator_controller()->IsDeprecated( |
44 accelerator); | 80 accelerator); |
45 } | 81 } |
46 | 82 |
47 } // namespace chrome | 83 } // namespace chrome |
OLD | NEW |