OLD | NEW |
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_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ |
6 #define CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ | 6 #define CHROME_BROWSER_SERVICES_GCM_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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 bool user_visible_only, | 62 bool user_visible_only, |
63 const content::PushMessagingService::RegisterCallback& callback) override; | 63 const content::PushMessagingService::RegisterCallback& callback) override; |
64 void RegisterFromWorker( | 64 void RegisterFromWorker( |
65 const GURL& requesting_origin, | 65 const GURL& requesting_origin, |
66 int64 service_worker_registration_id, | 66 int64 service_worker_registration_id, |
67 const std::string& sender_id, | 67 const std::string& sender_id, |
68 const content::PushMessagingService::RegisterCallback& callback) override; | 68 const content::PushMessagingService::RegisterCallback& callback) override; |
69 void Unregister( | 69 void Unregister( |
70 const GURL& requesting_origin, | 70 const GURL& requesting_origin, |
71 int64 service_worker_registration_id, | 71 int64 service_worker_registration_id, |
| 72 const std::string& sender_id, |
72 bool retry_on_failure, | 73 bool retry_on_failure, |
73 const content::PushMessagingService::UnregisterCallback&) override; | 74 const content::PushMessagingService::UnregisterCallback&) override; |
74 blink::WebPushPermissionStatus GetPermissionStatus( | 75 blink::WebPushPermissionStatus GetPermissionStatus( |
75 const GURL& requesting_origin, | 76 const GURL& requesting_origin, |
76 const GURL& embedding_origin) override; | 77 const GURL& embedding_origin) override; |
77 | 78 |
78 // content_settings::Observer implementation. | 79 // content_settings::Observer implementation. |
79 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 80 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
80 const ContentSettingsPattern& secondary_pattern, | 81 const ContentSettingsPattern& secondary_pattern, |
81 ContentSettingsType content_type, | 82 ContentSettingsType content_type, |
82 std::string resource_identifier) override; | 83 std::string resource_identifier) override; |
83 | 84 |
84 void SetProfileForTesting(Profile* profile); | 85 void SetProfileForTesting(Profile* profile); |
85 | 86 |
86 private: | 87 private: |
87 // A registration is pending until it has succeeded or failed. | 88 // A registration is pending until it has succeeded or failed. |
88 void IncreasePushRegistrationCount(int add, bool is_pending); | 89 void IncreasePushRegistrationCount(int add, bool is_pending); |
89 void DecreasePushRegistrationCount(int subtract, bool was_pending); | 90 void DecreasePushRegistrationCount(int subtract, bool was_pending); |
90 | 91 |
| 92 // OnMessage methods --------------------------------------------------------- |
| 93 |
91 void DeliverMessageCallback(const std::string& app_id_guid, | 94 void DeliverMessageCallback(const std::string& app_id_guid, |
92 const GURL& requesting_origin, | 95 const GURL& requesting_origin, |
93 int64 service_worker_registration_id, | 96 int64 service_worker_registration_id, |
94 const GCMClient::IncomingMessage& message, | 97 const GCMClient::IncomingMessage& message, |
95 content::PushDeliveryStatus status); | 98 content::PushDeliveryStatus status); |
96 | 99 |
97 // 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 |
98 // 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 |
99 // 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 |
100 // notification on their behalf. | 103 // notification on their behalf. |
101 void RequireUserVisibleUX(const GURL& requesting_origin, | 104 void RequireUserVisibleUX(const GURL& requesting_origin, |
102 int64 service_worker_registration_id); | 105 int64 service_worker_registration_id); |
103 void DidGetNotificationsShown( | 106 void DidGetNotificationsShown( |
104 const GURL& requesting_origin, | 107 const GURL& requesting_origin, |
105 int64 service_worker_registration_id, | 108 int64 service_worker_registration_id, |
106 bool notification_shown, | 109 bool notification_shown, |
107 bool notification_needed, | 110 bool notification_needed, |
108 const std::string& data, | 111 const std::string& data, |
109 bool success, | 112 bool success, |
110 bool not_found); | 113 bool not_found); |
111 | 114 |
| 115 // Register methods ---------------------------------------------------------- |
| 116 |
112 void RegisterEnd( | 117 void RegisterEnd( |
113 const content::PushMessagingService::RegisterCallback& callback, | 118 const content::PushMessagingService::RegisterCallback& callback, |
114 const std::string& registration_id, | 119 const std::string& registration_id, |
115 content::PushRegistrationStatus status); | 120 content::PushRegistrationStatus status); |
116 | 121 |
117 void DidRegister( | 122 void DidRegister( |
118 const PushMessagingApplicationId& application_id, | 123 const PushMessagingApplicationId& application_id, |
119 const content::PushMessagingService::RegisterCallback& callback, | 124 const content::PushMessagingService::RegisterCallback& callback, |
120 const std::string& registration_id, | 125 const std::string& registration_id, |
121 GCMClient::Result result); | 126 GCMClient::Result result); |
122 | 127 |
123 void DidRequestPermission( | 128 void DidRequestPermission( |
124 const PushMessagingApplicationId& application_id, | 129 const PushMessagingApplicationId& application_id, |
125 const std::string& sender_id, | 130 const std::string& sender_id, |
126 const content::PushMessagingService::RegisterCallback& callback, | 131 const content::PushMessagingService::RegisterCallback& callback, |
127 bool allow); | 132 bool allow); |
128 | 133 |
| 134 // Unregister methods -------------------------------------------------------- |
| 135 |
129 void Unregister(const std::string& app_id_guid, | 136 void Unregister(const std::string& app_id_guid, |
| 137 const std::string& sender_id, |
130 bool retry_on_failure, | 138 bool retry_on_failure, |
131 const content::PushMessagingService::UnregisterCallback&); | 139 const content::PushMessagingService::UnregisterCallback&); |
132 | 140 |
133 void DidUnregister(const std::string& app_id_guid, | 141 void DidUnregister(const std::string& app_id_guid, |
134 bool retry_on_failure, | 142 bool retry_on_failure, |
135 const content::PushMessagingService::UnregisterCallback&, | 143 const content::PushMessagingService::UnregisterCallback&, |
136 GCMClient::Result result); | 144 GCMClient::Result result); |
137 | 145 |
138 // Helper method that checks if a given origin is allowed to use Push. | 146 // OnContentSettingChanged methods ------------------------------------------- |
| 147 |
| 148 void UnregisterBecausePermissionRevoked(const PushMessagingApplicationId& id, |
| 149 const std::string& sender_id, |
| 150 bool success, bool not_found); |
| 151 |
| 152 // Helper methods ------------------------------------------------------------ |
| 153 |
| 154 // Checks if a given origin is allowed to use Push. |
139 bool HasPermission(const GURL& origin); | 155 bool HasPermission(const GURL& origin); |
140 | 156 |
141 GCMProfileService* gcm_profile_service_; // It owns us. | 157 GCMProfileService* gcm_profile_service_; // It owns us. |
142 | 158 |
143 Profile* profile_; // It owns our owner. | 159 Profile* profile_; // It owns our owner. |
144 | 160 |
145 int push_registration_count_; | 161 int push_registration_count_; |
146 int pending_push_registration_count_; | 162 int pending_push_registration_count_; |
147 | 163 |
148 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; | 164 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; |
149 | 165 |
150 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); | 166 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); |
151 }; | 167 }; |
152 | 168 |
153 } // namespace gcm | 169 } // namespace gcm |
154 | 170 |
155 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ | 171 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ |
OLD | NEW |