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

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

Issue 2935653002: [ios clean] Move dispatcher out of Browser.
Patch Set: Dispatcher out of Browser. Created 3 years, 6 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/shared/chrome/browser/ui/commands/command_dispatcher.h" 5 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h"
6 6
7 #include <objc/runtime.h> 7 #include <objc/runtime.h>
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 13
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 15 #error "This file requires ARC support."
16 #endif 16 #endif
17 17
18 @implementation CommandDispatcher { 18 @implementation CommandDispatcher {
19 // Stores which target to forward to for a given selector. 19 // Stores which target to forward to for a given selector.
20 std::unordered_map<SEL, __weak id> _forwardingTargets; 20 std::unordered_map<SEL, __weak id> _forwardingTargets;
21 } 21 }
22 22
23 - (void)startDispatchingToTarget:(id)target forSelector:(SEL)selector { 23 - (void)startDispatchingToTarget:(id)target forSelector:(SEL)selector {
24 DCHECK(_forwardingTargets.find(selector) == _forwardingTargets.end()); 24 DCHECK(_forwardingTargets.find(selector) == _forwardingTargets.end())
25 << "Already dispatching to a target for "
26 << base::SysNSStringToUTF8(NSStringFromSelector(selector));
25 27
26 _forwardingTargets[selector] = target; 28 _forwardingTargets[selector] = target;
27 } 29 }
28 30
29 - (void)startDispatchingToTarget:(id)target forProtocol:(Protocol*)protocol { 31 - (void)startDispatchingToTarget:(id)target forProtocol:(Protocol*)protocol {
30 unsigned int methodCount; 32 unsigned int methodCount;
31 objc_method_description* requiredInstanceMethods = 33 objc_method_description* requiredInstanceMethods =
32 protocol_copyMethodDescriptionList(protocol, YES /* isRequiredMethod */, 34 protocol_copyMethodDescriptionList(protocol, YES /* isRequiredMethod */,
33 YES /* isInstanceMethod */, 35 YES /* isInstanceMethod */,
34 &methodCount); 36 &methodCount);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Overridden to forward messages to registered handlers. 76 // Overridden to forward messages to registered handlers.
75 - (id)forwardingTargetForSelector:(SEL)selector { 77 - (id)forwardingTargetForSelector:(SEL)selector {
76 auto target = _forwardingTargets.find(selector); 78 auto target = _forwardingTargets.find(selector);
77 if (target != _forwardingTargets.end()) { 79 if (target != _forwardingTargets.end()) {
78 return target->second; 80 return target->second;
79 } 81 }
80 return [super forwardingTargetForSelector:selector]; 82 return [super forwardingTargetForSelector:selector];
81 } 83 }
82 84
83 @end 85 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698