summaryrefslogtreecommitdiffstats
path: root/ios/net/clients/crn_forwarding_network_client_factory.mm
blob: f2c16d3863ad3f4632660766dadc05a50e50bdcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/net/clients/crn_forwarding_network_client_factory.h"

#include "base/mac/scoped_nsobject.h"
#include "base/memory/weak_ptr.h"
#import "ios/net/clients/crn_forwarding_network_client.h"

@implementation CRNForwardingNetworkClientFactory

// Init just sanity checks that the factory class has sane ordering rules.
- (instancetype)init {
  if ((self = [super init])) {
    // Type checks.
    DCHECK(![[self class] mustApplyBefore] ||
           [[[self class] mustApplyBefore]
               isSubclassOfClass:[CRNForwardingNetworkClientFactory class]]);
    DCHECK(![[self class] mustApplyAfter] ||
           [[[self class] mustApplyAfter]
               isSubclassOfClass:[CRNForwardingNetworkClientFactory class]]);
    // Order check.
    DCHECK([[self class] orderedOK]);
  }
  return self;
}

- (CRNForwardingNetworkClient*)clientHandlingAnyRequest {
  return nil;
}

- (CRNForwardingNetworkClient*)
    clientHandlingRequest:(const net::URLRequest&)request {
   return nil;
}

- (CRNForwardingNetworkClient*)
    clientHandlingResponse:(NSURLResponse*)response
                   request:(const net::URLRequest&)request {
  return nil;
}

- (CRNForwardingNetworkClient*)
    clientHandlingRedirect:(const net::URLRequest&)request
                       url:(const GURL&)url
                  response:(NSURLResponse*)response {
  return nil;
}

- (Class)clientClass {
  return nil;
}

+ (Class)mustApplyBefore {
  return nil;
}

+ (Class)mustApplyAfter {
  return nil;
}

- (BOOL)requiresOrdering {
  return [[self class] mustApplyAfter] || [[self class] mustApplyBefore];
}

// Verify that the ordering is sensible. If the calling class encounters itself
// walking dependencies in either direction, it's broken. If any of the classes
// it must appear after are also classes it must appear before, it's broken.
+ (BOOL)orderedOK {
  Class precursor = [self class];
  NSMutableArray* precursors = [NSMutableArray array];
  while ((precursor = [precursor mustApplyAfter])) {
    if (precursor == [self class])
      return NO;
    [precursors addObject:precursor];
  }
  id successor = [self class];
  while ((successor = [successor mustApplyBefore])) {
    if (successor == [self class])
      return NO;
    if ([precursors indexOfObject:successor] != NSNotFound)
      return NO;
  }
  return YES;
}

- (NSComparisonResult)
    orderRelativeTo:(CRNForwardingNetworkClientFactory*)factory {
  NSComparisonResult result = NSOrderedSame;
  if ([[self class] mustApplyBefore] == [factory class] ||
      [[factory class] mustApplyAfter] == [self class]) {
    result = NSOrderedAscending;
  }
  if ([[self class] mustApplyAfter] == [factory class] ||
      [[factory class] mustApplyBefore] == [self class]) {
    result = NSOrderedDescending;
  }
  return result;
}

@end