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

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

Powered by Google App Engine
This is Rietveld 408576698