Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromecast / net / connectivity_checker.h
blobfcfb878bde3f2cc974cfa23d421d834e43afebd2
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.
5 #ifndef CHROMECAST_NET_CONNECTIVITY_CHECKER_H_
6 #define CHROMECAST_NET_CONNECTIVITY_CHECKER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list_threadsafe.h"
12 class GURL;
14 namespace base {
15 class SingleThreadTaskRunner;
18 namespace chromecast {
20 // Checks if internet connectivity is available.
21 class ConnectivityChecker
22 : public base::RefCountedThreadSafe<ConnectivityChecker> {
23 public:
24 class ConnectivityObserver {
25 public:
26 // Will be called when internet connectivity changes.
27 virtual void OnConnectivityChanged(bool connected) = 0;
29 protected:
30 ConnectivityObserver() {}
31 virtual ~ConnectivityObserver() {}
33 private:
34 DISALLOW_COPY_AND_ASSIGN(ConnectivityObserver);
37 static scoped_refptr<ConnectivityChecker> Create(
38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
40 ConnectivityChecker();
42 void AddConnectivityObserver(ConnectivityObserver* observer);
43 void RemoveConnectivityObserver(ConnectivityObserver* observer);
45 // Returns if there is internet connectivity.
46 virtual bool Connected() const = 0;
48 // Checks for connectivity.
49 virtual void Check() = 0;
51 protected:
52 virtual ~ConnectivityChecker();
54 // Notifies observes that connectivity has changed.
55 void Notify(bool connected);
57 private:
58 friend class base::RefCountedThreadSafe<ConnectivityChecker>;
60 const scoped_refptr<base::ObserverListThreadSafe<ConnectivityObserver>>
61 connectivity_observer_list_;
63 DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker);
66 } // namespace chromecast
68 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_H_