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

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

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

Powered by Google App Engine
This is Rietveld 408576698