OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "ios/chrome/browser/web/auto_reload_bridge.h" | 5 #include "ios/chrome/browser/web/auto_reload_bridge.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/ios/weak_nsobject.h" | |
10 #include "base/mac/scoped_nsobject.h" | |
11 #import "ios/chrome/browser/tabs/tab.h" | 9 #import "ios/chrome/browser/tabs/tab.h" |
12 #import "ios/web/public/navigation_manager.h" | 10 #import "ios/web/public/navigation_manager.h" |
13 #include "net/base/network_change_notifier.h" | 11 #include "net/base/network_change_notifier.h" |
14 | 12 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
14 #error "This file requires ARC support." | |
15 #endif | |
16 | |
15 namespace { | 17 namespace { |
16 class NetworkChangeObserverBridge; | 18 class NetworkChangeObserverBridge; |
17 } // namespace | 19 } // namespace |
18 | 20 |
19 @interface AutoReloadBridge () { | 21 @interface AutoReloadBridge () { |
20 base::WeakNSObject<Tab> _tab; | 22 __weak Tab* _tab; |
21 base::scoped_nsobject<AutoReloadController> _controller; | 23 AutoReloadController* _controller; |
22 std::unique_ptr<NetworkChangeObserverBridge> _networkBridge; | 24 std::unique_ptr<NetworkChangeObserverBridge> _networkBridge; |
23 } | 25 } |
24 | 26 |
25 // This method is called by NetworkChangeObserverBridge to indicate that the | 27 // This method is called by NetworkChangeObserverBridge to indicate that the |
26 // device's connected state changed to |online|. | 28 // device's connected state changed to |online|. |
27 - (void)networkStateChangedToOnline:(BOOL)online; | 29 - (void)networkStateChangedToOnline:(BOOL)online; |
28 | 30 |
29 @end | 31 @end |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 class NetworkChangeObserverBridge | 35 class NetworkChangeObserverBridge |
34 : public net::NetworkChangeNotifier::NetworkChangeObserver { | 36 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
35 public: | 37 public: |
36 explicit NetworkChangeObserverBridge(AutoReloadBridge* bridge) | 38 explicit NetworkChangeObserverBridge(AutoReloadBridge* bridge) |
37 : bridge_(bridge) {} | 39 : bridge_(bridge) {} |
38 ~NetworkChangeObserverBridge() override {} | 40 ~NetworkChangeObserverBridge() override {} |
39 | 41 |
40 void OnNetworkChanged( | 42 void OnNetworkChanged( |
41 net::NetworkChangeNotifier::ConnectionType type) override { | 43 net::NetworkChangeNotifier::ConnectionType type) override { |
42 bool online = type == net::NetworkChangeNotifier::CONNECTION_NONE; | 44 bool online = type == net::NetworkChangeNotifier::CONNECTION_NONE; |
43 [bridge_ networkStateChangedToOnline:online]; | 45 [bridge_ networkStateChangedToOnline:online]; |
44 } | 46 } |
45 | 47 |
46 private: | 48 private: |
47 AutoReloadBridge* bridge_; | 49 AutoReloadBridge* bridge_; |
stkhapugin
2017/04/19 16:42:34
This went from __unsafe_unretained to __strong, is
gambard
2017/04/20 08:31:40
Done.
| |
48 }; | 50 }; |
49 | 51 |
50 } // namespace | 52 } // namespace |
51 | 53 |
52 @implementation AutoReloadBridge | 54 @implementation AutoReloadBridge |
53 | 55 |
54 - (instancetype)initWithTab:(Tab*)tab { | 56 - (instancetype)initWithTab:(Tab*)tab { |
55 DCHECK(tab); | 57 DCHECK(tab); |
56 if ((self = [super init])) { | 58 if ((self = [super init])) { |
57 BOOL online = !net::NetworkChangeNotifier::IsOffline(); | 59 BOOL online = !net::NetworkChangeNotifier::IsOffline(); |
58 _tab.reset(tab); | 60 _tab = tab; |
59 _controller.reset([[AutoReloadController alloc] initWithDelegate:self | 61 _controller = [[AutoReloadController alloc] initWithDelegate:self |
60 onlineStatus:online]); | 62 onlineStatus:online]; |
61 _networkBridge.reset(new NetworkChangeObserverBridge(self)); | 63 _networkBridge.reset(new NetworkChangeObserverBridge(self)); |
62 } | 64 } |
63 return self; | 65 return self; |
64 } | 66 } |
65 | 67 |
66 - (void)loadStartedForURL:(const GURL&)url { | 68 - (void)loadStartedForURL:(const GURL&)url { |
67 [_controller loadStartedForURL:url]; | 69 [_controller loadStartedForURL:url]; |
68 } | 70 } |
69 | 71 |
70 - (void)loadFinishedForURL:(const GURL&)url wasPost:(BOOL)wasPost { | 72 - (void)loadFinishedForURL:(const GURL&)url wasPost:(BOOL)wasPost { |
71 [_controller loadFinishedForURL:url wasPost:wasPost]; | 73 [_controller loadFinishedForURL:url wasPost:wasPost]; |
72 } | 74 } |
73 | 75 |
74 - (void)loadFailedForURL:(const GURL&)url wasPost:(BOOL)wasPost { | 76 - (void)loadFailedForURL:(const GURL&)url wasPost:(BOOL)wasPost { |
75 [_controller loadFailedForURL:url wasPost:wasPost]; | 77 [_controller loadFailedForURL:url wasPost:wasPost]; |
76 } | 78 } |
77 | 79 |
78 - (void)networkStateChangedToOnline:(BOOL)online { | 80 - (void)networkStateChangedToOnline:(BOOL)online { |
79 [_controller networkStateChangedToOnline:online]; | 81 [_controller networkStateChangedToOnline:online]; |
80 } | 82 } |
81 | 83 |
82 #pragma mark AutoReloadDelegate methods | 84 #pragma mark AutoReloadDelegate methods |
83 | 85 |
84 - (void)reload { | 86 - (void)reload { |
85 [_tab navigationManager]->Reload(web::ReloadType::NORMAL, | 87 [_tab navigationManager]->Reload(web::ReloadType::NORMAL, |
86 false /* check_for_repost */); | 88 false /* check_for_repost */); |
87 } | 89 } |
88 | 90 |
89 @end | 91 @end |
OLD | NEW |