Chromium Code Reviews| Index: ios/shared/chrome/browser/ui/commands/command_dispatcher.mm |
| diff --git a/ios/shared/chrome/browser/ui/commands/command_dispatcher.mm b/ios/shared/chrome/browser/ui/commands/command_dispatcher.mm |
| index a3c12f8e54835ddbcb1a41b0c2e503e6d0772809..9543da14adb4bcf11592b3b4a013d70b6ca04cde 100644 |
| --- a/ios/shared/chrome/browser/ui/commands/command_dispatcher.mm |
| +++ b/ios/shared/chrome/browser/ui/commands/command_dispatcher.mm |
| @@ -4,6 +4,7 @@ |
| #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
| +#include <objc/runtime.h> |
| #include <unordered_map> |
| #include <vector> |
| @@ -25,10 +26,31 @@ |
| _forwardingTargets[selector] = target; |
| } |
| +- (void)startDispatchingToTarget:(id)target forProtocol:(Protocol*)protocol { |
| + unsigned int outCount; |
|
marq (ping after 24h)
2017/03/30 14:03:55
Prefer method_count, here and below.
lpromero
2017/03/30 15:00:39
Would methodCount work?
marq (ping after 24h)
2017/03/31 07:43:01
Yes, sorry; I'm working on similar code inside a C
lpromero
2017/04/04 13:08:52
Done.
|
| + objc_method_description* requiredInstanceMethods = |
| + protocol_copyMethodDescriptionList(protocol, YES /* isRequiredMethod */, |
| + YES /* isInstanceMethod */, &outCount); |
| + for (unsigned int i = 0; i < outCount; i++) { |
| + [self startDispatchingToTarget:target |
| + forSelector:requiredInstanceMethods[i].name]; |
| + } |
|
marq (ping after 24h)
2017/03/30 14:03:55
What about protocols the protocol adheres to? (wit
lpromero
2017/03/30 15:00:39
I started this CL to basically raise all these que
marq (ping after 24h)
2017/03/31 07:43:01
Clearly either of these calls are just convenience
lpromero
2017/04/04 13:08:52
Done.
|
| +} |
| + |
| - (void)stopDispatchingForSelector:(SEL)selector { |
| _forwardingTargets.erase(selector); |
| } |
| +- (void)stopDispatchingForProtocol:(Protocol*)protocol { |
| + unsigned int outCount; |
| + objc_method_description* requiredInstanceMethods = |
| + protocol_copyMethodDescriptionList(protocol, YES /* isRequiredMethod */, |
| + YES /* isInstanceMethod */, &outCount); |
| + for (unsigned int i = 0; i < outCount; i++) { |
| + [self stopDispatchingForSelector:requiredInstanceMethods[i].name]; |
| + } |
| +} |
| + |
| // |-stopDispatchingToTarget| should be called much less often than |
| // |-forwardingTargetForSelector|, so removal is intentionally O(n) in order |
| // to prioritize the speed of lookups. |