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

Unified Diff: ios/chrome/app/chrome_overlay_window.mm

Issue 2580363002: Upstream Chrome on iOS source code [1/11]. (Closed)
Patch Set: Created 4 years 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/app/chrome_overlay_window.h ('k') | ios/chrome/app/chrome_overlay_window_testing.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/app/chrome_overlay_window.mm
diff --git a/ios/chrome/app/chrome_overlay_window.mm b/ios/chrome/app/chrome_overlay_window.mm
new file mode 100644
index 0000000000000000000000000000000000000000..7962b2088c416060be5fd2d230b8a100150cacd9
--- /dev/null
+++ b/ios/chrome/app/chrome_overlay_window.mm
@@ -0,0 +1,96 @@
+// Copyright 2015 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/app/chrome_overlay_window.h"
+
+#include "base/logging.h"
+#import "base/mac/scoped_nsobject.h"
+#import "ios/chrome/browser/crash_report/breakpad_helper.h"
+#import "ios/chrome/browser/metrics/size_class_recorder.h"
+#import "ios/chrome/browser/tabs/tab_model.h"
+#import "ios/chrome/browser/ui/ui_util.h"
+
+@interface ChromeOverlayWindow () {
+ base::scoped_nsobject<SizeClassRecorder> _recorder;
+}
+
+// Initializes the size class recorder. On iPad iOS 9+, it starts tracking
+// horizontal size class changes. Otherwise, it is a no-op.
+- (void)initializeRecorderIfNeeded;
+
+// Updates the Breakpad report with the current size class on iOS 8+. Otherwise,
+// it's a no-op since size class doesn't exist.
+- (void)updateBreakpad;
+
+@end
+
+@implementation ChromeOverlayWindow
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+ if (self) {
+ // When not created via a nib, create the recorder immediately.
+ [self initializeRecorderIfNeeded];
+ [self updateBreakpad];
+ }
+ return self;
+}
+
+- (void)awakeFromNib {
+ [super awakeFromNib];
+ // When creating via a nib, wait to be awoken, as the size class is not
+ // reliable before.
+ [self initializeRecorderIfNeeded];
+ [self updateBreakpad];
+}
+
+- (void)initializeRecorderIfNeeded {
+ DCHECK(!_recorder);
+ if (IsIPadIdiom()) {
+ _recorder.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:self.traitCollection.horizontalSizeClass]);
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(pageLoaded:)
+ name:kTabModelTabDidFinishLoadingNotification
+ object:nil];
+ }
+}
+
+- (void)updateBreakpad {
+ breakpad_helper::SetCurrentHorizontalSizeClass(
+ self.traitCollection.horizontalSizeClass);
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [super dealloc];
+}
+
+#pragma mark - UITraitEnvironment
+
+- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
+ [super traitCollectionDidChange:previousTraitCollection];
+ if (previousTraitCollection.horizontalSizeClass !=
+ self.traitCollection.horizontalSizeClass) {
+ [_recorder
+ horizontalSizeClassDidChange:self.traitCollection.horizontalSizeClass];
+ [self updateBreakpad];
+ }
+}
+
+#pragma mark - Notification handler
+
+- (void)pageLoaded:(NSNotification*)notification {
+ [_recorder pageLoadedWithHorizontalSizeClass:self.traitCollection
+ .horizontalSizeClass];
+}
+
+#pragma mark - Testing methods
+
+- (void)unsetSizeClassRecorder {
+ _recorder.reset();
+}
+
+@end
« no previous file with comments | « ios/chrome/app/chrome_overlay_window.h ('k') | ios/chrome/app/chrome_overlay_window_testing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698