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

Side by Side Diff: chrome/browser/services/gcm/fake_gcm_profile_service.cc

Issue 1851423003: Make Web Push use InstanceID tokens instead of GCM registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid4default
Patch Set: Address review comments, and rewrite following rebase (e.g. no longer depends on NestedMessagePumpA… Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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/thread_task_runner_handle.h" 16 #include "base/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 {
Peter Beverloo 2016/04/21 13:26:19 Can we remove the driver override from the Instanc
johnme 2016/05/25 14:11:51 Done.
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 194 }
196 195
197 void FakeGCMProfileService::DispatchMessage(const std::string& app_id, 196 void FakeGCMProfileService::DispatchMessage(const std::string& app_id,
198 const IncomingMessage& message) { 197 const IncomingMessage& message) {
199 CustomFakeGCMDriver* custom_driver = 198 CustomFakeGCMDriver* custom_driver =
200 static_cast<CustomFakeGCMDriver*>(driver()); 199 static_cast<CustomFakeGCMDriver*>(driver());
201 custom_driver->OnDispatchMessage(app_id, message); 200 custom_driver->OnDispatchMessage(app_id, message);
202 } 201 }
203 202
204 } // namespace gcm 203 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698