gcm_app_handler.h 2.8 KB

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