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..461edefacadc1695f1127445b5276d903bdef30c 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,33 @@ |
_forwardingTargets[selector] = target; |
} |
+- (void)startDispatchingToTarget:(id)target forProtocol:(Protocol*)protocol { |
+ unsigned int methodCount; |
+ objc_method_description* requiredInstanceMethods = |
+ protocol_copyMethodDescriptionList(protocol, YES /* isRequiredMethod */, |
+ YES /* isInstanceMethod */, |
+ &methodCount); |
+ for (unsigned int i = 0; i < methodCount; i++) { |
+ [self startDispatchingToTarget:target |
+ forSelector:requiredInstanceMethods[i].name]; |
+ } |
+} |
+ |
- (void)stopDispatchingForSelector:(SEL)selector { |
_forwardingTargets.erase(selector); |
} |
+- (void)stopDispatchingForProtocol:(Protocol*)protocol { |
+ unsigned int methodCount; |
+ objc_method_description* requiredInstanceMethods = |
+ protocol_copyMethodDescriptionList(protocol, YES /* isRequiredMethod */, |
+ YES /* isInstanceMethod */, |
+ &methodCount); |
+ for (unsigned int i = 0; i < methodCount; 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. |