| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 5 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "components/gcm_driver/fake_gcm_client_factory.h" | 11 #include "components/gcm_driver/fake_gcm_client_factory.h" |
| 12 #include "components/gcm_driver/fake_gcm_driver.h" |
| 13 #include "components/gcm_driver/gcm_driver.h" |
| 12 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 13 | 15 |
| 14 namespace gcm { | 16 namespace gcm { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 class FakeGCMDriver : public GCMDriver { | 20 class CustomFakeGCMDriver : public FakeGCMDriver { |
| 19 public: | 21 public: |
| 20 explicit FakeGCMDriver(FakeGCMProfileService* service); | 22 explicit CustomFakeGCMDriver(FakeGCMProfileService* service); |
| 21 virtual ~FakeGCMDriver(); | 23 virtual ~CustomFakeGCMDriver(); |
| 22 | 24 |
| 23 // GCMDriver overrides. | 25 // GCMDriver overrides: |
| 24 virtual void Shutdown() OVERRIDE; | |
| 25 virtual void AddAppHandler(const std::string& app_id, | |
| 26 GCMAppHandler* handler) OVERRIDE; | |
| 27 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; | |
| 28 virtual void Register(const std::string& app_id, | 26 virtual void Register(const std::string& app_id, |
| 29 const std::vector<std::string>& sender_ids, | 27 const std::vector<std::string>& sender_ids, |
| 30 const RegisterCallback& callback) OVERRIDE; | 28 const RegisterCallback& callback) OVERRIDE; |
| 31 virtual void Unregister(const std::string& app_id, | 29 virtual void Unregister(const std::string& app_id, |
| 32 const UnregisterCallback& callback) OVERRIDE; | 30 const UnregisterCallback& callback) OVERRIDE; |
| 33 virtual void Send(const std::string& app_id, | 31 virtual void Send(const std::string& app_id, |
| 34 const std::string& receiver_id, | 32 const std::string& receiver_id, |
| 35 const GCMClient::OutgoingMessage& message, | 33 const GCMClient::OutgoingMessage& message, |
| 36 const SendCallback& callback) OVERRIDE; | 34 const SendCallback& callback) OVERRIDE; |
| 37 | 35 |
| 38 private: | 36 private: |
| 39 FakeGCMProfileService* service_; | 37 FakeGCMProfileService* service_; |
| 40 | 38 |
| 41 DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver); | 39 DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver); |
| 42 }; | 40 }; |
| 43 | 41 |
| 44 FakeGCMDriver::FakeGCMDriver(FakeGCMProfileService* service) | 42 CustomFakeGCMDriver::CustomFakeGCMDriver(FakeGCMProfileService* service) |
| 45 : service_(service) { | 43 : service_(service) { |
| 46 } | 44 } |
| 47 | 45 |
| 48 FakeGCMDriver::~FakeGCMDriver() { | 46 CustomFakeGCMDriver::~CustomFakeGCMDriver() { |
| 49 } | 47 } |
| 50 | 48 |
| 51 void FakeGCMDriver::Shutdown() { | 49 void CustomFakeGCMDriver::Register(const std::string& app_id, |
| 52 } | |
| 53 | |
| 54 void FakeGCMDriver::AddAppHandler(const std::string& app_id, | |
| 55 GCMAppHandler* handler) { | |
| 56 } | |
| 57 | |
| 58 void FakeGCMDriver::RemoveAppHandler(const std::string& app_id) { | |
| 59 } | |
| 60 | |
| 61 void FakeGCMDriver::Register(const std::string& app_id, | |
| 62 const std::vector<std::string>& sender_ids, | 50 const std::vector<std::string>& sender_ids, |
| 63 const RegisterCallback& callback) { | 51 const RegisterCallback& callback) { |
| 64 base::MessageLoop::current()->PostTask( | 52 base::MessageLoop::current()->PostTask( |
| 65 FROM_HERE, | 53 FROM_HERE, |
| 66 base::Bind(&FakeGCMProfileService::RegisterFinished, | 54 base::Bind(&FakeGCMProfileService::RegisterFinished, |
| 67 base::Unretained(service_), | 55 base::Unretained(service_), |
| 68 app_id, | 56 app_id, |
| 69 sender_ids, | 57 sender_ids, |
| 70 callback)); | 58 callback)); |
| 71 } | 59 } |
| 72 | 60 |
| 73 void FakeGCMDriver::Unregister(const std::string& app_id, | 61 void CustomFakeGCMDriver::Unregister(const std::string& app_id, |
| 74 const UnregisterCallback& callback) { | 62 const UnregisterCallback& callback) { |
| 75 base::MessageLoop::current()->PostTask( | 63 base::MessageLoop::current()->PostTask( |
| 76 FROM_HERE, base::Bind( | 64 FROM_HERE, base::Bind( |
| 77 &FakeGCMProfileService::UnregisterFinished, | 65 &FakeGCMProfileService::UnregisterFinished, |
| 78 base::Unretained(service_), | 66 base::Unretained(service_), |
| 79 app_id, | 67 app_id, |
| 80 callback)); | 68 callback)); |
| 81 } | 69 } |
| 82 | 70 |
| 83 void FakeGCMDriver::Send(const std::string& app_id, | 71 void CustomFakeGCMDriver::Send(const std::string& app_id, |
| 84 const std::string& receiver_id, | 72 const std::string& receiver_id, |
| 85 const GCMClient::OutgoingMessage& message, | 73 const GCMClient::OutgoingMessage& message, |
| 86 const SendCallback& callback) { | 74 const SendCallback& callback) { |
| 87 base::MessageLoop::current()->PostTask( | 75 base::MessageLoop::current()->PostTask( |
| 88 FROM_HERE, | 76 FROM_HERE, |
| 89 base::Bind(&FakeGCMProfileService::SendFinished, | 77 base::Bind(&FakeGCMProfileService::SendFinished, |
| 90 base::Unretained(service_), | 78 base::Unretained(service_), |
| 91 app_id, | 79 app_id, |
| 92 receiver_id, | 80 receiver_id, |
| 93 message, | 81 message, |
| 94 callback)); | 82 callback)); |
| 95 } | 83 } |
| 96 | 84 |
| 97 } // namespace | 85 } // namespace |
| 98 | 86 |
| 99 // static | 87 // static |
| 100 KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) { | 88 KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) { |
| 101 Profile* profile = static_cast<Profile*>(context); | 89 Profile* profile = static_cast<Profile*>(context); |
| 102 FakeGCMProfileService* service = new FakeGCMProfileService(profile); | 90 FakeGCMProfileService* service = new FakeGCMProfileService(profile); |
| 103 service->SetDriverForTesting(new FakeGCMDriver(service)); | 91 service->SetDriverForTesting(new CustomFakeGCMDriver(service)); |
| 104 return service; | 92 return service; |
| 105 } | 93 } |
| 106 | 94 |
| 107 FakeGCMProfileService::FakeGCMProfileService(Profile* profile) | 95 FakeGCMProfileService::FakeGCMProfileService(Profile* profile) |
| 108 : collect_(false) {} | 96 : collect_(false) {} |
| 109 | 97 |
| 110 FakeGCMProfileService::~FakeGCMProfileService() {} | 98 FakeGCMProfileService::~FakeGCMProfileService() {} |
| 111 | 99 |
| 112 void FakeGCMProfileService::RegisterFinished( | 100 void FakeGCMProfileService::RegisterFinished( |
| 113 const std::string& app_id, | 101 const std::string& app_id, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 133 |
| 146 callback.Run(message.id, GCMClient::SUCCESS); | 134 callback.Run(message.id, GCMClient::SUCCESS); |
| 147 } | 135 } |
| 148 | 136 |
| 149 void FakeGCMProfileService::AddExpectedUnregisterResponse( | 137 void FakeGCMProfileService::AddExpectedUnregisterResponse( |
| 150 GCMClient::Result result) { | 138 GCMClient::Result result) { |
| 151 unregister_responses_.push_back(result); | 139 unregister_responses_.push_back(result); |
| 152 } | 140 } |
| 153 | 141 |
| 154 } // namespace gcm | 142 } // namespace gcm |
| OLD | NEW |