| 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 "components/gcm_driver/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" | |
| 18 #include "components/gcm_driver/fake_gcm_client_factory.h" | 17 #include "components/gcm_driver/fake_gcm_client_factory.h" |
| 19 #include "components/gcm_driver/fake_gcm_driver.h" | 18 #include "components/gcm_driver/fake_gcm_driver.h" |
| 20 #include "components/gcm_driver/gcm_driver.h" | 19 #include "components/gcm_driver/gcm_driver.h" |
| 21 #include "content/public/browser/browser_context.h" | |
| 22 | 20 |
| 23 namespace gcm { | 21 namespace gcm { |
| 24 | 22 |
| 25 namespace { | 23 namespace { |
| 26 | 24 |
| 27 class CustomFakeGCMDriver : public FakeGCMDriver { | 25 class CustomFakeGCMDriver : public FakeGCMDriver { |
| 28 public: | 26 public: |
| 29 explicit CustomFakeGCMDriver(FakeGCMProfileService* service); | 27 explicit CustomFakeGCMDriver(FakeGCMProfileService* service); |
| 30 ~CustomFakeGCMDriver() override; | 28 ~CustomFakeGCMDriver() override; |
| 31 | 29 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void CustomFakeGCMDriver::OnDispatchMessage(const std::string& app_id, | 112 void CustomFakeGCMDriver::OnDispatchMessage(const std::string& app_id, |
| 115 const IncomingMessage& message) { | 113 const IncomingMessage& message) { |
| 116 DispatchMessage(app_id, message); | 114 DispatchMessage(app_id, message); |
| 117 } | 115 } |
| 118 | 116 |
| 119 } // namespace | 117 } // namespace |
| 120 | 118 |
| 121 // static | 119 // static |
| 122 std::unique_ptr<KeyedService> FakeGCMProfileService::Build( | 120 std::unique_ptr<KeyedService> FakeGCMProfileService::Build( |
| 123 content::BrowserContext* context) { | 121 content::BrowserContext* context) { |
| 124 Profile* profile = static_cast<Profile*>(context); | 122 std::unique_ptr<FakeGCMProfileService> service(new FakeGCMProfileService); |
| 125 std::unique_ptr<FakeGCMProfileService> service( | |
| 126 new FakeGCMProfileService(profile)); | |
| 127 service->SetDriverForTesting(new CustomFakeGCMDriver(service.get())); | 123 service->SetDriverForTesting(new CustomFakeGCMDriver(service.get())); |
| 128 return std::move(service); | 124 return std::move(service); |
| 129 } | 125 } |
| 130 | 126 |
| 131 FakeGCMProfileService::FakeGCMProfileService(Profile* profile) | 127 FakeGCMProfileService::FakeGCMProfileService() |
| 132 : collect_(false), | 128 : collect_(false), |
| 133 registration_count_(0) { | 129 registration_count_(0) { |
| 134 } | 130 } |
| 135 | 131 |
| 136 FakeGCMProfileService::~FakeGCMProfileService() {} | 132 FakeGCMProfileService::~FakeGCMProfileService() {} |
| 137 | 133 |
| 138 void FakeGCMProfileService::RegisterFinished( | 134 void FakeGCMProfileService::RegisterFinished( |
| 139 const std::string& app_id, | 135 const std::string& app_id, |
| 140 const std::vector<std::string>& sender_ids) { | 136 const std::vector<std::string>& sender_ids) { |
| 141 if (collect_) { | 137 if (collect_) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 192 } |
| 197 | 193 |
| 198 void FakeGCMProfileService::DispatchMessage(const std::string& app_id, | 194 void FakeGCMProfileService::DispatchMessage(const std::string& app_id, |
| 199 const IncomingMessage& message) { | 195 const IncomingMessage& message) { |
| 200 CustomFakeGCMDriver* custom_driver = | 196 CustomFakeGCMDriver* custom_driver = |
| 201 static_cast<CustomFakeGCMDriver*>(driver()); | 197 static_cast<CustomFakeGCMDriver*>(driver()); |
| 202 custom_driver->OnDispatchMessage(app_id, message); | 198 custom_driver->OnDispatchMessage(app_id, message); |
| 203 } | 199 } |
| 204 | 200 |
| 205 } // namespace gcm | 201 } // namespace gcm |
| OLD | NEW |