OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/app/chrome_overlay_window.h" | 5 #import "ios/chrome/app/chrome_overlay_window.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/mac/scoped_nsobject.h" | |
9 #import "ios/chrome/browser/crash_report/breakpad_helper.h" | 8 #import "ios/chrome/browser/crash_report/breakpad_helper.h" |
10 #import "ios/chrome/browser/metrics/size_class_recorder.h" | 9 #import "ios/chrome/browser/metrics/size_class_recorder.h" |
11 #import "ios/chrome/browser/tabs/tab_model.h" | 10 #import "ios/chrome/browser/tabs/tab_model.h" |
12 #import "ios/chrome/browser/ui/ui_util.h" | 11 #import "ios/chrome/browser/ui/ui_util.h" |
13 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
14 @interface ChromeOverlayWindow () { | 17 @interface ChromeOverlayWindow () { |
15 base::scoped_nsobject<SizeClassRecorder> _recorder; | 18 SizeClassRecorder* _recorder; |
16 } | 19 } |
17 | 20 |
18 // Initializes the size class recorder. On iPad iOS 9+, it starts tracking | 21 // Initializes the size class recorder. On iPad iOS 9+, it starts tracking |
19 // horizontal size class changes. Otherwise, it is a no-op. | 22 // horizontal size class changes. Otherwise, it is a no-op. |
20 - (void)initializeRecorderIfNeeded; | 23 - (void)initializeRecorderIfNeeded; |
21 | 24 |
22 // Updates the Breakpad report with the current size class on iOS 8+. Otherwise, | 25 // 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. | 26 // it's a no-op since size class doesn't exist. |
24 - (void)updateBreakpad; | 27 - (void)updateBreakpad; |
25 | 28 |
(...skipping 15 matching lines...) Expand all Loading... |
41 [super awakeFromNib]; | 44 [super awakeFromNib]; |
42 // When creating via a nib, wait to be awoken, as the size class is not | 45 // When creating via a nib, wait to be awoken, as the size class is not |
43 // reliable before. | 46 // reliable before. |
44 [self initializeRecorderIfNeeded]; | 47 [self initializeRecorderIfNeeded]; |
45 [self updateBreakpad]; | 48 [self updateBreakpad]; |
46 } | 49 } |
47 | 50 |
48 - (void)initializeRecorderIfNeeded { | 51 - (void)initializeRecorderIfNeeded { |
49 DCHECK(!_recorder); | 52 DCHECK(!_recorder); |
50 if (IsIPadIdiom()) { | 53 if (IsIPadIdiom()) { |
51 _recorder.reset([[SizeClassRecorder alloc] | 54 _recorder = [[SizeClassRecorder alloc] |
52 initWithHorizontalSizeClass:self.traitCollection.horizontalSizeClass]); | 55 initWithHorizontalSizeClass:self.traitCollection.horizontalSizeClass]; |
53 [[NSNotificationCenter defaultCenter] | 56 [[NSNotificationCenter defaultCenter] |
54 addObserver:self | 57 addObserver:self |
55 selector:@selector(pageLoaded:) | 58 selector:@selector(pageLoaded:) |
56 name:kTabModelTabDidFinishLoadingNotification | 59 name:kTabModelTabDidFinishLoadingNotification |
57 object:nil]; | 60 object:nil]; |
58 } | 61 } |
59 } | 62 } |
60 | 63 |
61 - (void)updateBreakpad { | 64 - (void)updateBreakpad { |
62 breakpad_helper::SetCurrentHorizontalSizeClass( | 65 breakpad_helper::SetCurrentHorizontalSizeClass( |
63 self.traitCollection.horizontalSizeClass); | 66 self.traitCollection.horizontalSizeClass); |
64 } | 67 } |
65 | 68 |
66 - (void)dealloc { | 69 - (void)dealloc { |
67 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 70 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
68 [super dealloc]; | |
69 } | 71 } |
70 | 72 |
71 #pragma mark - UITraitEnvironment | 73 #pragma mark - UITraitEnvironment |
72 | 74 |
73 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { | 75 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { |
74 [super traitCollectionDidChange:previousTraitCollection]; | 76 [super traitCollectionDidChange:previousTraitCollection]; |
75 if (previousTraitCollection.horizontalSizeClass != | 77 if (previousTraitCollection.horizontalSizeClass != |
76 self.traitCollection.horizontalSizeClass) { | 78 self.traitCollection.horizontalSizeClass) { |
77 [_recorder | 79 [_recorder |
78 horizontalSizeClassDidChange:self.traitCollection.horizontalSizeClass]; | 80 horizontalSizeClassDidChange:self.traitCollection.horizontalSizeClass]; |
79 [self updateBreakpad]; | 81 [self updateBreakpad]; |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
83 #pragma mark - Notification handler | 85 #pragma mark - Notification handler |
84 | 86 |
85 - (void)pageLoaded:(NSNotification*)notification { | 87 - (void)pageLoaded:(NSNotification*)notification { |
86 [_recorder pageLoadedWithHorizontalSizeClass:self.traitCollection | 88 [_recorder pageLoadedWithHorizontalSizeClass:self.traitCollection |
87 .horizontalSizeClass]; | 89 .horizontalSizeClass]; |
88 } | 90 } |
89 | 91 |
90 #pragma mark - Testing methods | 92 #pragma mark - Testing methods |
91 | 93 |
92 - (void)unsetSizeClassRecorder { | 94 - (void)unsetSizeClassRecorder { |
93 _recorder.reset(); | 95 _recorder = nil; |
94 } | 96 } |
95 | 97 |
96 @end | 98 @end |
OLD | NEW |