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