Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: ash/mus/accelerator_registrar_impl.cc

Issue 2105653003: Fixes shutdown race in mash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/accelerator_registrar_impl.h ('k') | ash/mus/root_windows_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ash/mus/accelerator_registrar_impl.h" 5 #include "ash/mus/accelerator_registrar_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/mus/root_window_controller.h" 10 #include "ash/mus/root_window_controller.h"
(...skipping 17 matching lines...) Expand all
28 28
29 AcceleratorRegistrarImpl::AcceleratorRegistrarImpl( 29 AcceleratorRegistrarImpl::AcceleratorRegistrarImpl(
30 WindowManager* window_manager, 30 WindowManager* window_manager,
31 uint32_t accelerator_namespace, 31 uint32_t accelerator_namespace,
32 mojo::InterfaceRequest<AcceleratorRegistrar> request, 32 mojo::InterfaceRequest<AcceleratorRegistrar> request,
33 const DestroyCallback& destroy_callback) 33 const DestroyCallback& destroy_callback)
34 : window_manager_(window_manager), 34 : window_manager_(window_manager),
35 binding_(this, std::move(request)), 35 binding_(this, std::move(request)),
36 accelerator_namespace_(accelerator_namespace & 0xffff), 36 accelerator_namespace_(accelerator_namespace & 0xffff),
37 destroy_callback_(destroy_callback) { 37 destroy_callback_(destroy_callback) {
38 window_manager_->AddObserver(this);
38 binding_.set_connection_error_handler(base::Bind( 39 binding_.set_connection_error_handler(base::Bind(
39 &AcceleratorRegistrarImpl::OnBindingGone, base::Unretained(this))); 40 &AcceleratorRegistrarImpl::OnBindingGone, base::Unretained(this)));
40 } 41 }
41 42
42 void AcceleratorRegistrarImpl::Destroy() { 43 void AcceleratorRegistrarImpl::Destroy() {
43 delete this; 44 delete this;
44 } 45 }
45 46
46 bool AcceleratorRegistrarImpl::OwnsAccelerator(uint32_t accelerator_id) const { 47 bool AcceleratorRegistrarImpl::OwnsAccelerator(uint32_t accelerator_id) const {
47 return !!accelerators_.count(accelerator_id); 48 return !!accelerators_.count(accelerator_id);
48 } 49 }
49 50
50 void AcceleratorRegistrarImpl::ProcessAccelerator(uint32_t accelerator_id, 51 void AcceleratorRegistrarImpl::ProcessAccelerator(uint32_t accelerator_id,
51 const ui::Event& event) { 52 const ui::Event& event) {
52 DCHECK(OwnsAccelerator(accelerator_id)); 53 DCHECK(OwnsAccelerator(accelerator_id));
53 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map 54 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map
54 // mojom::Event directly to ui::Event. 55 // mojom::Event directly to ui::Event.
55 accelerator_handler_->OnAccelerator(accelerator_id & kAcceleratorIdMask, 56 accelerator_handler_->OnAccelerator(accelerator_id & kAcceleratorIdMask,
56 ui::Event::Clone(event)); 57 ui::Event::Clone(event));
57 } 58 }
58 59
59 AcceleratorRegistrarImpl::~AcceleratorRegistrarImpl() { 60 AcceleratorRegistrarImpl::~AcceleratorRegistrarImpl() {
61 window_manager_->RemoveObserver(this);
60 RemoveAllAccelerators(); 62 RemoveAllAccelerators();
61 destroy_callback_.Run(this); 63 destroy_callback_.Run(this);
62 } 64 }
63 65
64 uint32_t AcceleratorRegistrarImpl::ComputeAcceleratorId( 66 uint32_t AcceleratorRegistrarImpl::ComputeAcceleratorId(
65 uint32_t accelerator_id) const { 67 uint32_t accelerator_id) const {
66 return (accelerator_namespace_ << 16) | (accelerator_id & kAcceleratorIdMask); 68 return (accelerator_namespace_ << 16) | (accelerator_id & kAcceleratorIdMask);
67 } 69 }
68 70
69 void AcceleratorRegistrarImpl::OnBindingGone() { 71 void AcceleratorRegistrarImpl::OnBindingGone() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 window_manager_->window_manager_client()->RemoveAccelerator( 127 window_manager_->window_manager_client()->RemoveAccelerator(
126 namespaced_accelerator_id); 128 namespaced_accelerator_id);
127 129
128 // If the registrar is not bound anymore (i.e. the client can no longer 130 // If the registrar is not bound anymore (i.e. the client can no longer
129 // install new accelerators), and the last accelerator has been removed, then 131 // install new accelerators), and the last accelerator has been removed, then
130 // there's no point keeping this alive anymore. 132 // there's no point keeping this alive anymore.
131 if (accelerators_.empty() && !binding_.is_bound()) 133 if (accelerators_.empty() && !binding_.is_bound())
132 delete this; 134 delete this;
133 } 135 }
134 136
137 void AcceleratorRegistrarImpl::OnAccelerator(uint32_t id,
138 const ui::Event& event) {
139 if (OwnsAccelerator(id))
140 ProcessAccelerator(id, event);
141 }
142
143 void AcceleratorRegistrarImpl::OnWindowTreeClientDestroyed() {
144 delete this;
145 }
146
135 } // namespace mus 147 } // namespace mus
136 } // namespace ash 148 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/accelerator_registrar_impl.h ('k') | ash/mus/root_windows_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698