| Index: chrome/browser/services/gcm/fake_gcm_profile_service.cc
|
| diff --git a/chrome/browser/services/gcm/fake_gcm_profile_service.cc b/chrome/browser/services/gcm/fake_gcm_profile_service.cc
|
| index e2b32e63f1063f176f6e4550e93e5a194aab417f..8bd36911e0b4fe6960a7891431067a2c81c8770c 100644
|
| --- a/chrome/browser/services/gcm/fake_gcm_profile_service.cc
|
| +++ b/chrome/browser/services/gcm/fake_gcm_profile_service.cc
|
| @@ -12,10 +12,81 @@
|
|
|
| namespace gcm {
|
|
|
| +namespace {
|
| +
|
| +class FakeGCMDriver : public GCMDriver {
|
| + public:
|
| + explicit FakeGCMDriver(FakeGCMProfileService* service);
|
| + virtual ~FakeGCMDriver();
|
| +
|
| + // GCMDriver overrides.
|
| + 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;
|
| +
|
| + private:
|
| + FakeGCMProfileService* service_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver);
|
| +};
|
| +
|
| +FakeGCMDriver::FakeGCMDriver(FakeGCMProfileService* service)
|
| + : service_(service) {
|
| +}
|
| +
|
| +FakeGCMDriver::~FakeGCMDriver() {
|
| +}
|
| +
|
| +void FakeGCMDriver::Register(const std::string& app_id,
|
| + const std::vector<std::string>& sender_ids,
|
| + const RegisterCallback& callback) {
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&FakeGCMProfileService::RegisterFinished,
|
| + base::Unretained(service_),
|
| + app_id,
|
| + sender_ids,
|
| + callback));
|
| +}
|
| +
|
| +void FakeGCMDriver::Unregister(const std::string& app_id,
|
| + const UnregisterCallback& callback) {
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE, base::Bind(
|
| + &FakeGCMProfileService::UnregisterFinished,
|
| + base::Unretained(service_),
|
| + app_id,
|
| + callback));
|
| +}
|
| +
|
| +void FakeGCMDriver::Send(const std::string& app_id,
|
| + const std::string& receiver_id,
|
| + const GCMClient::OutgoingMessage& message,
|
| + const SendCallback& callback) {
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&FakeGCMProfileService::SendFinished,
|
| + base::Unretained(service_),
|
| + app_id,
|
| + receiver_id,
|
| + message,
|
| + callback));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // static
|
| KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) {
|
| Profile* profile = static_cast<Profile*>(context);
|
| - return new FakeGCMProfileService(profile);
|
| + FakeGCMProfileService* service = new FakeGCMProfileService(profile);
|
| + service->SetDriverForTesting(new FakeGCMDriver(service));
|
| + return service;
|
| }
|
|
|
| FakeGCMProfileService::FakeGCMProfileService(Profile* profile)
|
| @@ -24,22 +95,10 @@ FakeGCMProfileService::FakeGCMProfileService(Profile* profile)
|
|
|
| FakeGCMProfileService::~FakeGCMProfileService() {}
|
|
|
| -void FakeGCMProfileService::Register(const std::string& app_id,
|
| - const std::vector<std::string>& sender_ids,
|
| - const RegisterCallback& callback) {
|
| - base::MessageLoop::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&FakeGCMProfileService::RegisterFinished,
|
| - base::Unretained(this),
|
| - app_id,
|
| - sender_ids,
|
| - callback));
|
| -}
|
| -
|
| void FakeGCMProfileService::RegisterFinished(
|
| const std::string& app_id,
|
| const std::vector<std::string>& sender_ids,
|
| - const RegisterCallback& callback) {
|
| + const GCMDriver::RegisterCallback& callback) {
|
| if (collect_) {
|
| last_registered_app_id_ = app_id;
|
| last_registered_sender_ids_ = sender_ids;
|
| @@ -48,31 +107,23 @@ void FakeGCMProfileService::RegisterFinished(
|
| callback.Run(base::UintToString(sender_ids.size()), GCMClient::SUCCESS);
|
| }
|
|
|
| -void FakeGCMProfileService::Unregister(const std::string& app_id,
|
| - const UnregisterCallback& callback) {
|
| - base::MessageLoop::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, GetNextExpectedUnregisterResponse()));
|
| -}
|
| +void FakeGCMProfileService::UnregisterFinished(
|
| + const std::string& app_id,
|
| + const GCMDriver::UnregisterCallback& callback) {
|
| + GCMClient::Result result = GCMClient::SUCCESS;
|
| + if (!unregister_responses_.empty()) {
|
| + result = unregister_responses_.front();
|
| + unregister_responses_.pop_front();
|
| + }
|
|
|
| -void FakeGCMProfileService::Send(const std::string& app_id,
|
| - const std::string& receiver_id,
|
| - const GCMClient::OutgoingMessage& message,
|
| - const SendCallback& callback) {
|
| - base::MessageLoop::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&FakeGCMProfileService::SendFinished,
|
| - base::Unretained(this),
|
| - app_id,
|
| - receiver_id,
|
| - message,
|
| - callback));
|
| + callback.Run(result);
|
| }
|
|
|
| void FakeGCMProfileService::SendFinished(
|
| const std::string& app_id,
|
| const std::string& receiver_id,
|
| const GCMClient::OutgoingMessage& message,
|
| - const SendCallback& callback) {
|
| + const GCMDriver::SendCallback& callback) {
|
| if (collect_) {
|
| last_sent_message_ = message;
|
| last_receiver_id_ = receiver_id;
|
| @@ -86,12 +137,4 @@ void FakeGCMProfileService::AddExpectedUnregisterResponse(
|
| unregister_responses_.push_back(result);
|
| }
|
|
|
| -GCMClient::Result FakeGCMProfileService::GetNextExpectedUnregisterResponse() {
|
| - if (unregister_responses_.empty())
|
| - return GCMClient::SUCCESS;
|
| - GCMClient::Result response = *unregister_responses_.begin();
|
| - unregister_responses_.erase(unregister_responses_.begin());
|
| - return response;
|
| -}
|
| -
|
| } // namespace gcm
|
|
|