OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/net/clients/crn_forwarding_network_client_factory.h" |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #import "ios/net/clients/crn_forwarding_network_client.h" |
| 10 |
| 11 @implementation CRNForwardingNetworkClientFactory |
| 12 |
| 13 // Init just sanity checks that the factory class has sane ordering rules. |
| 14 - (instancetype)init { |
| 15 if ((self = [super init])) { |
| 16 // Type checks. |
| 17 DCHECK(![[self class] mustApplyBefore] || |
| 18 [[[self class] mustApplyBefore] |
| 19 isSubclassOfClass:[CRNForwardingNetworkClientFactory class]]); |
| 20 DCHECK(![[self class] mustApplyAfter] || |
| 21 [[[self class] mustApplyAfter] |
| 22 isSubclassOfClass:[CRNForwardingNetworkClientFactory class]]); |
| 23 // Order check. |
| 24 DCHECK([[self class] orderedOK]); |
| 25 } |
| 26 return self; |
| 27 } |
| 28 |
| 29 - (CRNForwardingNetworkClient*)clientHandlingAnyRequest { |
| 30 return nil; |
| 31 } |
| 32 |
| 33 - (CRNForwardingNetworkClient*) |
| 34 clientHandlingRequest:(const net::URLRequest&)request { |
| 35 return nil; |
| 36 } |
| 37 |
| 38 - (CRNForwardingNetworkClient*) |
| 39 clientHandlingResponse:(NSURLResponse*)response |
| 40 request:(const net::URLRequest&)request { |
| 41 return nil; |
| 42 } |
| 43 |
| 44 - (CRNForwardingNetworkClient*) |
| 45 clientHandlingRedirect:(const net::URLRequest&)request |
| 46 url:(const GURL&)url |
| 47 response:(NSURLResponse*)response { |
| 48 return nil; |
| 49 } |
| 50 |
| 51 - (Class)clientClass { |
| 52 return nil; |
| 53 } |
| 54 |
| 55 + (Class)mustApplyBefore { |
| 56 return nil; |
| 57 } |
| 58 |
| 59 + (Class)mustApplyAfter { |
| 60 return nil; |
| 61 } |
| 62 |
| 63 - (BOOL)requiresOrdering { |
| 64 return [[self class] mustApplyAfter] || [[self class] mustApplyBefore]; |
| 65 } |
| 66 |
| 67 // Verify that the ordering is sensible. If the calling class encounters itself |
| 68 // walking dependencies in either direction, it's broken. If any of the classes |
| 69 // it must appear after are also classes it must appear before, it's broken. |
| 70 + (BOOL)orderedOK { |
| 71 Class precursor = [self class]; |
| 72 NSMutableArray* precursors = [NSMutableArray array]; |
| 73 while ((precursor = [precursor mustApplyAfter])) { |
| 74 if (precursor == [self class]) |
| 75 return NO; |
| 76 [precursors addObject:precursor]; |
| 77 } |
| 78 id successor = [self class]; |
| 79 while ((successor = [successor mustApplyBefore])) { |
| 80 if (successor == [self class]) |
| 81 return NO; |
| 82 if ([precursors indexOfObject:successor] != NSNotFound) |
| 83 return NO; |
| 84 } |
| 85 return YES; |
| 86 } |
| 87 |
| 88 - (NSComparisonResult) |
| 89 orderRelativeTo:(CRNForwardingNetworkClientFactory*)factory { |
| 90 NSComparisonResult result = NSOrderedSame; |
| 91 if ([[self class] mustApplyBefore] == [factory class] || |
| 92 [[factory class] mustApplyAfter] == [self class]) { |
| 93 result = NSOrderedAscending; |
| 94 } |
| 95 if ([[self class] mustApplyAfter] == [factory class] || |
| 96 [[factory class] mustApplyBefore] == [self class]) { |
| 97 result = NSOrderedDescending; |
| 98 } |
| 99 return result; |
| 100 } |
| 101 |
| 102 @end |
OLD | NEW |