Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/clean/chrome/browser/ui/commands/command_dispatcher.h" | |
| 6 | |
| 7 #include <unordered_map> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 | |
|
lpromero
2017/03/07 10:04:17
Missing ARC header.
rohitrao (ping after 24h)
2017/03/09 14:41:11
We should add this to boilerplate.py =)
sdefresne
2017/03/09 15:38:07
This has already been done (https://codereview.chr
lpromero
2017/03/09 16:16:30
Well, Sylvain has struck again! https://codereview
| |
| 12 @implementation CommandDispatcher { | |
| 13 std::unordered_map<SEL, __weak id> _forwardingTargets; | |
| 14 } | |
| 15 | |
| 16 - (void)registerTarget:(id)target forSelector:(SEL)selector { | |
| 17 DCHECK(_forwardingTargets.find(selector) == _forwardingTargets.end()); | |
| 18 | |
| 19 _forwardingTargets[selector] = target; | |
| 20 } | |
| 21 | |
| 22 - (void)stopDispatchingForTarget:(id)target { | |
| 23 std::vector<SEL> selectorsToErase; | |
|
sdefresne
2017/03/06 22:32:59
I'm wondering whether using C++ algorithms is simp
rohitrao (ping after 24h)
2017/03/09 14:41:11
Kept my original code but changed it to a range-ba
sdefresne
2017/03/09 15:38:07
Looks better, thank you.
| |
| 24 for (auto it = _forwardingTargets.begin(); it != _forwardingTargets.end(); | |
| 25 ++it) { | |
| 26 if (it->second == target) { | |
| 27 selectorsToErase.push_back(it->first); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 for (auto* selector : selectorsToErase) { | |
| 32 _forwardingTargets.erase(selector); | |
| 33 } | |
| 34 } | |
| 35 | |
|
lpromero
2017/03/07 10:04:17
#pragma mark - NSObject
to signify that this is a
rohitrao (ping after 24h)
2017/03/09 14:41:11
Done.
| |
| 36 - (id)forwardingTargetForSelector:(SEL)selector { | |
| 37 auto target = _forwardingTargets.find(selector); | |
| 38 if (target != _forwardingTargets.end()) { | |
| 39 return target->second; | |
| 40 } | |
| 41 return nil; | |
|
sdefresne
2017/03/06 22:32:59
I think we should NOTREACHED() here as this will g
rohitrao (ping after 24h)
2017/03/07 18:53:58
I can't put a check here, because this object will
sdefresne
2017/03/07 19:12:35
Ack. We'll have to watch for those uncaught Object
rohitrao (ping after 24h)
2017/03/09 14:41:11
Let's revisit this in a few days. I can try to ad
| |
| 42 } | |
| 43 | |
| 44 @end | |
| OLD | NEW |