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

Side by Side Diff: ios/chrome/app/startup/setup_debugging.mm

Issue 2863983002: DCHECK when loading images that do not exist. (Closed)
Patch Set: Ran downstream bots. Added more exceptions. Better logging. Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "ios/chrome/app/startup/setup_debugging.h" 5 #include "ios/chrome/app/startup/setup_debugging.h"
6 6
7 #include <objc/runtime.h>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/sys_string_conversions.h"
8 #include "components/crash/core/common/objc_zombie.h" 11 #include "components/crash/core/common/objc_zombie.h"
9 12
10 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support." 14 #error "This file requires ARC support."
12 #endif 15 #endif
13 16
17 namespace {
18
19 #ifndef NDEBUG
20
21 // Swizzles [UIImage imageNamed:] to trigger a DCHECK if an invalid image is
lpromero 2017/05/29 13:31:12 There are other methods for loading images. For ex
jif 2017/05/31 13:20:51 Correct! See https://bugs.chromium.org/p/chromium/
22 // attempted to be loaded.
23 void swizzleUIImageImageNamed() {
24 // Retained by the swizzle block.
25 NSMutableSet* whiteList = [NSMutableSet set];
26
27 // TODO(crbug.com/720337): Add missing image.
28 [whiteList addObject:@"card_close_button_pressed_incognito"];
29 // TODO(crbug.com/720355): Add missing image.
30 [whiteList addObject:@"find_close_pressed_incognito"];
31 // TODO(crbug.com/720338): Add missing images.
32 [whiteList addObject:@"glif-mic-to-dots-large_37"];
33 [whiteList addObject:@"glif-google-to-dots_28"];
34
pkl (ping after 24h if needed) 2017/05/11 22:28:41 When I run locally in debugger, I'm getting many D
35 // The original implementation of [UIImage imageNamed:].
36 // Called by the new implementation.
37 static IMP originalImp;
38 IMP* originalImpPtr = &originalImp;
39
40 id swizzleBlock = ^(id self, NSString* imageName) {
41 // Call the original [UIImage imageNamed:] method.
42 IMP imp = *originalImpPtr;
43 Class aClass = objc_getClass("UIImage");
44 UIImage* image = imp(aClass, @selector(imageNamed:), imageName);
45
46 if (![whiteList containsObject:imageName]) {
47 DCHECK(image) << "Missing image: " << base::SysNSStringToUTF8(imageName);
48 }
49 return image;
50 };
51
52 Method method = class_getClassMethod([UIImage class], @selector(imageNamed:));
53 DCHECK(method);
54
55 IMP blockImp = imp_implementationWithBlock(swizzleBlock);
56 originalImp = method_setImplementation(method, blockImp);
57 }
58
59 #endif
60
61 } // namespace
62
14 @implementation SetupDebugging 63 @implementation SetupDebugging
15 64
16 + (void)setUpDebuggingOptions { 65 + (void)setUpDebuggingOptions {
17 // Enable the zombie treadmill on simulator builds. 66 // Enable the zombie treadmill on simulator builds.
18 // TODO(crbug.com/663390): Consider enabling this on device builds too. 67 // TODO(crbug.com/663390): Consider enabling this on device builds too.
19 #if TARGET_IPHONE_SIMULATOR 68 #if TARGET_IPHONE_SIMULATOR
20 DCHECK(ObjcEvilDoers::ZombieEnable(true, 10000)); 69 DCHECK(ObjcEvilDoers::ZombieEnable(true, 10000));
21 #endif 70 #endif
71
72 // Enable the detection of missing image assets.
73 #ifndef NDEBUG
74 swizzleUIImageImageNamed();
75 #endif
22 } 76 }
23 77
24 @end 78 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698