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

Side by Side Diff: ios/clean/chrome/browser/ui/commands/command_dispatcher.mm

Issue 2766663002: Rename CommandDispatcher method to start dispatching. (Closed)
Patch Set: s/For/To Created 3 years, 9 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 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 #import "ios/clean/chrome/browser/ui/commands/command_dispatcher.h" 5 #import "ios/clean/chrome/browser/ui/commands/command_dispatcher.h"
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 12
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 14 #error "This file requires ARC support."
15 #endif 15 #endif
16 16
17 @implementation CommandDispatcher { 17 @implementation CommandDispatcher {
18 // Stores which target to forward to for a given selector. 18 // Stores which target to forward to for a given selector.
19 std::unordered_map<SEL, __weak id> _forwardingTargets; 19 std::unordered_map<SEL, __weak id> _forwardingTargets;
20 } 20 }
21 21
22 - (void)registerTarget:(id)target forSelector:(SEL)selector { 22 - (void)startDispatchingToTarget:(id)target forSelector:(SEL)selector {
23 DCHECK(_forwardingTargets.find(selector) == _forwardingTargets.end()); 23 DCHECK(_forwardingTargets.find(selector) == _forwardingTargets.end());
24 24
25 _forwardingTargets[selector] = target; 25 _forwardingTargets[selector] = target;
26 } 26 }
27 27
28 // |-stopDispatchingForTarget| should be called much less often than 28 // |-stopDispatchingToTarget| should be called much less often than
29 // |-forwardingTargetForSelector|, so removal is intentionally O(n) in order 29 // |-forwardingTargetForSelector|, so removal is intentionally O(n) in order
30 // to prioritize the speed of lookups. 30 // to prioritize the speed of lookups.
31 - (void)stopDispatchingForTarget:(id)target { 31 - (void)stopDispatchingToTarget:(id)target {
32 std::vector<SEL> selectorsToErase; 32 std::vector<SEL> selectorsToErase;
33 for (auto& kv : _forwardingTargets) { 33 for (auto& kv : _forwardingTargets) {
34 if (kv.second == target) { 34 if (kv.second == target) {
35 selectorsToErase.push_back(kv.first); 35 selectorsToErase.push_back(kv.first);
36 } 36 }
37 } 37 }
38 38
39 for (auto* selector : selectorsToErase) { 39 for (auto* selector : selectorsToErase) {
40 _forwardingTargets.erase(selector); 40 _forwardingTargets.erase(selector);
41 } 41 }
42 } 42 }
43 43
44 #pragma mark - NSObject 44 #pragma mark - NSObject
45 45
46 // Overridden to forward messages to registered handlers. 46 // Overridden to forward messages to registered handlers.
47 - (id)forwardingTargetForSelector:(SEL)selector { 47 - (id)forwardingTargetForSelector:(SEL)selector {
48 auto target = _forwardingTargets.find(selector); 48 auto target = _forwardingTargets.find(selector);
49 if (target != _forwardingTargets.end()) { 49 if (target != _forwardingTargets.end()) {
50 return target->second; 50 return target->second;
51 } 51 }
52 return [super forwardingTargetForSelector:selector]; 52 return [super forwardingTargetForSelector:selector];
53 } 53 }
54 54
55 @end 55 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698