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

Side by Side Diff: ios/chrome/browser/memory/memory_debugger_manager.mm

Issue 2917193002: [ObjC ARC] Converts ios/chrome/browser/memory:memory to ARC. (Closed)
Patch Set: Use __weak Created 3 years, 6 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 | « ios/chrome/browser/memory/memory_debugger.mm ('k') | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ios/chrome/browser/memory/memory_debugger_manager.h" 5 #import "ios/chrome/browser/memory/memory_debugger_manager.h"
6 6
7 #include "base/ios/weak_nsobject.h"
8 #import "base/mac/bind_objc_block.h" 7 #import "base/mac/bind_objc_block.h"
9 #include "base/mac/scoped_nsobject.h"
10 #include "components/prefs/pref_member.h" 8 #include "components/prefs/pref_member.h"
11 #include "components/prefs/pref_registry_simple.h" 9 #include "components/prefs/pref_registry_simple.h"
12 #include "components/prefs/pref_service.h" 10 #include "components/prefs/pref_service.h"
13 #import "ios/chrome/browser/memory/memory_debugger.h" 11 #import "ios/chrome/browser/memory/memory_debugger.h"
14 #import "ios/chrome/browser/pref_names.h" 12 #import "ios/chrome/browser/pref_names.h"
15 13
14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support."
16 #endif
17
16 @implementation MemoryDebuggerManager { 18 @implementation MemoryDebuggerManager {
17 __unsafe_unretained UIView* debuggerParentView_; // weak 19 __weak UIView* debuggerParentView_;
18 base::scoped_nsobject<MemoryDebugger> memoryDebugger_; 20 MemoryDebugger* memoryDebugger_;
19 BooleanPrefMember showMemoryDebugger_; 21 BooleanPrefMember showMemoryDebugger_;
20 } 22 }
21 23
22 - (instancetype)initWithView:(UIView*)debuggerParentView 24 - (instancetype)initWithView:(UIView*)debuggerParentView
23 prefs:(PrefService*)prefs { 25 prefs:(PrefService*)prefs {
24 if (self = [super init]) { 26 if (self = [super init]) {
25 debuggerParentView_ = debuggerParentView; 27 debuggerParentView_ = debuggerParentView;
26 28
27 // Set up the callback for when the pref to show/hide the debugger changes. 29 // Set up the callback for when the pref to show/hide the debugger changes.
28 base::WeakNSObject<MemoryDebuggerManager> weakSelf(self); 30 __weak MemoryDebuggerManager* weakSelf = self;
29 base::Closure callback = base::BindBlock(^{ 31 base::Closure callback = base::BindBlockArc(^{
30 base::scoped_nsobject<MemoryDebuggerManager> strongSelf( 32 MemoryDebuggerManager* strongSelf = weakSelf;
31 [weakSelf retain]);
32 if (strongSelf) { 33 if (strongSelf) {
33 [self onShowMemoryDebuggingToolsChange]; 34 [self onShowMemoryDebuggingToolsChange];
34 } 35 }
35 }); 36 });
36 showMemoryDebugger_.Init(prefs::kShowMemoryDebuggingTools, prefs, callback); 37 showMemoryDebugger_.Init(prefs::kShowMemoryDebuggingTools, prefs, callback);
37 // Invoke the pref change callback once to show the debugger on start up, 38 // Invoke the pref change callback once to show the debugger on start up,
38 // if necessary. 39 // if necessary.
39 [self onShowMemoryDebuggingToolsChange]; 40 [self onShowMemoryDebuggingToolsChange];
40 } 41 }
41 return self; 42 return self;
42 } 43 }
43 44
44 - (void)dealloc { 45 - (void)dealloc {
45 [self tearDownDebugger]; 46 [self tearDownDebugger];
46 [super dealloc];
47 } 47 }
48 48
49 #pragma mark - Pref-handling methods 49 #pragma mark - Pref-handling methods
50 50
51 // Registers local state prefs. 51 // Registers local state prefs.
52 + (void)registerLocalState:(PrefRegistrySimple*)registry { 52 + (void)registerLocalState:(PrefRegistrySimple*)registry {
53 registry->RegisterBooleanPref(prefs::kShowMemoryDebuggingTools, false); 53 registry->RegisterBooleanPref(prefs::kShowMemoryDebuggingTools, false);
54 } 54 }
55 55
56 // Shows or hides the debugger when the pref changes. 56 // Shows or hides the debugger when the pref changes.
57 - (void)onShowMemoryDebuggingToolsChange { 57 - (void)onShowMemoryDebuggingToolsChange {
58 if (showMemoryDebugger_.GetValue()) { 58 if (showMemoryDebugger_.GetValue()) {
59 memoryDebugger_.reset([[MemoryDebugger alloc] init]); 59 memoryDebugger_ = [[MemoryDebugger alloc] init];
60 [debuggerParentView_ addSubview:memoryDebugger_]; 60 [debuggerParentView_ addSubview:memoryDebugger_];
61 } else { 61 } else {
62 [self tearDownDebugger]; 62 [self tearDownDebugger];
63 } 63 }
64 } 64 }
65 65
66 // Tears down the debugger so it can be deallocated. 66 // Tears down the debugger so it can be deallocated.
67 - (void)tearDownDebugger { 67 - (void)tearDownDebugger {
68 [memoryDebugger_ invalidateTimers]; 68 [memoryDebugger_ invalidateTimers];
69 [memoryDebugger_ removeFromSuperview]; 69 [memoryDebugger_ removeFromSuperview];
70 memoryDebugger_.reset(); 70 memoryDebugger_ = nil;
71 } 71 }
72 @end 72 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/memory/memory_debugger.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698