diff options
author | derekjchow <derekjchow@chromium.org> | 2015-06-03 11:15:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-03 18:16:30 +0000 |
commit | d9fddc26832e6e93e0effa6fd1e0d23cb33c6136 (patch) | |
tree | 0e79dc9ed5f340c0bef6f19b568cc155bf806727 | |
parent | f039c1c50995c628f1f642f696126711228947ff (diff) | |
download | chromium_src-d9fddc26832e6e93e0effa6fd1e0d23cb33c6136.zip chromium_src-d9fddc26832e6e93e0effa6fd1e0d23cb33c6136.tar.gz chromium_src-d9fddc26832e6e93e0effa6fd1e0d23cb33c6136.tar.bz2 |
[Chromecast] ConnectivityChecker improvements.
Remove redefinition of observer list in impl class. Move observer
list into private in base class and expose a protected Notify
method.
BUG=
R=gunsch@chromium.org,byungchul@chromium.org
Review URL: https://codereview.chromium.org/1169533002
Cr-Commit-Position: refs/heads/master@{#332643}
-rw-r--r-- | chromecast/net/connectivity_checker.cc | 6 | ||||
-rw-r--r-- | chromecast/net/connectivity_checker.h | 14 | ||||
-rw-r--r-- | chromecast/net/connectivity_checker_impl.cc | 3 | ||||
-rw-r--r-- | chromecast/net/connectivity_checker_impl.h | 2 | ||||
-rw-r--r-- | chromecast/net/fake_connectivity_checker.cc | 3 |
5 files changed, 17 insertions, 11 deletions
diff --git a/chromecast/net/connectivity_checker.cc b/chromecast/net/connectivity_checker.cc index 16417ab..873ab1e 100644 --- a/chromecast/net/connectivity_checker.cc +++ b/chromecast/net/connectivity_checker.cc @@ -26,6 +26,12 @@ void ConnectivityChecker::RemoveConnectivityObserver( connectivity_observer_list_->RemoveObserver(observer); } +void ConnectivityChecker::Notify(bool connected) { + DCHECK(connectivity_observer_list_.get()); + connectivity_observer_list_->Notify( + FROM_HERE, &ConnectivityObserver::OnConnectivityChanged, connected); +} + // static scoped_refptr<ConnectivityChecker> ConnectivityChecker::Create( const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { diff --git a/chromecast/net/connectivity_checker.h b/chromecast/net/connectivity_checker.h index 0c843a0..6225962 100644 --- a/chromecast/net/connectivity_checker.h +++ b/chromecast/net/connectivity_checker.h @@ -23,7 +23,7 @@ class ConnectivityChecker public: class ConnectivityObserver { public: - // Will be called when internet connectivity changes + // Will be called when internet connectivity changes. virtual void OnConnectivityChanged(bool connected) = 0; protected: @@ -42,20 +42,24 @@ class ConnectivityChecker void AddConnectivityObserver(ConnectivityObserver* observer); void RemoveConnectivityObserver(ConnectivityObserver* observer); - // Returns if there is internet connectivity + // Returns if there is internet connectivity. virtual bool Connected() const = 0; - // Checks for connectivity + // Checks for connectivity. virtual void Check() = 0; protected: virtual ~ConnectivityChecker(); - const scoped_refptr<base::ObserverListThreadSafe<ConnectivityObserver>> - connectivity_observer_list_; + + // Notifies observes that connectivity has changed. + void Notify(bool connected); private: friend class base::RefCountedThreadSafe<ConnectivityChecker>; + const scoped_refptr<ObserverListThreadSafe<ConnectivityObserver>> + connectivity_observer_list_; + DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker); }; diff --git a/chromecast/net/connectivity_checker_impl.cc b/chromecast/net/connectivity_checker_impl.cc index f17a73f..3ca50c1 100644 --- a/chromecast/net/connectivity_checker_impl.cc +++ b/chromecast/net/connectivity_checker_impl.cc @@ -81,8 +81,7 @@ void ConnectivityCheckerImpl::SetConnected(bool connected) { return; connected_ = connected; - connectivity_observer_list_->Notify( - FROM_HERE, &ConnectivityObserver::OnConnectivityChanged, connected); + Notify(connected); LOG(INFO) << "Global connection is: " << (connected ? "Up" : "Down"); } diff --git a/chromecast/net/connectivity_checker_impl.h b/chromecast/net/connectivity_checker_impl.h index 6ebe718..8bf4494 100644 --- a/chromecast/net/connectivity_checker_impl.h +++ b/chromecast/net/connectivity_checker_impl.h @@ -71,8 +71,6 @@ class ConnectivityCheckerImpl scoped_ptr<GURL> connectivity_check_url_; scoped_ptr<net::URLRequestContext> url_request_context_; scoped_ptr<net::URLRequest> url_request_; - const scoped_refptr<ObserverListThreadSafe<ConnectivityObserver> > - connectivity_observer_list_; const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; bool connected_; // Number of connectivity check errors. diff --git a/chromecast/net/fake_connectivity_checker.cc b/chromecast/net/fake_connectivity_checker.cc index 7b97d8a..fc3caed 100644 --- a/chromecast/net/fake_connectivity_checker.cc +++ b/chromecast/net/fake_connectivity_checker.cc @@ -25,8 +25,7 @@ void FakeConnectivityChecker::SetConnectedForTest(bool connected) { return; connected_ = connected; - connectivity_observer_list_->Notify( - FROM_HERE, &ConnectivityObserver::OnConnectivityChanged, connected); + Notify(connected); } } // namespace chromecast |