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/gcm_driver/gcm_app_handler.h" | 10 #include "components/gcm_driver/gcm_app_handler.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 const GURL& requesting_origin, | 68 const GURL& requesting_origin, |
69 int64 service_worker_registration_id, | 69 int64 service_worker_registration_id, |
70 const content::PushMessagingService::UnregisterCallback&) override; | 70 const content::PushMessagingService::UnregisterCallback&) override; |
71 blink::WebPushPermissionStatus GetPermissionStatus( | 71 blink::WebPushPermissionStatus GetPermissionStatus( |
72 const GURL& requesting_origin, | 72 const GURL& requesting_origin, |
73 const GURL& embedding_origin) override; | 73 const GURL& embedding_origin) override; |
74 | 74 |
75 void SetProfileForTesting(Profile* profile); | 75 void SetProfileForTesting(Profile* profile); |
76 | 76 |
77 private: | 77 private: |
78 void IncreasePushRegistrationCount(int add); | 78 // A registration is pending until it has succeeded or failed. |
79 void DecreasePushRegistrationCount(int subtract); | 79 void IncreasePushRegistrationCount(int add, bool is_pending); |
| 80 void DecreasePushRegistrationCount(int subtract, bool was_pending); |
80 | 81 |
81 void DeliverMessageCallback(const PushMessagingApplicationId& application_id, | 82 void DeliverMessageCallback(const PushMessagingApplicationId& application_id, |
82 const GCMClient::IncomingMessage& message, | 83 const GCMClient::IncomingMessage& message, |
83 content::PushDeliveryStatus status); | 84 content::PushDeliveryStatus status); |
84 | 85 |
85 // Developers are required to display a Web Notification in response to an | 86 // Developers are required to display a Web Notification in response to an |
86 // incoming push message in order to clarify to the user that something has | 87 // incoming push message in order to clarify to the user that something has |
87 // happened in the background. When they forget to do so, display a default | 88 // happened in the background. When they forget to do so, display a default |
88 // notification on their behalf. | 89 // notification on their behalf. |
89 void RequireUserVisibleUX(const PushMessagingApplicationId& application_id); | 90 void RequireUserVisibleUX(const PushMessagingApplicationId& application_id); |
(...skipping 23 matching lines...) Expand all Loading... |
113 | 114 |
114 void Unregister(const PushMessagingApplicationId& application_id, | 115 void Unregister(const PushMessagingApplicationId& application_id, |
115 const content::PushMessagingService::UnregisterCallback&); | 116 const content::PushMessagingService::UnregisterCallback&); |
116 | 117 |
117 void DidUnregister(const content::PushMessagingService::UnregisterCallback&, | 118 void DidUnregister(const content::PushMessagingService::UnregisterCallback&, |
118 GCMClient::Result result); | 119 GCMClient::Result result); |
119 | 120 |
120 // Helper method that checks if a given origin is allowed to use Push. | 121 // Helper method that checks if a given origin is allowed to use Push. |
121 bool HasPermission(const GURL& origin); | 122 bool HasPermission(const GURL& origin); |
122 | 123 |
123 // Adds this service as an app handler to the GCMDriver if it has not been | |
124 // added yet. | |
125 void AddAppHandlerIfNecessary(); | |
126 | |
127 GCMProfileService* gcm_profile_service_; // It owns us. | 124 GCMProfileService* gcm_profile_service_; // It owns us. |
128 | 125 |
129 Profile* profile_; // It owns our owner. | 126 Profile* profile_; // It owns our owner. |
130 | 127 |
131 int push_registration_count_; | 128 int push_registration_count_; |
| 129 int pending_push_registration_count_; |
132 | 130 |
133 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; | 131 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; |
134 | 132 |
135 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); | 133 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); |
136 }; | 134 }; |
137 | 135 |
138 } // namespace gcm | 136 } // namespace gcm |
139 | 137 |
140 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ | 138 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_ |
OLD | NEW |