Commit 21b7765a authored by johnme@chromium.org's avatar johnme@chromium.org

This patch splits GCMDriver into an abstract interface and an

implementation thereof for desktop platforms. It also provides a stub
Android implementation, to be fleshed out in subsequent patches.

BUG=350384
TEST=existing tests
TBR=pavely@chromium.org for updates to invalidation tests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273977 0039d316-1c4b-4281-b951-d872f2087c98
parent 631fc091
......@@ -8,6 +8,7 @@
#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/gcm_driver/gcm_driver.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/fake_identity_provider.h"
......@@ -19,11 +20,12 @@ namespace {
// Implementation of GCMDriver::Register that always succeeds with the same
// registrationId.
class FakeGCMDriver : public gcm::GCMDriver {
class CustomFakeGCMDriver : public gcm::FakeGCMDriver {
public:
FakeGCMDriver() {}
virtual ~FakeGCMDriver() {}
CustomFakeGCMDriver() {}
virtual ~CustomFakeGCMDriver() {}
// GCMDriver overrides:
virtual void Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) OVERRIDE {
......@@ -34,7 +36,7 @@ class FakeGCMDriver : public gcm::GCMDriver {
}
private:
DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver);
DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver);
};
class GCMInvalidationBridgeTest : public ::testing::Test {
......@@ -53,7 +55,7 @@ class GCMInvalidationBridgeTest : public ::testing::Test {
(FakeProfileOAuth2TokenService*)
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
token_service->IssueRefreshTokenForUser("", "fake_refresh_token");
gcm_driver_.reset(new FakeGCMDriver());
gcm_driver_.reset(new CustomFakeGCMDriver());
identity_provider_.reset(new FakeIdentityProvider(token_service));
bridge_.reset(new GCMInvalidationBridge(gcm_driver_.get(),
......
......@@ -9,6 +9,7 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/invalidation/gcm_invalidation_bridge.h"
#include "chrome/browser/invalidation/invalidation_service_test_template.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/gcm_driver/gcm_driver.h"
#include "google_apis/gaia/fake_identity_provider.h"
#include "google_apis/gaia/fake_oauth2_token_service.h"
......@@ -35,15 +36,6 @@ class FakeTiclSettingsProvider : public TiclSettingsProvider {
DISALLOW_COPY_AND_ASSIGN(FakeTiclSettingsProvider);
};
class FakeGCMDriver : public gcm::GCMDriver {
public:
FakeGCMDriver();
virtual ~FakeGCMDriver();
private:
DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver);
};
FakeTiclSettingsProvider::FakeTiclSettingsProvider() {
}
......@@ -54,12 +46,6 @@ bool FakeTiclSettingsProvider::UseGCMChannel() const {
return false;
}
FakeGCMDriver::FakeGCMDriver() {
}
FakeGCMDriver::~FakeGCMDriver() {
}
} // namespace
class TiclInvalidationServiceTestDelegate {
......@@ -76,7 +62,7 @@ class TiclInvalidationServiceTestDelegate {
}
void CreateUninitializedInvalidationService() {
gcm_driver_.reset(new FakeGCMDriver());
gcm_driver_.reset(new gcm::FakeGCMDriver());
invalidation_service_.reset(new TiclInvalidationService(
scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
scoped_ptr<TiclSettingsProvider>(new FakeTiclSettingsProvider),
......
......@@ -9,22 +9,20 @@
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "components/gcm_driver/fake_gcm_client_factory.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/gcm_driver/gcm_driver.h"
#include "content/public/browser/browser_context.h"
namespace gcm {
namespace {
class FakeGCMDriver : public GCMDriver {
class CustomFakeGCMDriver : public FakeGCMDriver {
public:
explicit FakeGCMDriver(FakeGCMProfileService* service);
virtual ~FakeGCMDriver();
// GCMDriver overrides.
virtual void Shutdown() OVERRIDE;
virtual void AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) OVERRIDE;
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
explicit CustomFakeGCMDriver(FakeGCMProfileService* service);
virtual ~CustomFakeGCMDriver();
// GCMDriver overrides:
virtual void Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) OVERRIDE;
......@@ -38,27 +36,17 @@ class FakeGCMDriver : public GCMDriver {
private:
FakeGCMProfileService* service_;
DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver);
DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver);
};
FakeGCMDriver::FakeGCMDriver(FakeGCMProfileService* service)
CustomFakeGCMDriver::CustomFakeGCMDriver(FakeGCMProfileService* service)
: service_(service) {
}
FakeGCMDriver::~FakeGCMDriver() {
}
void FakeGCMDriver::Shutdown() {
}
void FakeGCMDriver::AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) {
}
void FakeGCMDriver::RemoveAppHandler(const std::string& app_id) {
CustomFakeGCMDriver::~CustomFakeGCMDriver() {
}
void FakeGCMDriver::Register(const std::string& app_id,
void CustomFakeGCMDriver::Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) {
base::MessageLoop::current()->PostTask(
......@@ -70,7 +58,7 @@ void FakeGCMDriver::Register(const std::string& app_id,
callback));
}
void FakeGCMDriver::Unregister(const std::string& app_id,
void CustomFakeGCMDriver::Unregister(const std::string& app_id,
const UnregisterCallback& callback) {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(
......@@ -80,7 +68,7 @@ void FakeGCMDriver::Unregister(const std::string& app_id,
callback));
}
void FakeGCMDriver::Send(const std::string& app_id,
void CustomFakeGCMDriver::Send(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message,
const SendCallback& callback) {
......@@ -100,7 +88,7 @@ void FakeGCMDriver::Send(const std::string& app_id,
KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) {
Profile* profile = static_cast<Profile*>(context);
FakeGCMProfileService* service = new FakeGCMProfileService(profile);
service->SetDriverForTesting(new FakeGCMDriver(service));
service->SetDriverForTesting(new CustomFakeGCMDriver(service));
return service;
}
......
......@@ -4,26 +4,28 @@
#include "chrome/browser/services/gcm/gcm_profile_service.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#if defined(OS_ANDROID)
#include "components/gcm_driver/gcm_driver_android.h"
#else
#include "base/files/file_path.h"
#include "chrome/browser/services/gcm/gcm_utils.h"
#include "chrome/browser/signin/profile_identity_provider.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_driver.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/gcm_driver/gcm_driver_desktop.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/identity_provider.h"
#include "net/url_request/url_request_context_getter.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#endif
namespace gcm {
......@@ -48,20 +50,18 @@ GCMProfileService::GCMProfileService(
: profile_(profile) {
DCHECK(!profile->IsOffTheRecord());
#if defined(OS_ANDROID)
driver_.reset(new GCMDriverAndroid());
#else
LoginUIService* login_ui_service =
LoginUIServiceFactory::GetForProfile(profile_);
scoped_refptr<base::SequencedWorkerPool> worker_pool(
content::BrowserThread::GetBlockingPool());
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
worker_pool->GetSequenceToken(),
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
#if defined(OS_ANDROID)
LoginUIService* login_ui_service = NULL;
#else
LoginUIService* login_ui_service =
LoginUIServiceFactory::GetForProfile(profile_);
#endif
driver_.reset(new GCMDriver(
driver_.reset(new GCMDriverDesktop(
gcm_client_factory.Pass(),
scoped_ptr<IdentityProvider>(new ProfileIdentityProvider(
SigninManagerFactory::GetForProfile(profile_),
......@@ -75,6 +75,7 @@ GCMProfileService::GCMProfileService(
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO),
blocking_task_runner));
#endif
}
GCMProfileService::GCMProfileService() : profile_(NULL) {
......
......@@ -2583,6 +2583,10 @@
# URL elider is not used on android.
'browser/ui/tests/elide_url_unittest.cc',
# GCMDriverAndroid is not yet implemented.
'browser/extensions/extension_gcm_app_handler_unittest.cc',
'browser/services/gcm/gcm_profile_service_unittest.cc',
],
'sources/': [
['exclude', '^browser/captive_portal/'],
......
......@@ -97,7 +97,7 @@
'domain_reliability/util_unittest.cc',
'enhanced_bookmarks/image_store_unittest.cc',
'feedback/feedback_uploader_unittest.cc',
'gcm_driver/gcm_driver_unittest.cc',
'gcm_driver/gcm_driver_desktop_unittest.cc',
'invalidation/invalidation_logger_unittest.cc',
'json_schema/json_schema_validator_unittest.cc',
'json_schema/json_schema_validator_unittest_base.cc',
......@@ -432,6 +432,7 @@
}],
['OS == "android"', {
'sources!': [
'gcm_driver/gcm_driver_desktop_unittest.cc',
'feedback/feedback_uploader_unittest.cc',
'signin/core/browser/mutable_profile_oauth2_token_service_unittest.cc',
'storage_monitor/media_storage_util_unittest.cc',
......
......@@ -28,6 +28,8 @@
'gcm_driver/gcm_driver.h',
'gcm_driver/gcm_driver_android.cc',
'gcm_driver/gcm_driver_android.h',
'gcm_driver/gcm_driver_desktop.cc',
'gcm_driver/gcm_driver_desktop.h',
'gcm_driver/system_encryptor.cc',
'gcm_driver/system_encryptor.h',
],
......@@ -36,6 +38,10 @@
'dependencies': [
'gcm_driver_jni_headers',
],
'sources!': [
'gcm_driver/gcm_driver_desktop.cc',
'gcm_driver/gcm_driver_desktop.h',
],
}],
],
},
......@@ -57,6 +63,8 @@
'gcm_driver/fake_gcm_client.h',
'gcm_driver/fake_gcm_client_factory.cc',
'gcm_driver/fake_gcm_client_factory.h',
'gcm_driver/fake_gcm_driver.cc',
'gcm_driver/fake_gcm_driver.h',
],
},
],
......
// 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/fake_gcm_driver.h"
namespace gcm {
FakeGCMDriver::FakeGCMDriver() {
}
FakeGCMDriver::~FakeGCMDriver() {
}
void FakeGCMDriver::Shutdown() {
}
void FakeGCMDriver::AddAppHandler(
const std::string& app_id, GCMAppHandler* handler) {
}
void FakeGCMDriver::RemoveAppHandler(const std::string& app_id) {
}
void FakeGCMDriver::Enable() {
}
void FakeGCMDriver::Disable() {
}
void FakeGCMDriver::Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) {
}
void FakeGCMDriver::Unregister(const std::string& app_id,
const UnregisterCallback& callback) {
}
void FakeGCMDriver::Send(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message,
const SendCallback& callback) {
}
GCMClient* FakeGCMDriver::GetGCMClientForTesting() const {
return NULL;
}
bool FakeGCMDriver::IsStarted() const {
return true;
}
bool FakeGCMDriver::IsGCMClientReady() const {
return true;
}
void FakeGCMDriver::GetGCMStatistics(const GetGCMStatisticsCallback& callback,
bool clear_logs) {
}
void FakeGCMDriver::SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) {
}
std::string FakeGCMDriver::SignedInUserName() const {
return std::string();
}
} // namespace gcm
// 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.
#ifndef COMPONENTS_GCM_DRIVER_FAKE_GCM_DRIVER_H_
#define COMPONENTS_GCM_DRIVER_FAKE_GCM_DRIVER_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "components/gcm_driver/gcm_driver.h"
namespace gcm {
class FakeGCMDriver : public GCMDriver {
public:
FakeGCMDriver();
virtual ~FakeGCMDriver();
// GCMDriver overrides:
virtual void Shutdown() OVERRIDE;
virtual void AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) OVERRIDE;
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
// GCMDriver implementation:
virtual void Enable() OVERRIDE;
virtual void Disable() OVERRIDE;
virtual void Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) OVERRIDE;
virtual void Unregister(const std::string& app_id,
const UnregisterCallback& callback) OVERRIDE;
virtual void Send(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message,
const SendCallback& callback) OVERRIDE;
virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
virtual bool IsStarted() const OVERRIDE;
virtual bool IsGCMClientReady() const OVERRIDE;
virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
virtual std::string SignedInUserName() const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver);
};
} // namespace gcm
#endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_DRIVER_H_
This diff is collapsed.
......@@ -9,36 +9,18 @@
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "components/gcm_driver/default_gcm_app_handler.h"
#include "google_apis/gaia/identity_provider.h"
#include "google_apis/gcm/gcm_client.h"
namespace base {
class FilePath;
class SequencedTaskRunner;
}
namespace extensions {
class ExtensionGCMAppHandlerTest;
}
namespace net {
class URLRequestContextGetter;
}
namespace gcm {
class GCMAppHandler;
class GCMClientFactory;
// A bridge between the GCM users in Chrome and the GCMClient layer.
class GCMDriver : public IdentityProvider::Observer {
// Bridge between GCM users in Chrome and the platform-specific implementation.
class GCMDriver {
public:
typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap;
typedef base::Callback<void(const std::string& registration_id,
......@@ -49,21 +31,9 @@ class GCMDriver : public IdentityProvider::Observer {
typedef base::Callback<void(const GCMClient::GCMStatistics& stats)>
GetGCMStatisticsCallback;
GCMDriver(
scoped_ptr<GCMClientFactory> gcm_client_factory,
scoped_ptr<IdentityProvider> identity_provider,
const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const scoped_refptr<net::URLRequestContextGetter>& request_context,
const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
const scoped_refptr<base::SequencedTaskRunner>& io_thread,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
GCMDriver();
virtual ~GCMDriver();
// Enables/disables GCM service.
void Enable();
void Disable();
// This method must be called before destroying the GCMDriver. Once it has
// been called, no other GCMDriver methods may be used.
virtual void Shutdown();
......@@ -74,6 +44,10 @@ class GCMDriver : public IdentityProvider::Observer {
// Remove the handler for a given app.
virtual void RemoveAppHandler(const std::string& app_id);
// Enables/disables GCM service.
virtual void Enable() = 0;
virtual void Disable() = 0;
// Registers |sender_id| for an app. A registration ID will be returned by
// the GCM server.
// |app_id|: application ID.
......@@ -83,13 +57,13 @@ class GCMDriver : public IdentityProvider::Observer {
// |callback|: to be called once the asynchronous operation is done.
virtual void Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback);
const RegisterCallback& callback) = 0;
// Unregisters an app from using GCM.
// |app_id|: application ID.
// |callback|: to be called once the asynchronous operation is done.
virtual void Unregister(const std::string& app_id,
const UnregisterCallback& callback);
const UnregisterCallback& callback) = 0;
// Sends a message to a given receiver.
// |app_id|: application ID.
......@@ -99,110 +73,37 @@ class GCMDriver : public IdentityProvider::Observer {
virtual void Send(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message,
const SendCallback& callback);
const SendCallback& callback) = 0;
// For testing purpose.
GCMClient* GetGCMClientForTesting() const;
// For testing purpose. Always NULL on Android.
virtual GCMClient* GetGCMClientForTesting() const = 0;
// Returns true if the service was started.
bool IsStarted() const;
virtual bool IsStarted() const = 0;
// Returns true if the gcm client is ready.
bool IsGCMClientReady() const;
virtual bool IsGCMClientReady() const = 0;
// Get GCM client internal states and statistics.
// If clear_logs is true then activity logs will be cleared before the stats
// are returned.
void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
bool clear_logs);
virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
bool clear_logs) = 0;
// Enables/disables GCM activity recording, and then returns the stats.
void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording);
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) = 0;
// Returns the user name if the profile is signed in. Empty string otherwise.
std::string SignedInUserName() const;
// IdentityProvider::Observer:
virtual void OnActiveAccountLogin() OVERRIDE;
virtual void OnActiveAccountLogout() OVERRIDE;
virtual std::string SignedInUserName() const = 0;
const GCMAppHandlerMap& app_handlers() const { return app_handlers_; }
protected:
// Used for constructing fake GCMDriver for testing purpose.
GCMDriver();
private:
class DelayedTaskController;
class IOWorker;
// Ensures that the GCM service starts when all of the following conditions
// satisfy:
// 1) GCM is enabled.
// 2) The identity provider is able to supply an account ID.
GCMClient::Result EnsureStarted();
// Stops the GCM service. It can be restarted by calling EnsureStarted again.
void Stop();
// Remove cached data when GCM service is stopped.
void RemoveCachedData();
// Checks out of GCM and erases any cached and persisted data.
void CheckOut();
// Should be called when an app with |app_id| is trying to un/register.
// Checks whether another un/registration is in progress.
bool IsAsyncOperationPending(const std::string& app_id) const;
void DoRegister(const std::string& app_id,
const std::vector<std::string>& sender_ids);
void DoUnregister(const std::string& app_id);
void DoSend(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message);
// Callbacks posted from IO thread to UI thread.
void RegisterFinished(const std::string& app_id,
const std::string& registration_id,
GCMClient::Result result);
void UnregisterFinished(const std::string& app_id, GCMClient::Result result);
void SendFinished(const std::string& app_id,
const std::string& message_id,
GCMClient::Result result);
void MessageReceived(const std::string& app_id,
GCMClient::IncomingMessage message);
void MessagesDeleted(const std::string& app_id);
void MessageSendError(const std::string& app_id,
const GCMClient::SendErrorDetails& send_error_details);
void GCMClientReady();
// Returns the handler for the given app.
GCMAppHandler* GetAppHandler(const std::string& app_id);
void GetGCMStatisticsFinished(GCMClient::GCMStatistics stats);
// Flag to indicate if GCM is enabled.
bool gcm_enabled_;
// Flag to indicate if GCMClient is ready.
bool gcm_client_ready_;
// The account ID that this service is responsible for. Empty when the service
// is not running.
std::string account_id_;
scoped_ptr<IdentityProvider> identity_provider_;
scoped_refptr<base::SequencedTaskRunner> ui_thread_;
scoped_refptr<base::SequencedTaskRunner> io_thread_;
scoped_ptr<DelayedTaskController> delayed_task_controller_;
// For all the work occurring on the IO thread. Must be destroyed on the IO
// thread.
scoped_ptr<IOWorker> io_worker_;
private:
// App handler map (from app_id to handler pointer).
// The handler is not owned.
GCMAppHandlerMap app_handlers_;
......@@ -210,21 +111,6 @@ class GCMDriver : public IdentityProvider::Observer {
// The default handler when no app handler can be found in the map.
DefaultGCMAppHandler default_app_handler_;
// Callback map (from app_id to callback) for Register.
std::map<std::string, RegisterCallback> register_callbacks_;
// Callback map (from app_id to callback) for Unregister.
std::map<std::string, UnregisterCallback> unregister_callbacks_;
// Callback map (from <app_id, message_id> to callback) for Send.
std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_;
// Callback for GetGCMStatistics.
GetGCMStatisticsCallback request_gcm_statistics_callback_;
// Used to pass a weak pointer to the IO worker.
base::WeakPtrFactory<GCMDriver> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(GCMDriver);
};
......
......@@ -5,6 +5,7 @@
#include "components/gcm_driver/gcm_driver_android.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
namespace gcm {
static void Java_GCMDriver_doNothing(JNIEnv* env) ALLOW_UNUSED;
......@@ -15,9 +16,69 @@ static void Java_GCMDriver_doNothing(JNIEnv* env) ALLOW_UNUSED;
namespace gcm {
GCMDriverAndroid::GCMDriverAndroid() {
}
GCMDriverAndroid::~GCMDriverAndroid() {
}
void GCMDriverAndroid::Enable() {
}
void GCMDriverAndroid::Disable() {
}
void GCMDriverAndroid::Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) {
// TODO(johnme): Hook up to Android GCM API via JNI.
NOTIMPLEMENTED();
}
void GCMDriverAndroid::Unregister(const std::string& app_id,
const UnregisterCallback& callback) {
// TODO(johnme): Hook up to Android GCM API via JNI.
NOTIMPLEMENTED();
}
void GCMDriverAndroid::Send(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message,
const SendCallback& callback) {
NOTIMPLEMENTED();
}
GCMClient* GCMDriverAndroid::GetGCMClientForTesting() const {
NOTIMPLEMENTED();
return NULL;
}
bool GCMDriverAndroid::IsStarted() const {
return true;
}
bool GCMDriverAndroid::IsGCMClientReady() const {
return true;
}
void GCMDriverAndroid::GetGCMStatistics(
const GetGCMStatisticsCallback& callback,
bool clear_logs) {
NOTIMPLEMENTED();
}
void GCMDriverAndroid::SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) {
NOTIMPLEMENTED();
}
std::string GCMDriverAndroid::SignedInUserName() const {
return std::string();
}
// static
bool GCMDriverAndroid::RegisterBindings(JNIEnv* env) {
return RegisterNativesImpl(env);
}
} // namespace gcm
\ No newline at end of file
} // namespace gcm
......@@ -7,14 +7,46 @@
#include <jni.h>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "components/gcm_driver/gcm_driver.h"
namespace gcm {
class GCMDriverAndroid {
// GCMDriver implementation for Android.
class GCMDriverAndroid : public GCMDriver {
public:
// Register JNI methods
GCMDriverAndroid();
virtual ~GCMDriverAndroid();
// GCMDriver implementation:
virtual void Enable() OVERRIDE;
virtual void Disable() OVERRIDE;
virtual void Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) OVERRIDE;
virtual void Unregister(const std::string& app_id,
const UnregisterCallback& callback) OVERRIDE;
virtual void Send(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message,
const SendCallback& callback) OVERRIDE;
virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
virtual bool IsStarted() const OVERRIDE;
virtual bool IsGCMClientReady() const OVERRIDE;
virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
virtual std::string SignedInUserName() const OVERRIDE;
// Register JNI methods.
static bool RegisterBindings(JNIEnv* env);
private:
DISALLOW_COPY_AND_ASSIGN(GCMDriverAndroid);
};
} // namespace gcm
#endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H
\ No newline at end of file
#endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H
This diff is collapsed.
// 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.
#ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_
#define COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_
#include <map>
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/gcm_driver/gcm_driver.h"
#include "google_apis/gaia/identity_provider.h"
#include "google_apis/gcm/gcm_client.h"
namespace base {
class FilePath;
class SequencedTaskRunner;
}
namespace extensions {
class ExtensionGCMAppHandlerTest;
}
namespace net {
class URLRequestContextGetter;
}
namespace gcm {
class GCMAppHandler;
class GCMClientFactory;
// GCMDriver implementation for desktop and Chrome OS, using GCMClient.
class GCMDriverDesktop : public GCMDriver, public IdentityProvider::Observer {
public:
GCMDriverDesktop(
scoped_ptr<GCMClientFactory> gcm_client_factory,
scoped_ptr<IdentityProvider> identity_provider,
const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const scoped_refptr<net::URLRequestContextGetter>& request_context,
const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
const scoped_refptr<base::SequencedTaskRunner>& io_thread,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
virtual ~GCMDriverDesktop();
// GCMDriver overrides:
virtual void Shutdown() OVERRIDE;
virtual void AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) OVERRIDE;
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
// GCMDriver implementation:
virtual void Enable() OVERRIDE;
virtual void Disable() OVERRIDE;
virtual void Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const RegisterCallback& callback) OVERRIDE;
virtual void Unregister(const std::string& app_id,
const UnregisterCallback& callback) OVERRIDE;
virtual void Send(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message,
const SendCallback& callback) OVERRIDE;
virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
virtual bool IsStarted() const OVERRIDE;
virtual bool IsGCMClientReady() const OVERRIDE;
virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
virtual std::string SignedInUserName() const OVERRIDE;
// IdentityProvider::Observer implementation:
virtual void OnActiveAccountLogin() OVERRIDE;
virtual void OnActiveAccountLogout() OVERRIDE;
private:
class DelayedTaskController;
class IOWorker;
// Ensures that the GCM service starts when all of the following conditions
// satisfy:
// 1) GCM is enabled.
// 2) The identity provider is able to supply an account ID.
GCMClient::Result EnsureStarted();
// Stops the GCM service. It can be restarted by calling EnsureStarted again.
void Stop();
// Remove cached data when GCM service is stopped.
void RemoveCachedData();
// Checks out of GCM and erases any cached and persisted data.
void CheckOut();
// Should be called when an app with |app_id| is trying to un/register.
// Checks whether another un/registration is in progress.
bool IsAsyncOperationPending(const std::string& app_id) const;
void DoRegister(const std::string& app_id,
const std::vector<std::string>& sender_ids);
void DoUnregister(const std::string& app_id);
void DoSend(const std::string& app_id,
const std::string& receiver_id,
const GCMClient::OutgoingMessage& message);
// Callbacks posted from IO thread to UI thread.
void RegisterFinished(const std::string& app_id,
const std::string& registration_id,
GCMClient::Result result);
void UnregisterFinished(const std::string& app_id, GCMClient::Result result);
void SendFinished(const std::string& app_id,
const std::string& message_id,
GCMClient::Result result);
void MessageReceived(const std::string& app_id,
GCMClient::IncomingMessage message);
void MessagesDeleted(const std::string& app_id);
void MessageSendError(const std::string& app_id,
const GCMClient::SendErrorDetails& send_error_details);
void GCMClientReady();
void GetGCMStatisticsFinished(GCMClient::GCMStatistics stats);
// Flag to indicate if GCM is enabled.
bool gcm_enabled_;
// Flag to indicate if GCMClient is ready.
bool gcm_client_ready_;
// The account ID that this service is responsible for. Empty when the service
// is not running.
std::string account_id_;
scoped_ptr<IdentityProvider> identity_provider_;
scoped_refptr<base::SequencedTaskRunner> ui_thread_;
scoped_refptr<base::SequencedTaskRunner> io_thread_;
scoped_ptr<DelayedTaskController> delayed_task_controller_;
// For all the work occurring on the IO thread. Must be destroyed on the IO
// thread.
scoped_ptr<IOWorker> io_worker_;
// Callback map (from app_id to callback) for Register.
std::map<std::string, RegisterCallback> register_callbacks_;
// Callback map (from app_id to callback) for Unregister.
std::map<std::string, UnregisterCallback> unregister_callbacks_;
// Callback map (from <app_id, message_id> to callback) for Send.
std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_;
// Callback for GetGCMStatistics.
GetGCMStatisticsCallback request_gcm_statistics_callback_;
// Used to pass a weak pointer to the IO worker.
base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop);
};
} // namespace gcm
#endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_
......@@ -2,7 +2,7 @@
// 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_driver.h"
#include "components/gcm_driver/gcm_driver_desktop.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
......@@ -190,7 +190,8 @@ void GCMDriverTest::CreateDriver(
FakeGCMClient::StartMode gcm_client_start_mode) {
scoped_refptr<net::URLRequestContextGetter> request_context =
new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy());
driver_.reset(new GCMDriver(
// TODO(johnme): Need equivalent test coverage of GCMDriverAndroid.
driver_.reset(new GCMDriverDesktop(
scoped_ptr<GCMClientFactory>(new FakeGCMClientFactory(
gcm_client_start_mode,
base::MessageLoopProxy::current(),
......
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