| 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/FPRObjectInstrumentor.h"
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           #import "FirebasePerformance/Sources/Common/FPRDiagnostics.h"
  | 
        
        
            | 
            | 
           18 | 
           #import "FirebasePerformance/Sources/Instrumentation/FPRInstrument_Private.h"
  | 
        
        
            | 
            | 
           19 | 
           #import "FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.h"
  | 
        
        
            | 
            | 
           20 | 
              | 
        
        
            | 
            | 
           21 | 
           #import <GoogleUtilities/GULObjectSwizzler.h>
  | 
        
        
            | 
            | 
           22 | 
              | 
        
        
            | 
            | 
           23 | 
           @interface FPRObjectInstrumentor () {
  | 
        
        
            | 
            | 
           24 | 
             // The object swizzler instance this instrumentor will use.
  | 
        
        
            | 
            | 
           25 | 
             GULObjectSwizzler *_objectSwizzler;
  | 
        
        
            | 
            | 
           26 | 
           }
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
           @end
  | 
        
        
            | 
            | 
           29 | 
              | 
        
        
            | 
            | 
           30 | 
           @implementation FPRObjectInstrumentor
  | 
        
        
            | 
            | 
           31 | 
              | 
        
        
            | 
            | 
           32 | 
           - (instancetype)init {
  | 
        
        
            | 
            | 
           33 | 
             FPRAssert(NO, @"%@: Please use the designated initializer.", NSStringFromClass([self class]));
  | 
        
        
            | 
            | 
           34 | 
             return nil;
  | 
        
        
            | 
            | 
           35 | 
           }
  | 
        
        
            | 
            | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
           - (instancetype)initWithObject:(id)object {
  | 
        
        
            | 
            | 
           38 | 
             self = [super init];
  | 
        
        
            | 
            | 
           39 | 
             if (self) {
  | 
        
        
            | 
            | 
           40 | 
               _objectSwizzler = [[GULObjectSwizzler alloc] initWithObject:object];
  | 
        
        
            | 
            | 
           41 | 
               _instrumentedObject = object;
  | 
        
        
            | 
            | 
           42 | 
             }
  | 
        
        
            | 
            | 
           43 | 
             return self;
  | 
        
        
            | 
            | 
           44 | 
           }
  | 
        
        
            | 
            | 
           45 | 
              | 
        
        
            | 
            | 
           46 | 
           - (void)copySelector:(SEL)selector fromClass:(Class)aClass isClassSelector:(BOOL)isClassSelector {
  | 
        
        
            | 
            | 
           47 | 
             __strong id instrumentedObject = _instrumentedObject;
  | 
        
        
            | 
            | 
           48 | 
             if (instrumentedObject && ![instrumentedObject respondsToSelector:selector]) {
  | 
        
        
            | 
            | 
           49 | 
               _hasModifications = YES;
  | 
        
        
            | 
            | 
           50 | 
               [_objectSwizzler copySelector:selector fromClass:aClass isClassSelector:isClassSelector];
  | 
        
        
            | 
            | 
           51 | 
             }
  | 
        
        
            | 
            | 
           52 | 
           }
  | 
        
        
            | 
            | 
           53 | 
              | 
        
        
            | 
            | 
           54 | 
           - (void)swizzle {
  | 
        
        
            | 
            | 
           55 | 
             if (_hasModifications) {
  | 
        
        
            | 
            | 
           56 | 
               [_objectSwizzler swizzle];
  | 
        
        
            | 
            | 
           57 | 
             }
  | 
        
        
            | 
            | 
           58 | 
           }
  | 
        
        
            | 
            | 
           59 | 
              | 
        
        
            | 
            | 
           60 | 
           @end
  |