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

Unified Diff: ios/shared/chrome/browser/ui/commands/command_dispatcher.mm

Issue 2785153002: Add protocol APIs to CommandDispatcher. (Closed)
Patch Set: Feedback Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698