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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/memory/memory_debugger_manager.mm
diff --git a/ios/chrome/browser/memory/memory_debugger_manager.mm b/ios/chrome/browser/memory/memory_debugger_manager.mm
new file mode 100644
index 0000000000000000000000000000000000000000..e9e9acbce275453808f15fdc09591526a9b8e942
--- /dev/null
+++ b/ios/chrome/browser/memory/memory_debugger_manager.mm
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/memory/memory_debugger_manager.h"
+
+#include "base/ios/weak_nsobject.h"
+#import "base/mac/bind_objc_block.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/prefs/pref_member.h"
+#include "base/prefs/pref_registry_simple.h"
+#include "base/prefs/pref_service.h"
+#import "ios/chrome/browser/memory/memory_debugger.h"
+#import "ios/chrome/browser/pref_names.h"
+
+@implementation MemoryDebuggerManager {
+ UIView* debuggerParentView_; // weak
+ base::scoped_nsobject<MemoryDebugger> memoryDebugger_;
+ BooleanPrefMember showMemoryDebugger_;
+}
+
+- (instancetype)initWithView:(UIView*)debuggerParentView
+ prefs:(PrefService*)prefs {
+ if (self = [super init]) {
+ debuggerParentView_ = debuggerParentView;
+
+ // Set up the callback for when the pref to show/hide the debugger changes.
+ base::WeakNSObject<MemoryDebuggerManager> weakSelf(self);
+ base::Closure callback = base::BindBlock(^{
+ base::scoped_nsobject<MemoryDebuggerManager> strongSelf(
+ [weakSelf retain]);
+ if (strongSelf) {
+ [self onShowMemoryDebuggingToolsChange];
+ }
+ });
+ showMemoryDebugger_.Init(prefs::kShowMemoryDebuggingTools, prefs, callback);
+ // Invoke the pref change callback once to show the debugger on start up,
+ // if necessary.
+ [self onShowMemoryDebuggingToolsChange];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [self tearDownDebugger];
+ [super dealloc];
+}
+
+#pragma mark - Pref-handling methods
+
+// Registers local state prefs.
++ (void)registerLocalState:(PrefRegistrySimple*)registry {
+ registry->RegisterBooleanPref(prefs::kShowMemoryDebuggingTools, false);
+}
+
+// Shows or hides the debugger when the pref changes.
+- (void)onShowMemoryDebuggingToolsChange {
+ if (showMemoryDebugger_.GetValue()) {
+ memoryDebugger_.reset([[MemoryDebugger alloc] init]);
+ [debuggerParentView_ addSubview:memoryDebugger_];
+ } else {
+ [self tearDownDebugger];
+ }
+}
+
+// Tears down the debugger so it can be deallocated.
+- (void)tearDownDebugger {
+ [memoryDebugger_ invalidateTimers];
+ [memoryDebugger_ removeFromSuperview];
+ memoryDebugger_.reset();
+}
+@end
« 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