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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/app/startup/setup_debugging.mm
diff --git a/ios/chrome/app/startup/setup_debugging.mm b/ios/chrome/app/startup/setup_debugging.mm
index d918ccb836971567d2034d6cf317a53de7340921..7410a46d0cbae0196c8699fd1e7b4a30252f9d22 100644
--- a/ios/chrome/app/startup/setup_debugging.mm
+++ b/ios/chrome/app/startup/setup_debugging.mm
@@ -4,13 +4,62 @@
#include "ios/chrome/app/startup/setup_debugging.h"
+#include <objc/runtime.h>
+
#include "base/logging.h"
+#include "base/strings/sys_string_conversions.h"
#include "components/crash/core/common/objc_zombie.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
+namespace {
+
+#ifndef NDEBUG
+
+// 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/
+// attempted to be loaded.
+void swizzleUIImageImageNamed() {
+ // Retained by the swizzle block.
+ NSMutableSet* whiteList = [NSMutableSet set];
+
+ // TODO(crbug.com/720337): Add missing image.
+ [whiteList addObject:@"card_close_button_pressed_incognito"];
+ // TODO(crbug.com/720355): Add missing image.
+ [whiteList addObject:@"find_close_pressed_incognito"];
+ // TODO(crbug.com/720338): Add missing images.
+ [whiteList addObject:@"glif-mic-to-dots-large_37"];
+ [whiteList addObject:@"glif-google-to-dots_28"];
+
pkl (ping after 24h if needed) 2017/05/11 22:28:41 When I run locally in debugger, I'm getting many D
+ // The original implementation of [UIImage imageNamed:].
+ // Called by the new implementation.
+ static IMP originalImp;
+ IMP* originalImpPtr = &originalImp;
+
+ id swizzleBlock = ^(id self, NSString* imageName) {
+ // Call the original [UIImage imageNamed:] method.
+ IMP imp = *originalImpPtr;
+ Class aClass = objc_getClass("UIImage");
+ UIImage* image = imp(aClass, @selector(imageNamed:), imageName);
+
+ if (![whiteList containsObject:imageName]) {
+ DCHECK(image) << "Missing image: " << base::SysNSStringToUTF8(imageName);
+ }
+ return image;
+ };
+
+ Method method = class_getClassMethod([UIImage class], @selector(imageNamed:));
+ DCHECK(method);
+
+ IMP blockImp = imp_implementationWithBlock(swizzleBlock);
+ originalImp = method_setImplementation(method, blockImp);
+}
+
+#endif
+
+} // namespace
+
@implementation SetupDebugging
+ (void)setUpDebuggingOptions {
@@ -19,6 +68,11 @@ + (void)setUpDebuggingOptions {
#if TARGET_IPHONE_SIMULATOR
DCHECK(ObjcEvilDoers::ZombieEnable(true, 10000));
#endif
+
+// Enable the detection of missing image assets.
+#ifndef NDEBUG
+ swizzleUIImageImageNamed();
+#endif
}
@end
« 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