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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_service_impl.h

Issue 955673004: Move gcm-independent parts of push messaging out of gcm namespace and directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moving all of push_messaging out Created 5 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ 5 #ifndef CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ 6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "components/content_settings/core/browser/content_settings_observer.h" 10 #include "components/content_settings/core/browser/content_settings_observer.h"
11 #include "components/gcm_driver/gcm_app_handler.h" 11 #include "components/gcm_driver/gcm_app_handler.h"
12 #include "components/gcm_driver/gcm_client.h" 12 #include "components/gcm_driver/gcm_client.h"
13 #include "components/keyed_service/core/keyed_service.h"
13 #include "content/public/browser/push_messaging_service.h" 14 #include "content/public/browser/push_messaging_service.h"
14 #include "content/public/common/push_messaging_status.h" 15 #include "content/public/common/push_messaging_status.h"
15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi ssionStatus.h" 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi ssionStatus.h"
16 17
17 class Profile; 18 class Profile;
19 class PushMessagingApplicationId;
18 20
19 namespace user_prefs { 21 namespace user_prefs {
20 class PrefRegistrySyncable; 22 class PrefRegistrySyncable;
21 } 23 }
22 24
23 namespace gcm { 25 namespace gcm {
24 26 class GCMDriver;
25 class GCMProfileService; 27 class GCMProfileService;
26 class PushMessagingApplicationId; 28 }
27 29
28 class PushMessagingServiceImpl : public content::PushMessagingService, 30 class PushMessagingServiceImpl : public content::PushMessagingService,
29 public GCMAppHandler, 31 public gcm::GCMAppHandler,
30 public content_settings::Observer { 32 public content_settings::Observer,
33 public KeyedService {
31 public: 34 public:
32 // Register profile-specific prefs for GCM. 35 // Register profile-specific prefs for GCM.
33 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
34 37
35 // If any Service Workers are using push, starts GCM and adds an app handler. 38 explicit PushMessagingServiceImpl(Profile* profile);
36 static void InitializeForProfile(Profile* profile);
37
38 PushMessagingServiceImpl(GCMProfileService* gcm_profile_service,
39 Profile* profile);
40 ~PushMessagingServiceImpl() override; 39 ~PushMessagingServiceImpl() override;
41 40
42 // GCMAppHandler implementation. 41 // gcm::GCMAppHandler implementation.
43 void ShutdownHandler() override; 42 void ShutdownHandler() override;
44 void OnMessage(const std::string& app_id, 43 void OnMessage(const std::string& app_id,
45 const GCMClient::IncomingMessage& message) override; 44 const gcm::GCMClient::IncomingMessage& message) override;
46 void OnMessagesDeleted(const std::string& app_id) override; 45 void OnMessagesDeleted(const std::string& app_id) override;
47 void OnSendError( 46 void OnSendError(
48 const std::string& app_id, 47 const std::string& app_id,
49 const GCMClient::SendErrorDetails& send_error_details) override; 48 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
50 void OnSendAcknowledged(const std::string& app_id, 49 void OnSendAcknowledged(const std::string& app_id,
51 const std::string& message_id) override; 50 const std::string& message_id) override;
52 bool CanHandle(const std::string& app_id) const override; 51 bool CanHandle(const std::string& app_id) const override;
53 52
54 // content::PushMessagingService implementation: 53 // content::PushMessagingService implementation:
55 GURL GetPushEndpoint() override; 54 GURL GetPushEndpoint() override;
56 void RegisterFromDocument( 55 void RegisterFromDocument(
57 const GURL& requesting_origin, 56 const GURL& requesting_origin,
58 int64 service_worker_registration_id, 57 int64 service_worker_registration_id,
59 const std::string& sender_id, 58 const std::string& sender_id,
(...skipping 15 matching lines...) Expand all
75 blink::WebPushPermissionStatus GetPermissionStatus( 74 blink::WebPushPermissionStatus GetPermissionStatus(
76 const GURL& requesting_origin, 75 const GURL& requesting_origin,
77 const GURL& embedding_origin) override; 76 const GURL& embedding_origin) override;
78 77
79 // content_settings::Observer implementation. 78 // content_settings::Observer implementation.
80 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, 79 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern,
81 const ContentSettingsPattern& secondary_pattern, 80 const ContentSettingsPattern& secondary_pattern,
82 ContentSettingsType content_type, 81 ContentSettingsType content_type,
83 std::string resource_identifier) override; 82 std::string resource_identifier) override;
84 83
85 void SetProfileForTesting(Profile* profile); 84 // KeyedService implementation.
85 void Shutdown() override;
86 86
87 private: 87 private:
88 // A registration is pending until it has succeeded or failed. 88 // A registration is pending until it has succeeded or failed.
89 void IncreasePushRegistrationCount(int add, bool is_pending); 89 void IncreasePushRegistrationCount(int add, bool is_pending);
90 void DecreasePushRegistrationCount(int subtract, bool was_pending); 90 void DecreasePushRegistrationCount(int subtract, bool was_pending);
91 91
92 // OnMessage methods --------------------------------------------------------- 92 // OnMessage methods ---------------------------------------------------------
93 93
94 void DeliverMessageCallback(const std::string& app_id_guid, 94 void DeliverMessageCallback(const std::string& app_id_guid,
95 const GURL& requesting_origin, 95 const GURL& requesting_origin,
96 int64 service_worker_registration_id, 96 int64 service_worker_registration_id,
97 const GCMClient::IncomingMessage& message, 97 const gcm::GCMClient::IncomingMessage& message,
98 content::PushDeliveryStatus status); 98 content::PushDeliveryStatus status);
99 99
100 // Developers are required to display a Web Notification in response to an 100 // Developers are required to display a Web Notification in response to an
101 // incoming push message in order to clarify to the user that something has 101 // incoming push message in order to clarify to the user that something has
102 // happened in the background. When they forget to do so, display a default 102 // happened in the background. When they forget to do so, display a default
103 // notification on their behalf. 103 // notification on their behalf.
104 void RequireUserVisibleUX(const GURL& requesting_origin, 104 void RequireUserVisibleUX(const GURL& requesting_origin,
105 int64 service_worker_registration_id); 105 int64 service_worker_registration_id);
106 void DidGetNotificationsShown( 106 void DidGetNotificationsShown(
107 const GURL& requesting_origin, 107 const GURL& requesting_origin,
108 int64 service_worker_registration_id, 108 int64 service_worker_registration_id,
109 bool notification_shown, 109 bool notification_shown,
110 bool notification_needed, 110 bool notification_needed,
111 const std::string& data, 111 const std::string& data,
112 bool success, 112 bool success,
113 bool not_found); 113 bool not_found);
114 114
115 // Register methods ---------------------------------------------------------- 115 // Register methods ----------------------------------------------------------
116 116
117 void RegisterEnd( 117 void RegisterEnd(
118 const content::PushMessagingService::RegisterCallback& callback, 118 const content::PushMessagingService::RegisterCallback& callback,
119 const std::string& registration_id, 119 const std::string& registration_id,
120 content::PushRegistrationStatus status); 120 content::PushRegistrationStatus status);
121 121
122 void DidRegister( 122 void DidRegister(
123 const PushMessagingApplicationId& application_id, 123 const PushMessagingApplicationId& application_id,
124 const content::PushMessagingService::RegisterCallback& callback, 124 const content::PushMessagingService::RegisterCallback& callback,
125 const std::string& registration_id, 125 const std::string& registration_id,
126 GCMClient::Result result); 126 gcm::GCMClient::Result result);
127 127
128 void DidRequestPermission( 128 void DidRequestPermission(
129 const PushMessagingApplicationId& application_id, 129 const PushMessagingApplicationId& application_id,
130 const std::string& sender_id, 130 const std::string& sender_id,
131 const content::PushMessagingService::RegisterCallback& callback, 131 const content::PushMessagingService::RegisterCallback& callback,
132 bool allow); 132 bool allow);
133 133
134 // Unregister methods -------------------------------------------------------- 134 // Unregister methods --------------------------------------------------------
135 135
136 void Unregister(const std::string& app_id_guid, 136 void Unregister(const std::string& app_id_guid,
137 const std::string& sender_id, 137 const std::string& sender_id,
138 bool retry_on_failure, 138 bool retry_on_failure,
139 const content::PushMessagingService::UnregisterCallback&); 139 const content::PushMessagingService::UnregisterCallback&);
140 140
141 void DidUnregister(const std::string& app_id_guid, 141 void DidUnregister(const std::string& app_id_guid,
142 bool retry_on_failure, 142 bool retry_on_failure,
143 const content::PushMessagingService::UnregisterCallback&, 143 const content::PushMessagingService::UnregisterCallback&,
144 GCMClient::Result result); 144 gcm::GCMClient::Result result);
145 145
146 // OnContentSettingChanged methods ------------------------------------------- 146 // OnContentSettingChanged methods -------------------------------------------
147 147
148 void UnregisterBecausePermissionRevoked(const PushMessagingApplicationId& id, 148 void UnregisterBecausePermissionRevoked(const PushMessagingApplicationId& id,
149 const std::string& sender_id, 149 const std::string& sender_id,
150 bool success, bool not_found); 150 bool success, bool not_found);
151 151
152 // Helper methods ------------------------------------------------------------ 152 // Helper methods ------------------------------------------------------------
153 153
154 // Checks if a given origin is allowed to use Push. 154 // Checks if a given origin is allowed to use Push.
155 bool HasPermission(const GURL& origin); 155 bool HasPermission(const GURL& origin);
156 156
157 GCMProfileService* gcm_profile_service_; // It owns us. 157 gcm::GCMDriver* gcm_driver() const;
158 158
159 Profile* profile_; // It owns our owner. 159 gcm::GCMProfileService* gcm_profile_service_;
Peter Beverloo 2015/02/25 23:55:05 Could you add a comment that it's safe to hold on
kbalazs 2015/02/27 22:40:36 Done.
160
161 Profile* profile_;
160 162
161 int push_registration_count_; 163 int push_registration_count_;
162 int pending_push_registration_count_; 164 int pending_push_registration_count_;
163 165
164 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; 166 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_;
165 167
166 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); 168 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl);
167 }; 169 };
168 170
169 } // namespace gcm 171 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_
170
171 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698