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

Side by Side Diff: mash/wm/accelerator_registrar_impl.cc

Issue 1550693002: Global conversion of Pass()→std::move() on Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 | « mash/example/window_type_launcher/main.cc ('k') | mash/wm/window_manager_application.cc » ('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 "mash/wm/accelerator_registrar_impl.h" 5 #include "mash/wm/accelerator_registrar_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "components/mus/public/interfaces/window_tree_host.mojom.h" 11 #include "components/mus/public/interfaces/window_tree_host.mojom.h"
11 12
12 namespace mash { 13 namespace mash {
13 namespace wm { 14 namespace wm {
14 15
15 namespace { 16 namespace {
16 const int kAcceleratorIdMask = 0xffff; 17 const int kAcceleratorIdMask = 0xffff;
17 } 18 }
18 19
19 AcceleratorRegistrarImpl::AcceleratorRegistrarImpl( 20 AcceleratorRegistrarImpl::AcceleratorRegistrarImpl(
20 mus::mojom::WindowTreeHost* host, 21 mus::mojom::WindowTreeHost* host,
21 uint32_t accelerator_namespace, 22 uint32_t accelerator_namespace,
22 mojo::InterfaceRequest<AcceleratorRegistrar> request, 23 mojo::InterfaceRequest<AcceleratorRegistrar> request,
23 const DestroyCallback& destroy_callback) 24 const DestroyCallback& destroy_callback)
24 : host_(host), 25 : host_(host),
25 binding_(this, request.Pass()), 26 binding_(this, std::move(request)),
26 accelerator_namespace_(accelerator_namespace & 0xffff), 27 accelerator_namespace_(accelerator_namespace & 0xffff),
27 destroy_callback_(destroy_callback) { 28 destroy_callback_(destroy_callback) {
28 binding_.set_connection_error_handler(base::Bind( 29 binding_.set_connection_error_handler(base::Bind(
29 &AcceleratorRegistrarImpl::OnBindingGone, base::Unretained(this))); 30 &AcceleratorRegistrarImpl::OnBindingGone, base::Unretained(this)));
30 } 31 }
31 32
32 AcceleratorRegistrarImpl::~AcceleratorRegistrarImpl() { 33 AcceleratorRegistrarImpl::~AcceleratorRegistrarImpl() {
33 for (uint32_t accelerator_id : accelerator_ids_) 34 for (uint32_t accelerator_id : accelerator_ids_)
34 host_->RemoveAccelerator(accelerator_id); 35 host_->RemoveAccelerator(accelerator_id);
35 destroy_callback_.Run(this); 36 destroy_callback_.Run(this);
36 } 37 }
37 38
38 bool AcceleratorRegistrarImpl::OwnsAccelerator(uint32_t accelerator_id) const { 39 bool AcceleratorRegistrarImpl::OwnsAccelerator(uint32_t accelerator_id) const {
39 return !!accelerator_ids_.count(accelerator_id); 40 return !!accelerator_ids_.count(accelerator_id);
40 } 41 }
41 42
42 void AcceleratorRegistrarImpl::ProcessAccelerator(uint32_t accelerator_id, 43 void AcceleratorRegistrarImpl::ProcessAccelerator(uint32_t accelerator_id,
43 mus::mojom::EventPtr event) { 44 mus::mojom::EventPtr event) {
44 DCHECK(OwnsAccelerator(accelerator_id)); 45 DCHECK(OwnsAccelerator(accelerator_id));
45 accelerator_handler_->OnAccelerator(accelerator_id & kAcceleratorIdMask, 46 accelerator_handler_->OnAccelerator(accelerator_id & kAcceleratorIdMask,
46 event.Pass()); 47 std::move(event));
47 } 48 }
48 49
49 uint32_t AcceleratorRegistrarImpl::ComputeAcceleratorId( 50 uint32_t AcceleratorRegistrarImpl::ComputeAcceleratorId(
50 uint32_t accelerator_id) const { 51 uint32_t accelerator_id) const {
51 return (accelerator_namespace_ << 16) | (accelerator_id & kAcceleratorIdMask); 52 return (accelerator_namespace_ << 16) | (accelerator_id & kAcceleratorIdMask);
52 } 53 }
53 54
54 void AcceleratorRegistrarImpl::OnBindingGone() { 55 void AcceleratorRegistrarImpl::OnBindingGone() {
55 binding_.Unbind(); 56 binding_.Unbind();
56 // If there's no outstanding accelerators for this connection, then destroy 57 // If there's no outstanding accelerators for this connection, then destroy
(...skipping 11 matching lines...) Expand all
68 delete this; 69 delete this;
69 return; 70 return;
70 } 71 }
71 accelerator_handler_.reset(); 72 accelerator_handler_.reset();
72 for (uint32_t accelerator_id : accelerator_ids_) 73 for (uint32_t accelerator_id : accelerator_ids_)
73 host_->RemoveAccelerator(accelerator_id); 74 host_->RemoveAccelerator(accelerator_id);
74 } 75 }
75 76
76 void AcceleratorRegistrarImpl::SetHandler( 77 void AcceleratorRegistrarImpl::SetHandler(
77 mus::mojom::AcceleratorHandlerPtr handler) { 78 mus::mojom::AcceleratorHandlerPtr handler) {
78 accelerator_handler_ = handler.Pass(); 79 accelerator_handler_ = std::move(handler);
79 accelerator_handler_.set_connection_error_handler(base::Bind( 80 accelerator_handler_.set_connection_error_handler(base::Bind(
80 &AcceleratorRegistrarImpl::OnHandlerGone, base::Unretained(this))); 81 &AcceleratorRegistrarImpl::OnHandlerGone, base::Unretained(this)));
81 } 82 }
82 83
83 void AcceleratorRegistrarImpl::AddAccelerator( 84 void AcceleratorRegistrarImpl::AddAccelerator(
84 uint32_t accelerator_id, 85 uint32_t accelerator_id,
85 mus::mojom::EventMatcherPtr matcher, 86 mus::mojom::EventMatcherPtr matcher,
86 const AddAcceleratorCallback& callback) { 87 const AddAcceleratorCallback& callback) {
87 if (!accelerator_handler_ || 88 if (!accelerator_handler_ ||
88 (accelerator_id & kAcceleratorIdMask) != accelerator_id) { 89 (accelerator_id & kAcceleratorIdMask) != accelerator_id) {
89 // The |accelerator_id| is too large, and it can't be handled correctly. 90 // The |accelerator_id| is too large, and it can't be handled correctly.
90 callback.Run(false); 91 callback.Run(false);
91 return; 92 return;
92 } 93 }
93 uint32_t namespaced_accelerator_id = ComputeAcceleratorId(accelerator_id); 94 uint32_t namespaced_accelerator_id = ComputeAcceleratorId(accelerator_id);
94 accelerator_ids_.insert(namespaced_accelerator_id); 95 accelerator_ids_.insert(namespaced_accelerator_id);
95 host_->AddAccelerator(namespaced_accelerator_id, matcher.Pass(), callback); 96 host_->AddAccelerator(namespaced_accelerator_id, std::move(matcher),
97 callback);
96 } 98 }
97 99
98 void AcceleratorRegistrarImpl::RemoveAccelerator(uint32_t accelerator_id) { 100 void AcceleratorRegistrarImpl::RemoveAccelerator(uint32_t accelerator_id) {
99 uint32_t namespaced_accelerator_id = ComputeAcceleratorId(accelerator_id); 101 uint32_t namespaced_accelerator_id = ComputeAcceleratorId(accelerator_id);
100 if (!accelerator_ids_.count(namespaced_accelerator_id)) 102 if (!accelerator_ids_.count(namespaced_accelerator_id))
101 return; 103 return;
102 host_->RemoveAccelerator(namespaced_accelerator_id); 104 host_->RemoveAccelerator(namespaced_accelerator_id);
103 accelerator_ids_.erase(namespaced_accelerator_id); 105 accelerator_ids_.erase(namespaced_accelerator_id);
104 // If the registrar is not bound anymore (i.e. the client can no longer 106 // If the registrar is not bound anymore (i.e. the client can no longer
105 // install new accelerators), and the last accelerator has been removed, then 107 // install new accelerators), and the last accelerator has been removed, then
106 // there's no point keeping this alive anymore. 108 // there's no point keeping this alive anymore.
107 if (accelerator_ids_.empty() && !binding_.is_bound()) 109 if (accelerator_ids_.empty() && !binding_.is_bound())
108 delete this; 110 delete this;
109 } 111 }
110 112
111 } // namespace wm 113 } // namespace wm
112 } // namespace mash 114 } // namespace mash
OLDNEW
« no previous file with comments | « mash/example/window_type_launcher/main.cc ('k') | mash/wm/window_manager_application.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698