[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 5 | #ifndef COMPONENTS_INVALIDATION_GCM_NETWORK_CHANNEL_DELEGATE_H_ |
| 6 | #define COMPONENTS_INVALIDATION_GCM_NETWORK_CHANNEL_DELEGATE_H_ |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/callback.h" |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 11 | #include "components/gcm_driver/gcm_client.h" |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 12 | |
| 13 | class GoogleServiceAuthError; |
| 14 | |
| 15 | namespace syncer { |
| 16 | |
| 17 | // Delegate for GCMNetworkChannel. |
| 18 | // GCMNetworkChannel needs Register to register with GCM client and obtain gcm |
| 19 | // registration id. This id is used for building URL to cache invalidation |
| 20 | // endpoint. |
| 21 | // It needs RequestToken and InvalidateToken to get access token to include it |
| 22 | // in HTTP message to server. |
| 23 | // GCMNetworkChannel lives on IO thread therefore calls will be made on IO |
| 24 | // thread and callbacks should be invoked there as well. |
| 25 | class GCMNetworkChannelDelegate { |
| 26 | public: |
| 27 | typedef base::Callback<void(const GoogleServiceAuthError& error, |
| 28 | const std::string& token)> RequestTokenCallback; |
| 29 | typedef base::Callback<void(const std::string& registration_id, |
| 30 | gcm::GCMClient::Result result)> RegisterCallback; |
[email protected] | 88af124 | 2014-03-12 22:02:09 | [diff] [blame] | 31 | typedef base::Callback<void(const std::string& message, |
| 32 | const std::string& echo_token)> MessageCallback; |
[email protected] | afff175 | 2014-06-20 04:42:10 | [diff] [blame] | 33 | typedef base::Callback<void(bool online)> ConnectionStateCallback; |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 34 | |
| 35 | virtual ~GCMNetworkChannelDelegate() {} |
| 36 | |
[email protected] | dd507f5 | 2014-06-19 01:27:56 | [diff] [blame] | 37 | virtual void Initialize(ConnectionStateCallback callback) = 0; |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 38 | // Request access token. Callback should be called either with access token or |
| 39 | // error code. |
| 40 | virtual void RequestToken(RequestTokenCallback callback) = 0; |
| 41 | // Invalidate access token that was rejected by server. |
| 42 | virtual void InvalidateToken(const std::string& token) = 0; |
| 43 | |
[email protected] | df84c53 | 2014-04-25 15:36:54 | [diff] [blame] | 44 | // Request registration_id from GCMService. Callback should be called with |
| 45 | // either registration id or error code. |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 46 | virtual void Register(RegisterCallback callback) = 0; |
[email protected] | 88af124 | 2014-03-12 22:02:09 | [diff] [blame] | 47 | // Provide callback for incoming messages from GCM. |
| 48 | virtual void SetMessageReceiver(MessageCallback callback) = 0; |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 49 | }; |
| 50 | } // namespace syncer |
| 51 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 52 | #endif // COMPONENTS_INVALIDATION_GCM_NETWORK_CHANNEL_DELEGATE_H_ |