| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ |
| 6 #define COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ | 6 #define COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "components/gcm_driver/gcm_client.h" | 10 #include "components/gcm_driver/gcm_client.h" |
| 11 | 11 |
| 12 namespace gcm { | 12 namespace gcm { |
| 13 | 13 |
| 14 // Defines the interface to provide handling and event routing logic for a given | 14 // Defines the interface to provide handling and event routing logic for a given |
| 15 // app. | 15 // app. |
| 16 class GCMAppHandler { | 16 class GCMAppHandler { |
| 17 public: | 17 public: |
| 18 GCMAppHandler(); | 18 GCMAppHandler(); |
| 19 virtual ~GCMAppHandler(); | 19 virtual ~GCMAppHandler(); |
| 20 | 20 |
| 21 // Called to do all the cleanup when GCM is shutting down. | 21 // Called to do all the cleanup when GCM is shutting down. |
| 22 // In the case that multiple apps share the same app handler, it should be | 22 // In the case that multiple apps share the same app handler, it should be |
| 23 // make safe for ShutdownHandler to be called multiple times. | 23 // make safe for ShutdownHandler to be called multiple times. |
| 24 virtual void ShutdownHandler() = 0; | 24 virtual void ShutdownHandler() = 0; |
| 25 | 25 |
| 26 // Called when the GCM store is reset (e.g. due to corruption), which changes |
| 27 // the device ID, invalidating all prior registrations. Any stored state |
| 28 // related to GCM registrations or InstanceIDs should be deleted. This should |
| 29 // only be considered a defense in depth, as this method will not be called if |
| 30 // the store is reset before this app handler is registered; hence it is |
| 31 // recommended to regularly revalidate any stored registrations/InstanceIDs. |
| 32 // TODO(johnme): GCMDriver doesn't yet provide an API for revalidating them. |
| 33 virtual void OnStoreReset() = 0; |
| 34 |
| 26 // Called when a GCM message has been received. | 35 // Called when a GCM message has been received. |
| 27 virtual void OnMessage(const std::string& app_id, | 36 virtual void OnMessage(const std::string& app_id, |
| 28 const IncomingMessage& message) = 0; | 37 const IncomingMessage& message) = 0; |
| 29 | 38 |
| 30 // Called when some GCM messages have been deleted from the server. | 39 // Called when some GCM messages have been deleted from the server. |
| 31 virtual void OnMessagesDeleted(const std::string& app_id) = 0; | 40 virtual void OnMessagesDeleted(const std::string& app_id) = 0; |
| 32 | 41 |
| 33 // Called when a GCM message failed to be delivered. | 42 // Called when a GCM message failed to be delivered. |
| 34 virtual void OnSendError( | 43 virtual void OnSendError( |
| 35 const std::string& app_id, | 44 const std::string& app_id, |
| 36 const GCMClient::SendErrorDetails& send_error_details) = 0; | 45 const GCMClient::SendErrorDetails& send_error_details) = 0; |
| 37 | 46 |
| 38 // Called when a GCM message was received by GCM server. | 47 // Called when a GCM message was received by GCM server. |
| 39 virtual void OnSendAcknowledged(const std::string& app_id, | 48 virtual void OnSendAcknowledged(const std::string& app_id, |
| 40 const std::string& message_id) = 0; | 49 const std::string& message_id) = 0; |
| 41 | 50 |
| 42 // If no app handler has been added with the exact app_id of an incoming | 51 // If no app handler has been added with the exact app_id of an incoming |
| 43 // event, all handlers will be asked (in arbitrary order) whether they can | 52 // event, all handlers will be asked (in arbitrary order) whether they can |
| 44 // handle the app_id, and the first to return true will receive the event. | 53 // handle the app_id, and the first to return true will receive the event. |
| 45 virtual bool CanHandle(const std::string& app_id) const; | 54 virtual bool CanHandle(const std::string& app_id) const; |
| 46 }; | 55 }; |
| 47 | 56 |
| 48 } // namespace gcm | 57 } // namespace gcm |
| 49 | 58 |
| 50 #endif // COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ | 59 #endif // COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ |
| OLD | NEW |