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 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ 6 #define COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ 7 8 #include <string> 9 10 #include "components/gcm_driver/gcm_client.h" 11 12 namespace gcm { 13 14 // Defines the interface to provide handling and event routing logic for a given 15 // app. 16 class GCMAppHandler { 17 public: 18 GCMAppHandler(); 19 virtual ~GCMAppHandler(); 20 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 23 // make safe for ShutdownHandler to be called multiple times. 24 virtual void ShutdownHandler() = 0; 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 35 // Called when a GCM message has been received. 36 virtual void OnMessage(const std::string& app_id, 37 const IncomingMessage& message) = 0; 38 39 // Called when some GCM messages have been deleted from the server. 40 virtual void OnMessagesDeleted(const std::string& app_id) = 0; 41 42 // Called when a GCM message failed to be delivered. 43 virtual void OnSendError( 44 const std::string& app_id, 45 const GCMClient::SendErrorDetails& send_error_details) = 0; 46 47 // Called when a GCM message was received by GCM server. 48 virtual void OnSendAcknowledged(const std::string& app_id, 49 const std::string& message_id) = 0; 50 51 // Called when a GCM message has been received but decryption failed. 52 // |message_id| is a message identifier sent by the GCM server. 53 // |error_message| is human-readable description of the error, for reporting 54 // purposes. By default this handler does nothing. 55 virtual void OnMessageDecryptionFailed(const std::string& app_id, 56 const std::string& message_id, 57 const std::string& error_message); 58 59 // If no app handler has been added with the exact app_id of an incoming 60 // event, all handlers will be asked (in arbitrary order) whether they can 61 // handle the app_id, and the first to return true will receive the event. 62 virtual bool CanHandle(const std::string& app_id) const; 63 }; 64 65 } // namespace gcm 66 67 #endif // COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_ 68