Commit 0d5c00d8 authored by fgorski's avatar fgorski Committed by Commit bot

[GCM] Extracting GCMConnectionObserver from GCMAppHandler

Extracting GCMConnectionObserver from GCMAppHandler
* Updating consuming code: GCMInvalidationBridge
* Updating GCMAppHandler overrides
* Updating tests for GCMDriverDesktop

BUG=407841
R=jianli@chromium.org

Review URL: https://codereview.chromium.org/515763002

Cr-Commit-Position: refs/heads/master@{#292396}
parent d9b32ee8
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
'gcm_driver/gcm_client_factory.h', 'gcm_driver/gcm_client_factory.h',
'gcm_driver/gcm_client_impl.cc', 'gcm_driver/gcm_client_impl.cc',
'gcm_driver/gcm_client_impl.h', 'gcm_driver/gcm_client_impl.h',
'gcm_driver/gcm_connection_observer.cc',
'gcm_driver/gcm_connection_observer.h',
'gcm_driver/gcm_driver.cc', 'gcm_driver/gcm_driver.cc',
'gcm_driver/gcm_driver.h', 'gcm_driver/gcm_driver.h',
'gcm_driver/gcm_driver_android.cc', 'gcm_driver/gcm_driver_android.cc',
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "components/gcm_driver/default_gcm_app_handler.h" #include "components/gcm_driver/default_gcm_app_handler.h"
#include "base/logging.h" #include "base/logging.h"
#include "net/base/ip_endpoint.h"
namespace gcm { namespace gcm {
...@@ -42,14 +41,4 @@ void DefaultGCMAppHandler::OnSendAcknowledged(const std::string& app_id, ...@@ -42,14 +41,4 @@ void DefaultGCMAppHandler::OnSendAcknowledged(const std::string& app_id,
<< app_id; << app_id;
} }
void DefaultGCMAppHandler::OnConnected(const net::IPEndPoint& ip_endpoint) {
// TODO(semenzato): update CrOS NIC state.
DVLOG(1) << "GCM connected to " << ip_endpoint.ToString();
}
void DefaultGCMAppHandler::OnDisconnected() {
// TODO(semenzato): update CrOS NIC state.
DVLOG(1) << "GCM disconnected";
}
} // namespace gcm } // namespace gcm
...@@ -27,8 +27,6 @@ class DefaultGCMAppHandler : public GCMAppHandler { ...@@ -27,8 +27,6 @@ class DefaultGCMAppHandler : public GCMAppHandler {
const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; const GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
virtual void OnSendAcknowledged(const std::string& app_id, virtual void OnSendAcknowledged(const std::string& app_id,
const std::string& message_id) OVERRIDE; const std::string& message_id) OVERRIDE;
virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE;
virtual void OnDisconnected() OVERRIDE;
private: private:
DISALLOW_COPY_AND_ASSIGN(DefaultGCMAppHandler); DISALLOW_COPY_AND_ASSIGN(DefaultGCMAppHandler);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace gcm { namespace gcm {
FakeGCMAppHandler::FakeGCMAppHandler() FakeGCMAppHandler::FakeGCMAppHandler()
: received_event_(NO_EVENT), connected_(false) { : received_event_(NO_EVENT) {
} }
FakeGCMAppHandler::~FakeGCMAppHandler() { FakeGCMAppHandler::~FakeGCMAppHandler() {
...@@ -71,12 +71,4 @@ void FakeGCMAppHandler::ClearResults() { ...@@ -71,12 +71,4 @@ void FakeGCMAppHandler::ClearResults() {
send_error_details_ = GCMClient::SendErrorDetails(); send_error_details_ = GCMClient::SendErrorDetails();
} }
void FakeGCMAppHandler::OnConnected(const net::IPEndPoint& ip_endpoint) {
connected_ = true;
}
void FakeGCMAppHandler::OnDisconnected() {
connected_ = false;
}
} // namespace gcm } // namespace gcm
...@@ -34,7 +34,6 @@ class FakeGCMAppHandler : public GCMAppHandler { ...@@ -34,7 +34,6 @@ class FakeGCMAppHandler : public GCMAppHandler {
const GCMClient::SendErrorDetails& send_error_details() const { const GCMClient::SendErrorDetails& send_error_details() const {
return send_error_details_; return send_error_details_;
} }
bool connected() const { return connected_; }
void WaitForNotification(); void WaitForNotification();
...@@ -48,8 +47,6 @@ class FakeGCMAppHandler : public GCMAppHandler { ...@@ -48,8 +47,6 @@ class FakeGCMAppHandler : public GCMAppHandler {
const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; const GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
virtual void OnSendAcknowledged(const std::string& app_id, virtual void OnSendAcknowledged(const std::string& app_id,
const std::string& message_id) OVERRIDE; const std::string& message_id) OVERRIDE;
virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE;
virtual void OnDisconnected() OVERRIDE;
private: private:
void ClearResults(); void ClearResults();
...@@ -61,7 +58,6 @@ class FakeGCMAppHandler : public GCMAppHandler { ...@@ -61,7 +58,6 @@ class FakeGCMAppHandler : public GCMAppHandler {
std::string acked_message_id_; std::string acked_message_id_;
GCMClient::IncomingMessage message_; GCMClient::IncomingMessage message_;
GCMClient::SendErrorDetails send_error_details_; GCMClient::SendErrorDetails send_error_details_;
bool connected_;
DISALLOW_COPY_AND_ASSIGN(FakeGCMAppHandler); DISALLOW_COPY_AND_ASSIGN(FakeGCMAppHandler);
}; };
......
...@@ -28,6 +28,12 @@ void FakeGCMDriver::OnSignedIn() { ...@@ -28,6 +28,12 @@ void FakeGCMDriver::OnSignedIn() {
void FakeGCMDriver::Purge() { void FakeGCMDriver::Purge() {
} }
void FakeGCMDriver::AddConnectionObserver(GCMConnectionObserver* observer) {
}
void FakeGCMDriver::RemoveConnectionObserver(GCMConnectionObserver* observer) {
}
void FakeGCMDriver::Enable() { void FakeGCMDriver::Enable() {
} }
......
...@@ -23,6 +23,9 @@ class FakeGCMDriver : public GCMDriver { ...@@ -23,6 +23,9 @@ class FakeGCMDriver : public GCMDriver {
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
virtual void OnSignedIn() OVERRIDE; virtual void OnSignedIn() OVERRIDE;
virtual void Purge() OVERRIDE; virtual void Purge() OVERRIDE;
virtual void AddConnectionObserver(GCMConnectionObserver* observer) OVERRIDE;
virtual void RemoveConnectionObserver(
GCMConnectionObserver* observer) OVERRIDE;
virtual void Enable() OVERRIDE; virtual void Enable() OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual GCMClient* GetGCMClientForTesting() const OVERRIDE; virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
......
...@@ -9,12 +9,6 @@ namespace gcm { ...@@ -9,12 +9,6 @@ namespace gcm {
GCMAppHandler::GCMAppHandler() {} GCMAppHandler::GCMAppHandler() {}
GCMAppHandler::~GCMAppHandler() {} GCMAppHandler::~GCMAppHandler() {}
void GCMAppHandler::OnConnected(const net::IPEndPoint& ip_endpoint) {
}
void GCMAppHandler::OnDisconnected() {
}
bool GCMAppHandler::CanHandle(const std::string& app_id) const { bool GCMAppHandler::CanHandle(const std::string& app_id) const {
return false; return false;
} }
......
...@@ -40,16 +40,6 @@ class GCMAppHandler { ...@@ -40,16 +40,6 @@ class GCMAppHandler {
virtual void OnSendAcknowledged(const std::string& app_id, virtual void OnSendAcknowledged(const std::string& app_id,
const std::string& message_id) = 0; const std::string& message_id) = 0;
// Called when a new connection is established and a successful handshake
// has been performed. Note that |ip_endpoint| is only set if available for
// the current platform.
// Default implementation does nothing.
virtual void OnConnected(const net::IPEndPoint& ip_endpoint);
// Called when the connection is interrupted.
// Default implementation does nothing.
virtual void OnDisconnected();
// If no app handler has been added with the exact app_id of an incoming // If no app handler has been added with the exact app_id of an incoming
// event, all handlers will be asked (in arbitrary order) whether they can // event, all handlers will be asked (in arbitrary order) whether they can
// handle the app_id, and the first to return true will receive the event. // handle the app_id, and the first to return true will receive the event.
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/gcm_driver/gcm_connection_observer.h"
namespace gcm {
GCMConnectionObserver::GCMConnectionObserver() {}
GCMConnectionObserver::~GCMConnectionObserver() {}
void GCMConnectionObserver::OnConnected(const net::IPEndPoint& ip_endpoint) {
}
void GCMConnectionObserver::OnDisconnected() {
}
} // namespace gcm
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_GCM_DRIVER_GCM_CONNECTION_OBSERVER_H_
#define COMPONENTS_GCM_DRIVER_GCM_CONNECTION_OBSERVER_H_
#include "base/basictypes.h"
namespace net {
class IPEndPoint;
}
namespace gcm {
// Interface for objects observing GCM connection events.
class GCMConnectionObserver {
public:
GCMConnectionObserver();
virtual ~GCMConnectionObserver();
// Called when a new connection is established and a successful handshake
// has been performed. Note that |ip_endpoint| is only set if available for
// the current platform.
// Default implementation does nothing.
virtual void OnConnected(const net::IPEndPoint& ip_endpoint);
// Called when the connection is interrupted.
// Default implementation does nothing.
virtual void OnDisconnected();
};
} // namespace gcm
#endif // COMPONENTS_GCM_DRIVER_GCM_CONNECTION_OBSERVER_H_
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
namespace gcm { namespace gcm {
class GCMAppHandler; class GCMAppHandler;
class GCMConnectionObserver;
struct AccountMapping; struct AccountMapping;
// Bridge between GCM users in Chrome and the platform-specific implementation. // Bridge between GCM users in Chrome and the platform-specific implementation.
...@@ -88,6 +89,12 @@ class GCMDriver { ...@@ -88,6 +89,12 @@ class GCMDriver {
// Returns the handler for the given app. // Returns the handler for the given app.
GCMAppHandler* GetAppHandler(const std::string& app_id); GCMAppHandler* GetAppHandler(const std::string& app_id);
// Adds a connection state observer.
virtual void AddConnectionObserver(GCMConnectionObserver* observer) = 0;
// Removes a connection state observer.
virtual void RemoveConnectionObserver(GCMConnectionObserver* observer) = 0;
// Enables/disables GCM service. // Enables/disables GCM service.
virtual void Enable() = 0; virtual void Enable() = 0;
virtual void Disable() = 0; virtual void Disable() = 0;
......
...@@ -98,6 +98,13 @@ void GCMDriverAndroid::OnSignedIn() { ...@@ -98,6 +98,13 @@ void GCMDriverAndroid::OnSignedIn() {
void GCMDriverAndroid::Purge() { void GCMDriverAndroid::Purge() {
} }
void GCMDriverAndroid::AddConnectionObserver(GCMConnectionObserver* observer) {
}
void GCMDriverAndroid::RemoveConnectionObserver(
GCMConnectionObserver* observer) {
}
void GCMDriverAndroid::Enable() { void GCMDriverAndroid::Enable() {
} }
......
...@@ -47,6 +47,9 @@ class GCMDriverAndroid : public GCMDriver { ...@@ -47,6 +47,9 @@ class GCMDriverAndroid : public GCMDriver {
virtual void OnSignedIn() OVERRIDE; virtual void OnSignedIn() OVERRIDE;
virtual void Purge() OVERRIDE; virtual void Purge() OVERRIDE;
virtual void Enable() OVERRIDE; virtual void Enable() OVERRIDE;
virtual void AddConnectionObserver(GCMConnectionObserver* observer) OVERRIDE;
virtual void RemoveConnectionObserver(
GCMConnectionObserver* observer) OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual GCMClient* GetGCMClientForTesting() const OVERRIDE; virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
virtual bool IsStarted() const OVERRIDE; virtual bool IsStarted() const OVERRIDE;
......
...@@ -22,13 +22,6 @@ ...@@ -22,13 +22,6 @@
namespace gcm { namespace gcm {
namespace {
// Empty string is reserved for the default app handler.
const char kDefaultAppHandler[] = "";
} // namespace
// Helper class to save tasks to run until we're ready to execute them. // Helper class to save tasks to run until we're ready to execute them.
class GCMDriverDesktop::DelayedTaskController { class GCMDriverDesktop::DelayedTaskController {
public: public:
...@@ -463,6 +456,15 @@ void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { ...@@ -463,6 +456,15 @@ void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) {
Stop(); Stop();
} }
void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) {
connection_observer_list_.AddObserver(observer);
}
void GCMDriverDesktop::RemoveConnectionObserver(
GCMConnectionObserver* observer) {
connection_observer_list_.RemoveObserver(observer);
}
void GCMDriverDesktop::Enable() { void GCMDriverDesktop::Enable() {
DCHECK(ui_thread_->RunsTasksOnCurrentThread()); DCHECK(ui_thread_->RunsTasksOnCurrentThread());
...@@ -759,13 +761,9 @@ void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { ...@@ -759,13 +761,9 @@ void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) {
if (!gcm_started_) if (!gcm_started_)
return; return;
const GCMAppHandlerMap& app_handler_map = app_handlers(); FOR_EACH_OBSERVER(GCMConnectionObserver,
for (GCMAppHandlerMap::const_iterator iter = app_handler_map.begin(); connection_observer_list_,
iter != app_handler_map.end(); ++iter) { OnConnected(ip_endpoint));
iter->second->OnConnected(ip_endpoint);
}
GetAppHandler(kDefaultAppHandler)->OnConnected(ip_endpoint);
} }
void GCMDriverDesktop::OnDisconnected() { void GCMDriverDesktop::OnDisconnected() {
...@@ -777,13 +775,8 @@ void GCMDriverDesktop::OnDisconnected() { ...@@ -777,13 +775,8 @@ void GCMDriverDesktop::OnDisconnected() {
if (!gcm_started_) if (!gcm_started_)
return; return;
const GCMAppHandlerMap& app_handler_map = app_handlers(); FOR_EACH_OBSERVER(
for (GCMAppHandlerMap::const_iterator iter = app_handler_map.begin(); GCMConnectionObserver, connection_observer_list_, OnDisconnected());
iter != app_handler_map.end(); ++iter) {
iter->second->OnDisconnected();
}
GetAppHandler(kDefaultAppHandler)->OnDisconnected();
} }
void GCMDriverDesktop::GetGCMStatisticsFinished( void GCMDriverDesktop::GetGCMStatisticsFinished(
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "components/gcm_driver/gcm_client.h" #include "components/gcm_driver/gcm_client.h"
#include "components/gcm_driver/gcm_connection_observer.h"
#include "components/gcm_driver/gcm_driver.h" #include "components/gcm_driver/gcm_driver.h"
namespace base { namespace base {
...@@ -55,6 +57,9 @@ class GCMDriverDesktop : public GCMDriver { ...@@ -55,6 +57,9 @@ class GCMDriverDesktop : public GCMDriver {
virtual void AddAppHandler(const std::string& app_id, virtual void AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) OVERRIDE; GCMAppHandler* handler) OVERRIDE;
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
virtual void AddConnectionObserver(GCMConnectionObserver* observer) OVERRIDE;
virtual void RemoveConnectionObserver(
GCMConnectionObserver* observer) OVERRIDE;
virtual void Enable() OVERRIDE; virtual void Enable() OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual GCMClient* GetGCMClientForTesting() const OVERRIDE; virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
...@@ -134,6 +139,10 @@ class GCMDriverDesktop : public GCMDriver { ...@@ -134,6 +139,10 @@ class GCMDriverDesktop : public GCMDriver {
// it may be out of date while connection changes are happening. // it may be out of date while connection changes are happening.
bool connected_; bool connected_;
// List of observers to notify when connection state changes.
// Makes sure list is empty on destruction.
ObserverList<GCMConnectionObserver, true> connection_observer_list_;
scoped_refptr<base::SequencedTaskRunner> ui_thread_; scoped_refptr<base::SequencedTaskRunner> ui_thread_;
scoped_refptr<base::SequencedTaskRunner> io_thread_; scoped_refptr<base::SequencedTaskRunner> io_thread_;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "components/gcm_driver/fake_gcm_client_factory.h" #include "components/gcm_driver/fake_gcm_client_factory.h"
#include "components/gcm_driver/gcm_app_handler.h" #include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_client_factory.h" #include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_connection_observer.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -34,6 +35,36 @@ const char kTestAppID1[] = "TestApp1"; ...@@ -34,6 +35,36 @@ const char kTestAppID1[] = "TestApp1";
const char kTestAppID2[] = "TestApp2"; const char kTestAppID2[] = "TestApp2";
const char kUserID1[] = "user1"; const char kUserID1[] = "user1";
class FakeGCMConnectionObserver : public GCMConnectionObserver {
public:
FakeGCMConnectionObserver();
virtual ~FakeGCMConnectionObserver();
// gcm::GCMConnectionObserver implementation:
virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE;
virtual void OnDisconnected() OVERRIDE;
bool connected() const { return connected_; }
private:
bool connected_;
};
FakeGCMConnectionObserver::FakeGCMConnectionObserver() : connected_(false) {
}
FakeGCMConnectionObserver::~FakeGCMConnectionObserver() {
}
void FakeGCMConnectionObserver::OnConnected(
const net::IPEndPoint& ip_endpoint) {
connected_ = true;
}
void FakeGCMConnectionObserver::OnDisconnected() {
connected_ = false;
}
void PumpCurrentLoop() { void PumpCurrentLoop() {
base::MessageLoop::ScopedNestableTaskAllower base::MessageLoop::ScopedNestableTaskAllower
nestable_task_allower(base::MessageLoop::current()); nestable_task_allower(base::MessageLoop::current());
...@@ -68,6 +99,9 @@ class GCMDriverTest : public testing::Test { ...@@ -68,6 +99,9 @@ class GCMDriverTest : public testing::Test {
GCMDriver* driver() { return driver_.get(); } GCMDriver* driver() { return driver_.get(); }
FakeGCMAppHandler* gcm_app_handler() { return gcm_app_handler_.get(); } FakeGCMAppHandler* gcm_app_handler() { return gcm_app_handler_.get(); }
FakeGCMConnectionObserver* gcm_connection_observer() {
return gcm_connection_observer_.get();
}
const std::string& registration_id() const { return registration_id_; } const std::string& registration_id() const { return registration_id_; }
GCMClient::Result registration_result() const { return registration_result_; } GCMClient::Result registration_result() const { return registration_result_; }
const std::string& send_message_id() const { return send_message_id_; } const std::string& send_message_id() const { return send_message_id_; }
...@@ -114,6 +148,7 @@ class GCMDriverTest : public testing::Test { ...@@ -114,6 +148,7 @@ class GCMDriverTest : public testing::Test {
base::FieldTrialList field_trial_list_; base::FieldTrialList field_trial_list_;
scoped_ptr<GCMDriver> driver_; scoped_ptr<GCMDriver> driver_;
scoped_ptr<FakeGCMAppHandler> gcm_app_handler_; scoped_ptr<FakeGCMAppHandler> gcm_app_handler_;
scoped_ptr<FakeGCMConnectionObserver> gcm_connection_observer_;
base::Closure async_operation_completed_callback_; base::Closure async_operation_completed_callback_;
...@@ -147,6 +182,8 @@ void GCMDriverTest::TearDown() { ...@@ -147,6 +182,8 @@ void GCMDriverTest::TearDown() {
if (!driver_) if (!driver_)
return; return;
if (gcm_connection_observer_.get())
driver_->RemoveConnectionObserver(gcm_connection_observer_.get());
driver_->Shutdown(); driver_->Shutdown();
driver_.reset(); driver_.reset();
PumpIOLoop(); PumpIOLoop();
...@@ -199,6 +236,9 @@ void GCMDriverTest::CreateDriver( ...@@ -199,6 +236,9 @@ void GCMDriverTest::CreateDriver(
task_runner_)); task_runner_));
gcm_app_handler_.reset(new FakeGCMAppHandler); gcm_app_handler_.reset(new FakeGCMAppHandler);
gcm_connection_observer_.reset(new FakeGCMConnectionObserver);
driver_->AddConnectionObserver(gcm_connection_observer_.get());
} }
void GCMDriverTest::AddAppHandlers() { void GCMDriverTest::AddAppHandlers() {
...@@ -299,14 +339,14 @@ TEST_F(GCMDriverTest, Create) { ...@@ -299,14 +339,14 @@ TEST_F(GCMDriverTest, Create) {
SignIn(kTestAccountID1); SignIn(kTestAccountID1);
EXPECT_FALSE(driver()->IsStarted()); EXPECT_FALSE(driver()->IsStarted());
EXPECT_FALSE(driver()->IsConnected()); EXPECT_FALSE(driver()->IsConnected());
EXPECT_FALSE(gcm_app_handler()->connected()); EXPECT_FALSE(gcm_connection_observer()->connected());
// GCM will be started only after both sign-in and app handler being added. // GCM will be started only after both sign-in and app handler being added.
AddAppHandlers(); AddAppHandlers();
EXPECT_TRUE(driver()->IsStarted()); EXPECT_TRUE(driver()->IsStarted());
PumpIOLoop(); PumpIOLoop();
EXPECT_TRUE(driver()->IsConnected()); EXPECT_TRUE(driver()->IsConnected());
EXPECT_TRUE(gcm_app_handler()->connected()); EXPECT_TRUE(gcm_connection_observer()->connected());
} }
TEST_F(GCMDriverTest, CreateByFieldTrial) { TEST_F(GCMDriverTest, CreateByFieldTrial) {
...@@ -316,14 +356,14 @@ TEST_F(GCMDriverTest, CreateByFieldTrial) { ...@@ -316,14 +356,14 @@ TEST_F(GCMDriverTest, CreateByFieldTrial) {
CreateDriver(FakeGCMClient::NO_DELAY_START); CreateDriver(FakeGCMClient::NO_DELAY_START);
EXPECT_FALSE(driver()->IsStarted()); EXPECT_FALSE(driver()->IsStarted());
EXPECT_FALSE(driver()->IsConnected()); EXPECT_FALSE(driver()->IsConnected());
EXPECT_FALSE(gcm_app_handler()->connected()); EXPECT_FALSE(gcm_connection_observer()->connected());
// GCM will be started after app handler is added. // GCM will be started after app handler is added.
AddAppHandlers(); AddAppHandlers();
EXPECT_TRUE(driver()->IsStarted()); EXPECT_TRUE(driver()->IsStarted());
PumpIOLoop(); PumpIOLoop();
EXPECT_TRUE(driver()->IsConnected()); EXPECT_TRUE(driver()->IsConnected());
EXPECT_TRUE(gcm_app_handler()->connected()); EXPECT_TRUE(gcm_connection_observer()->connected());
} }
TEST_F(GCMDriverTest, Shutdown) { TEST_F(GCMDriverTest, Shutdown) {
...@@ -336,7 +376,7 @@ TEST_F(GCMDriverTest, Shutdown) { ...@@ -336,7 +376,7 @@ TEST_F(GCMDriverTest, Shutdown) {
driver()->Shutdown(); driver()->Shutdown();
EXPECT_FALSE(HasAppHandlers()); EXPECT_FALSE(HasAppHandlers());
EXPECT_FALSE(driver()->IsConnected()); EXPECT_FALSE(driver()->IsConnected());
EXPECT_FALSE(gcm_app_handler()->connected()); EXPECT_FALSE(gcm_connection_observer()->connected());
} }
TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) { TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) {
......
...@@ -165,8 +165,10 @@ GCMInvalidationBridge::GCMInvalidationBridge( ...@@ -165,8 +165,10 @@ GCMInvalidationBridge::GCMInvalidationBridge(
weak_factory_(this) {} weak_factory_(this) {}
GCMInvalidationBridge::~GCMInvalidationBridge() { GCMInvalidationBridge::~GCMInvalidationBridge() {
if (subscribed_for_incoming_messages_) if (subscribed_for_incoming_messages_) {
gcm_driver_->RemoveAppHandler(kInvalidationsAppId); gcm_driver_->RemoveAppHandler(kInvalidationsAppId);
gcm_driver_->RemoveConnectionObserver(this);
}
} }
scoped_ptr<syncer::GCMNetworkChannelDelegate> scoped_ptr<syncer::GCMNetworkChannelDelegate>
...@@ -285,6 +287,7 @@ void GCMInvalidationBridge::SubscribeForIncomingMessages() { ...@@ -285,6 +287,7 @@ void GCMInvalidationBridge::SubscribeForIncomingMessages() {
DCHECK(!subscribed_for_incoming_messages_); DCHECK(!subscribed_for_incoming_messages_);
gcm_driver_->AddAppHandler(kInvalidationsAppId, this); gcm_driver_->AddAppHandler(kInvalidationsAppId, this);
gcm_driver_->AddConnectionObserver(this);
core_thread_task_runner_->PostTask( core_thread_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "components/gcm_driver/gcm_app_handler.h" #include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_client.h" #include "components/gcm_driver/gcm_client.h"
#include "components/gcm_driver/gcm_connection_observer.h"
#include "components/invalidation/gcm_network_channel_delegate.h" #include "components/invalidation/gcm_network_channel_delegate.h"
#include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service.h"
...@@ -32,6 +33,7 @@ namespace invalidation { ...@@ -32,6 +33,7 @@ namespace invalidation {
// all function calls to GCMInvalidationBridge which does actual work to perform // all function calls to GCMInvalidationBridge which does actual work to perform
// them. // them.
class GCMInvalidationBridge : public gcm::GCMAppHandler, class GCMInvalidationBridge : public gcm::GCMAppHandler,
public gcm::GCMConnectionObserver,
public OAuth2TokenService::Consumer, public OAuth2TokenService::Consumer,
public base::NonThreadSafe { public base::NonThreadSafe {
public: public:
...@@ -59,6 +61,8 @@ class GCMInvalidationBridge : public gcm::GCMAppHandler, ...@@ -59,6 +61,8 @@ class GCMInvalidationBridge : public gcm::GCMAppHandler,
const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE; const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
virtual void OnSendAcknowledged(const std::string& app_id, virtual void OnSendAcknowledged(const std::string& app_id,
const std::string& message_id) OVERRIDE; const std::string& message_id) OVERRIDE;
// gcm::GCMConnectionObserver implementation.
virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE; virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE;
virtual void OnDisconnected() OVERRIDE; virtual void OnDisconnected() OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment