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

Side by Side Diff: ios/clean/chrome/browser/ui/omnibox/location_bar_mediator.mm

Issue 2820493002: Use a scoped WebStateListObserverBridge. (Closed)
Patch Set: Feedback Created 3 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
« no previous file with comments | « no previous file | ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/clean/chrome/browser/ui/omnibox/location_bar_mediator.h" 5 #import "ios/clean/chrome/browser/ui/omnibox/location_bar_mediator.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/scoped_observer.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" 10 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h"
10 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" 11 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h"
11 #include "ios/chrome/browser/web_state_list/web_state_list.h" 12 #include "ios/chrome/browser/web_state_list/web_state_list.h"
12 #include "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h" 13 #include "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
13 #import "ios/shared/chrome/browser/ui/omnibox/location_bar_controller.h" 14 #import "ios/shared/chrome/browser/ui/omnibox/location_bar_controller.h"
14 #import "ios/web/public/navigation_manager.h" 15 #import "ios/web/public/navigation_manager.h"
15 #import "ios/web/public/web_state/web_state.h" 16 #import "ios/web/public/web_state/web_state.h"
16 #import "ios/web/public/web_state/web_state_observer_bridge.h" 17 #import "ios/web/public/web_state/web_state_observer_bridge.h"
17 18
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 19 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 20 #error "This file requires ARC support."
20 #endif 21 #endif
21 22
22 @interface LocationBarMediator ()<CRWWebStateObserver, 23 @interface LocationBarMediator ()<CRWWebStateObserver,
23 LocationBarDelegate, 24 LocationBarDelegate,
24 WebStateListObserving> 25 WebStateListObserving>
25 @property(nonatomic, readwrite, assign) WebStateList* webStateList; 26 @property(nonatomic, readwrite, assign) WebStateList* webStateList;
26 @end 27 @end
27 28
28 @implementation LocationBarMediator { 29 @implementation LocationBarMediator {
29 // Observes the WebStateList so that this mediator can update the UI when the 30 // Observes the WebStateList so that this mediator can update the UI when the
30 // active WebState changes. 31 // active WebState changes.
31 std::unique_ptr<WebStateListObserverBridge> _webStateListObserver; 32 std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
33 std::unique_ptr<ScopedObserver<WebStateList, WebStateListObserverBridge>>
34 _scopedWebStateListObserver;
32 35
33 // Used to update the UI in response to WebState observer notifications. This 36 // Used to update the UI in response to WebState observer notifications. This
34 // observer is always observing the currently-active WebState and may be 37 // observer is always observing the currently-active WebState and may be
35 // nullptr if no WebState is currently active. 38 // nullptr if no WebState is currently active.
36 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; 39 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
37 40
38 // The LocationBarController that wraps OmniboxViewIOS and 41 // The LocationBarController that wraps OmniboxViewIOS and
39 // OmniboxTextFieldIOS. This mediator updates the UI through |_locationBar| 42 // OmniboxTextFieldIOS. This mediator updates the UI through |_locationBar|
40 // rather than through a consumer. 43 // rather than through a consumer.
41 std::unique_ptr<LocationBarController> _locationBar; 44 std::unique_ptr<LocationBarController> _locationBar;
42 45
43 // The ToolbarModelDelegate, backed by |_webStateList|. 46 // The ToolbarModelDelegate, backed by |_webStateList|.
44 std::unique_ptr<ToolbarModelDelegateIOS> _toolbarModelDelegate; 47 std::unique_ptr<ToolbarModelDelegateIOS> _toolbarModelDelegate;
45 48
46 // The ToolbarModel that backs |_locationBar|. 49 // The ToolbarModel that backs |_locationBar|.
47 std::unique_ptr<ToolbarModelImplIOS> _toolbarModel; 50 std::unique_ptr<ToolbarModelImplIOS> _toolbarModel;
48 } 51 }
49 52
50 @synthesize webStateList = _webStateList; 53 @synthesize webStateList = _webStateList;
51 54
52 - (instancetype)initWithWebStateList:(WebStateList*)webStateList { 55 - (instancetype)initWithWebStateList:(WebStateList*)webStateList {
53 if ((self = [super init])) { 56 if ((self = [super init])) {
54 _webStateList = webStateList; 57 _webStateList = webStateList;
55 58
56 _webStateListObserver = base::MakeUnique<WebStateListObserverBridge>(self); 59 _webStateListObserver = base::MakeUnique<WebStateListObserverBridge>(self);
57 _webStateList->AddObserver(_webStateListObserver.get()); 60 _scopedWebStateListObserver = base::MakeUnique<
61 ScopedObserver<WebStateList, WebStateListObserverBridge>>(
62 _webStateListObserver.get());
63 _scopedWebStateListObserver->Add(_webStateList);
58 web::WebState* webState = _webStateList->GetActiveWebState(); 64 web::WebState* webState = _webStateList->GetActiveWebState();
59 if (webState) { 65 if (webState) {
60 _webStateObserver = 66 _webStateObserver =
61 base::MakeUnique<web::WebStateObserverBridge>(webState, self); 67 base::MakeUnique<web::WebStateObserverBridge>(webState, self);
62 } 68 }
63 69
64 _toolbarModelDelegate = 70 _toolbarModelDelegate =
65 base::MakeUnique<ToolbarModelDelegateIOS>(webStateList); 71 base::MakeUnique<ToolbarModelDelegateIOS>(webStateList);
66 _toolbarModel = 72 _toolbarModel =
67 base::MakeUnique<ToolbarModelImplIOS>(_toolbarModelDelegate.get()); 73 base::MakeUnique<ToolbarModelImplIOS>(_toolbarModelDelegate.get());
68 } 74 }
69 return self; 75 return self;
70 } 76 }
71 77
72 - (void)dealloc {
73 _webStateList->RemoveObserver(_webStateListObserver.get());
74 }
75
76 - (void)setLocationBar:(std::unique_ptr<LocationBarController>)locationBar { 78 - (void)setLocationBar:(std::unique_ptr<LocationBarController>)locationBar {
77 _locationBar = std::move(locationBar); 79 _locationBar = std::move(locationBar);
78 _locationBar->OnToolbarUpdated(); 80 _locationBar->OnToolbarUpdated();
79 } 81 }
80 82
81 #pragma mark - LocationBarDelegate 83 #pragma mark - LocationBarDelegate
82 84
83 - (void)loadGURLFromLocationBar:(const GURL&)url 85 - (void)loadGURLFromLocationBar:(const GURL&)url
84 transition:(ui::PageTransition)transition { 86 transition:(ui::PageTransition)transition {
85 web::WebState* webState = _webStateList->GetActiveWebState(); 87 web::WebState* webState = _webStateList->GetActiveWebState();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 184
183 - (void)webStateDidChangeVisibleSecurityState:(web::WebState*)webState { 185 - (void)webStateDidChangeVisibleSecurityState:(web::WebState*)webState {
184 _locationBar->OnToolbarUpdated(); 186 _locationBar->OnToolbarUpdated();
185 } 187 }
186 188
187 - (void)webStateDestroyed:(web::WebState*)webState { 189 - (void)webStateDestroyed:(web::WebState*)webState {
188 _webStateObserver = nullptr; 190 _webStateObserver = nullptr;
189 } 191 }
190 192
191 @end 193 @end
OLDNEW
« no previous file with comments | « no previous file | ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698