| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "components/gcm_driver/fake_gcm_client_factory.h" | 18 #include "components/gcm_driver/fake_gcm_client_factory.h" |
| 19 #include "components/gcm_driver/fake_gcm_driver.h" | 19 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" |
| 20 #include "components/gcm_driver/gcm_driver.h" | |
| 21 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 22 | 21 |
| 23 namespace gcm { | 22 namespace gcm { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 class CustomFakeGCMDriver : public FakeGCMDriver { | 26 class CustomFakeGCMDriver : public instance_id::FakeGCMDriverForInstanceID { |
| 28 public: | 27 public: |
| 29 explicit CustomFakeGCMDriver(FakeGCMProfileService* service); | 28 explicit CustomFakeGCMDriver(FakeGCMProfileService* service); |
| 30 ~CustomFakeGCMDriver() override; | 29 ~CustomFakeGCMDriver() override; |
| 31 | 30 |
| 32 void OnRegisterFinished(const std::string& app_id, | 31 void OnRegisterFinished(const std::string& app_id, |
| 33 const std::string& registration_id, | 32 const std::string& registration_id, |
| 34 GCMClient::Result result); | 33 GCMClient::Result result); |
| 35 void OnUnregisterFinished(const std::string& app_id, | 34 void OnUnregisterFinished(const std::string& app_id, |
| 36 GCMClient::Result result); | 35 GCMClient::Result result); |
| 37 void OnSendFinished(const std::string& app_id, | 36 void OnSendFinished(const std::string& app_id, |
| 38 const std::string& message_id, | 37 const std::string& message_id, |
| 39 GCMClient::Result result); | 38 GCMClient::Result result); |
| 40 | 39 |
| 41 void OnDispatchMessage(const std::string& app_id, | 40 void OnDispatchMessage(const std::string& app_id, |
| 42 const IncomingMessage& message); | 41 const IncomingMessage& message); |
| 43 | 42 |
| 44 protected: | 43 protected: |
| 45 // FakeGCMDriver overrides: | 44 // FakeGCMDriverForInstanceID overrides: |
| 46 void RegisterImpl(const std::string& app_id, | 45 void RegisterImpl(const std::string& app_id, |
| 47 const std::vector<std::string>& sender_ids) override; | 46 const std::vector<std::string>& sender_ids) override; |
| 48 void UnregisterImpl(const std::string& app_id) override; | 47 void UnregisterImpl(const std::string& app_id) override; |
| 49 void UnregisterWithSenderIdImpl(const std::string& app_id, | 48 void UnregisterWithSenderIdImpl(const std::string& app_id, |
| 50 const std::string& sender_id) override; | 49 const std::string& sender_id) override; |
| 51 void SendImpl(const std::string& app_id, | 50 void SendImpl(const std::string& app_id, |
| 52 const std::string& receiver_id, | 51 const std::string& receiver_id, |
| 53 const OutgoingMessage& message) override; | 52 const OutgoingMessage& message) override; |
| 54 | 53 |
| 55 private: | 54 private: |
| 56 FakeGCMProfileService* service_; | 55 FakeGCMProfileService* service_; |
| 57 | 56 |
| 58 DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver); | 57 DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver); |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 CustomFakeGCMDriver::CustomFakeGCMDriver(FakeGCMProfileService* service) | 60 CustomFakeGCMDriver::CustomFakeGCMDriver(FakeGCMProfileService* service) |
| 62 : FakeGCMDriver(base::ThreadTaskRunnerHandle::Get()), | 61 : instance_id::FakeGCMDriverForInstanceID( |
| 63 service_(service) { | 62 base::ThreadTaskRunnerHandle::Get()), |
| 64 } | 63 service_(service) {} |
| 65 | 64 |
| 66 CustomFakeGCMDriver::~CustomFakeGCMDriver() { | 65 CustomFakeGCMDriver::~CustomFakeGCMDriver() { |
| 67 } | 66 } |
| 68 | 67 |
| 69 void CustomFakeGCMDriver::RegisterImpl( | 68 void CustomFakeGCMDriver::RegisterImpl( |
| 70 const std::string& app_id, | 69 const std::string& app_id, |
| 71 const std::vector<std::string>& sender_ids) { | 70 const std::vector<std::string>& sender_ids) { |
| 72 base::ThreadTaskRunnerHandle::Get()->PostTask( | 71 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 73 FROM_HERE, base::Bind(&FakeGCMProfileService::RegisterFinished, | 72 FROM_HERE, base::Bind(&FakeGCMProfileService::RegisterFinished, |
| 74 base::Unretained(service_), app_id, sender_ids)); | 73 base::Unretained(service_), app_id, sender_ids)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 195 } |
| 197 | 196 |
| 198 void FakeGCMProfileService::DispatchMessage(const std::string& app_id, | 197 void FakeGCMProfileService::DispatchMessage(const std::string& app_id, |
| 199 const IncomingMessage& message) { | 198 const IncomingMessage& message) { |
| 200 CustomFakeGCMDriver* custom_driver = | 199 CustomFakeGCMDriver* custom_driver = |
| 201 static_cast<CustomFakeGCMDriver*>(driver()); | 200 static_cast<CustomFakeGCMDriver*>(driver()); |
| 202 custom_driver->OnDispatchMessage(app_id, message); | 201 custom_driver->OnDispatchMessage(app_id, message); |
| 203 } | 202 } |
| 204 | 203 |
| 205 } // namespace gcm | 204 } // namespace gcm |
| OLD | NEW |