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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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/app/chrome_overlay_window.h"
6
7 #include "base/logging.h"
8 #import "base/mac/scoped_nsobject.h"
9 #import "ios/chrome/browser/crash_report/breakpad_helper.h"
10 #import "ios/chrome/browser/metrics/size_class_recorder.h"
11 #import "ios/chrome/browser/tabs/tab_model.h"
12 #import "ios/chrome/browser/ui/ui_util.h"
13
14 @interface ChromeOverlayWindow () {
15 base::scoped_nsobject<SizeClassRecorder> _recorder;
16 }
17
18 // Initializes the size class recorder. On iPad iOS 9+, it starts tracking
19 // horizontal size class changes. Otherwise, it is a no-op.
20 - (void)initializeRecorderIfNeeded;
21
22 // Updates the Breakpad report with the current size class on iOS 8+. Otherwise,
23 // it's a no-op since size class doesn't exist.
24 - (void)updateBreakpad;
25
26 @end
27
28 @implementation ChromeOverlayWindow
29
30 - (instancetype)initWithFrame:(CGRect)frame {
31 self = [super initWithFrame:frame];
32 if (self) {
33 // When not created via a nib, create the recorder immediately.
34 [self initializeRecorderIfNeeded];
35 [self updateBreakpad];
36 }
37 return self;
38 }
39
40 - (void)awakeFromNib {
41 [super awakeFromNib];
42 // When creating via a nib, wait to be awoken, as the size class is not
43 // reliable before.
44 [self initializeRecorderIfNeeded];
45 [self updateBreakpad];
46 }
47
48 - (void)initializeRecorderIfNeeded {
49 DCHECK(!_recorder);
50 if (IsIPadIdiom()) {
51 _recorder.reset([[SizeClassRecorder alloc]
52 initWithHorizontalSizeClass:self.traitCollection.horizontalSizeClass]);
53 [[NSNotificationCenter defaultCenter]
54 addObserver:self
55 selector:@selector(pageLoaded:)
56 name:kTabModelTabDidFinishLoadingNotification
57 object:nil];
58 }
59 }
60
61 - (void)updateBreakpad {
62 breakpad_helper::SetCurrentHorizontalSizeClass(
63 self.traitCollection.horizontalSizeClass);
64 }
65
66 - (void)dealloc {
67 [[NSNotificationCenter defaultCenter] removeObserver:self];
68 [super dealloc];
69 }
70
71 #pragma mark - UITraitEnvironment
72
73 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
74 [super traitCollectionDidChange:previousTraitCollection];
75 if (previousTraitCollection.horizontalSizeClass !=
76 self.traitCollection.horizontalSizeClass) {
77 [_recorder
78 horizontalSizeClassDidChange:self.traitCollection.horizontalSizeClass];
79 [self updateBreakpad];
80 }
81 }
82
83 #pragma mark - Notification handler
84
85 - (void)pageLoaded:(NSNotification*)notification {
86 [_recorder pageLoadedWithHorizontalSizeClass:self.traitCollection
87 .horizontalSizeClass];
88 }
89
90 #pragma mark - Testing methods
91
92 - (void)unsetSizeClassRecorder {
93 _recorder.reset();
94 }
95
96 @end
OLDNEW
« 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