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

Side by Side Diff: ios/chrome/browser/web/auto_reload_bridge.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/web/auto_reload_bridge.h"
6
7 #include <memory>
8
9 #include "base/ios/weak_nsobject.h"
10 #include "base/mac/scoped_nsobject.h"
11 #include "net/base/network_change_notifier.h"
12
13 namespace {
14 class NetworkChangeObserverBridge;
15 } // namespace
16
17 @interface AutoReloadBridge () {
18 base::WeakNSObject<Tab> _tab;
19 base::scoped_nsobject<AutoReloadController> _controller;
20 std::unique_ptr<NetworkChangeObserverBridge> _networkBridge;
21 }
22
23 // This method is called by NetworkChangeObserverBridge to indicate that the
24 // device's connected state changed to |online|.
25 - (void)networkStateChangedToOnline:(BOOL)online;
26
27 @end
28
29 namespace {
30
31 class NetworkChangeObserverBridge
32 : public net::NetworkChangeNotifier::NetworkChangeObserver {
33 public:
34 explicit NetworkChangeObserverBridge(AutoReloadBridge* bridge)
35 : bridge_(bridge) {}
36 ~NetworkChangeObserverBridge() override {}
37
38 void OnNetworkChanged(
39 net::NetworkChangeNotifier::ConnectionType type) override {
40 bool online = type == net::NetworkChangeNotifier::CONNECTION_NONE;
41 [bridge_ networkStateChangedToOnline:online];
42 }
43
44 private:
45 AutoReloadBridge* bridge_;
46 };
47
48 } // namespace
49
50 @implementation AutoReloadBridge
51
52 - (instancetype)initWithTab:(Tab*)tab {
53 DCHECK(tab);
54 if ((self = [super init])) {
55 BOOL online = !net::NetworkChangeNotifier::IsOffline();
56 _tab.reset(tab);
57 _controller.reset([[AutoReloadController alloc] initWithDelegate:self
58 onlineStatus:online]);
59 _networkBridge.reset(new NetworkChangeObserverBridge(self));
60 }
61 return self;
62 }
63
64 - (void)loadStartedForURL:(const GURL&)url {
65 [_controller loadStartedForURL:url];
66 }
67
68 - (void)loadFinishedForURL:(const GURL&)url wasPost:(BOOL)wasPost {
69 [_controller loadFinishedForURL:url wasPost:wasPost];
70 }
71
72 - (void)loadFailedForURL:(const GURL&)url wasPost:(BOOL)wasPost {
73 [_controller loadFailedForURL:url wasPost:wasPost];
74 }
75
76 - (void)networkStateChangedToOnline:(BOOL)online {
77 [_controller networkStateChangedToOnline:online];
78 }
79
80 #pragma mark AutoReloadDelegate methods
81
82 - (void)reload {
83 [_tab reload];
84 }
85
86 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/auto_reload_bridge.h ('k') | ios/chrome/browser/web/auto_reload_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698