Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2020 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#import "FirebasePerformance/Sources/Instrumentation/FPRInstrument.h"
16
#import "FirebasePerformance/Sources/Instrumentation/FPRInstrument_Private.h"
17
 
18
#import "FirebasePerformance/Sources/Common/FPRDiagnostics.h"
19
#import "FirebasePerformance/Sources/Instrumentation/FPRClassInstrumentor.h"
20
#import "FirebasePerformance/Sources/Instrumentation/FPRObjectInstrumentor.h"
21
 
22
@implementation FPRInstrument {
23
  NSMutableArray<FPRClassInstrumentor *> *_classInstrumentors;
24
 
25
  NSMutableSet<Class> *_instrumentedClasses;
26
}
27
 
28
- (instancetype)init {
29
  self = [super init];
30
  if (self) {
31
    _classInstrumentors = [[NSMutableArray<FPRClassInstrumentor *> alloc] init];
32
    _instrumentedClasses = [[NSMutableSet<Class> alloc] init];
33
  }
34
  return self;
35
}
36
 
37
- (NSMutableArray<FPRClassInstrumentor *> *)classInstrumentors {
38
  return _classInstrumentors;
39
}
40
 
41
- (NSMutableSet<Class> *)instrumentedClasses {
42
  return _instrumentedClasses;
43
}
44
 
45
- (void)registerInstrumentors {
46
  FPRAssert(NO, @"registerInstrumentors should be implemented in a concrete subclass.");
47
}
48
 
49
- (BOOL)isObjectInstrumentable:(id)object {
50
  if ([object isKindOfClass:[NSOperation class]]) {
51
    return NO;
52
  }
53
  return YES;
54
}
55
 
56
- (BOOL)registerClassInstrumentor:(FPRClassInstrumentor *)instrumentor {
57
  @synchronized(self) {
58
    if ([_instrumentedClasses containsObject:instrumentor.instrumentedClass] ||
59
        [instrumentor.instrumentedClass instancesRespondToSelector:@selector(gul_class)]) {
60
      return NO;
61
    }
62
    [_instrumentedClasses addObject:instrumentor.instrumentedClass];
63
    [_classInstrumentors addObject:instrumentor];
64
    return YES;
65
  }
66
}
67
 
68
- (void)deregisterInstrumentors {
69
  @synchronized(self) {
70
    for (FPRClassInstrumentor *classInstrumentor in self.classInstrumentors) {
71
      [classInstrumentor unswizzle];
72
    }
73
    [_classInstrumentors removeAllObjects];
74
    [_instrumentedClasses removeAllObjects];
75
  }
76
}
77
 
78
@end