From d9fddc26832e6e93e0effa6fd1e0d23cb33c6136 Mon Sep 17 00:00:00 2001 From: derekjchow Date: Wed, 3 Jun 2015 11:15:46 -0700 Subject: [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} --- chromecast/net/connectivity_checker.cc | 6 ++++++ chromecast/net/connectivity_checker.h | 14 +++++++++----- chromecast/net/connectivity_checker_impl.cc | 3 +-- chromecast/net/connectivity_checker_impl.h | 2 -- 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::Create( const scoped_refptr& 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> - connectivity_observer_list_; + + // Notifies observes that connectivity has changed. + void Notify(bool connected); private: friend class base::RefCountedThreadSafe; + const scoped_refptr> + 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 connectivity_check_url_; scoped_ptr url_request_context_; scoped_ptr url_request_; - const scoped_refptr > - connectivity_observer_list_; const scoped_refptr 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 -- cgit v1.1