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

Side by Side Diff: chromecast/net/connectivity_checker.h

Issue 925183003: [Chromecast] Add connectivity checking for Chromecast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 #ifndef CHROMECAST_NET_CONNECTIVITY_CHECKER_H_
6 #define CHROMECAST_NET_CONNECTIVITY_CHECKER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "net/base/network_change_notifier.h"
12 #include "net/url_request/url_request.h"
13
14 class GURL;
15
16 namespace base {
17 class MessageLoopProxy;
18 }
19
20 namespace net {
21 class URLRequestContext;
22 }
23
24 namespace chromecast {
25
26 // Simple class to check network connectivity by sending a HEAD http request
27 // to given url.
28 class ConnectivityChecker
29 : public base::RefCountedThreadSafe<ConnectivityChecker>,
30 public net::URLRequest::Delegate,
31 public net::NetworkChangeNotifier::ConnectionTypeObserver {
32 public:
33 class ConnectivityObserver {
34 public:
35 // Will be called when internet connectivity changes
36 virtual void OnConnectivityChanged(bool connected) = 0;
37
38 protected:
39 ConnectivityObserver() {}
40 virtual ~ConnectivityObserver() {};
byungchul 2015/02/20 01:32:39 ';' not necessary. And, as far as I know, 'virtua
derekjchow1 2015/02/20 02:24:17 Done. I removed the virtual keyword for the dtor
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(ConnectivityObserver);
44 };
45
46 explicit ConnectivityChecker(
47 const scoped_refptr<base::MessageLoopProxy>& loop_proxy);
48
49 void AddConnectivityObserver(ConnectivityObserver* observer);
50 void RemoveConnectivityObserver(ConnectivityObserver* observer);
51
52 // Returns if there is internet connectivity
53 bool Connected() const;
54
55 // Checks for connectivity
56 void Check();
57
58 protected:
59 // Empty constructor for test
gunsch 2015/02/20 01:56:03 alternately, make it private and add a protected
derekjchow1 2015/02/20 02:24:16 This actually isn't referenced now. Removed.
60 ConnectivityChecker();
61 ~ConnectivityChecker() override;
62
63 private:
64 friend class base::RefCountedThreadSafe<ConnectivityChecker>;
65
66 // UrlRequest::Delegate implementation:
67 void OnResponseStarted(net::URLRequest* request) override;
68 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
69
70 // Initializes ConnectivityChecker
71 void Initialize();
72
73 // NetworkChangeNotifier::ConnectionTypeObserver implementation:
74 void OnConnectionTypeChanged(
75 net::NetworkChangeNotifier::ConnectionType type) override;
76
77 // Cancels current connectivity checking in progress.
78 void Cancel();
79
80 // Sets connectivity and alerts observers if it has changed
81 void SetConnectivity(bool connected);
82
83 scoped_ptr<GURL> connectivity_check_url_;
84 scoped_ptr<net::URLRequestContext> url_request_context_;
85 scoped_ptr<net::URLRequest> url_request_;
86 const scoped_refptr<ObserverListThreadSafe<ConnectivityObserver> >
87 connectivity_observer_list_;
88 const scoped_refptr<base::MessageLoopProxy> loop_proxy_;
89 bool connected_;
90 unsigned int bad_responses_;
91
92 DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker);
93 };
94
95 } // namespace chromecast
96
97 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698