Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: chrome/browser/services/gcm/fake_gcm_profile_service.cc

Issue 286213003: Make GCMProfileService own GCMDriver, instead of deriving from it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/services/gcm/fake_gcm_profile_service.h ('k') | chrome/browser/services/gcm/gcm_driver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b82f79170dabac97ac16e7da56dab34a56d8cf4f 100644
--- a/chrome/browser/services/gcm/fake_gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/fake_gcm_profile_service.cc
@@ -8,38 +8,111 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/services/gcm/fake_gcm_client_factory.h"
#include "content/public/browser/browser_context.h"
namespace gcm {
+namespace {
+
+class FakeGCMDriver : public GCMDriver {
+ 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;
+ 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::Shutdown() {
+}
+
+void FakeGCMDriver::AddAppHandler(const std::string& app_id,
+ GCMAppHandler* handler) {
+}
+
+void FakeGCMDriver::RemoveAppHandler(const std::string& app_id) {
+}
+
+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)
- : GCMProfileService(profile),
- collect_(false) {}
+ : collect_(false) {}
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 +121,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 +151,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
« no previous file with comments | « chrome/browser/services/gcm/fake_gcm_profile_service.h ('k') | chrome/browser/services/gcm/gcm_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698