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

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: Address comments in patchset 1 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
« no previous file with comments | « chromecast/chromecast.gyp ('k') | chromecast/net/connectivity_checker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {}
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 ~ConnectivityChecker() override;
60
61 private:
62 friend class base::RefCountedThreadSafe<ConnectivityChecker>;
63
64 // UrlRequest::Delegate implementation:
65 void OnResponseStarted(net::URLRequest* request) override;
66 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
67
68 // Initializes ConnectivityChecker
69 void Initialize();
70
71 // NetworkChangeNotifier::ConnectionTypeObserver implementation:
72 void OnConnectionTypeChanged(
73 net::NetworkChangeNotifier::ConnectionType type) override;
74
75 // Cancels current connectivity checking in progress.
76 void Cancel();
77
78 // Sets connectivity and alerts observers if it has changed
79 void SetConnectivity(bool connected);
80
81 scoped_ptr<GURL> connectivity_check_url_;
82 scoped_ptr<net::URLRequestContext> url_request_context_;
83 scoped_ptr<net::URLRequest> url_request_;
84 const scoped_refptr<ObserverListThreadSafe<ConnectivityObserver> >
85 connectivity_observer_list_;
86 const scoped_refptr<base::MessageLoopProxy> loop_proxy_;
87 bool connected_;
88 unsigned int bad_responses_;
89
90 DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker);
91 };
92
93 } // namespace chromecast
94
95 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_H_
OLDNEW
« no previous file with comments | « chromecast/chromecast.gyp ('k') | chromecast/net/connectivity_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698