OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 GOOGLE_APIS_GCM_GCM_CLIENT_H_ | 5 #ifndef GOOGLE_APIS_GCM_GCM_CLIENT_H_ |
6 #define GOOGLE_APIS_GCM_GCM_CLIENT_H_ | 6 #define GOOGLE_APIS_GCM_GCM_CLIENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "google_apis/gcm/base/gcm_export.h" | 13 #include "google_apis/gcm/base/gcm_export.h" |
14 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 14 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 15 #include "google_apis/gcm/public/gcm_types.h" |
15 | 16 |
16 template <class T> class scoped_refptr; | 17 template <class T> class scoped_refptr; |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 class FilePath; | 20 class FilePath; |
20 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
21 } | 22 } |
22 | 23 |
23 namespace checkin_proto { | 24 namespace checkin_proto { |
24 class ChromeBuildProto; | 25 class ChromeBuildProto; |
25 } | 26 } |
26 | 27 |
27 namespace net { | 28 namespace net { |
28 class URLRequestContextGetter; | 29 class URLRequestContextGetter; |
29 } | 30 } |
30 | 31 |
31 namespace gcm { | 32 namespace gcm { |
32 | 33 |
33 // Interface that encapsulates the network communications with the Google Cloud | 34 // Interface that encapsulates the network communications with the Google Cloud |
34 // Messaging server. This interface is not supposed to be thread-safe. | 35 // Messaging server. This interface is not supposed to be thread-safe. |
35 class GCM_EXPORT GCMClient { | 36 class GCM_EXPORT GCMClient { |
36 public: | 37 public: |
37 enum Result { | |
38 // Successful operation. | |
39 SUCCESS, | |
40 // Invalid parameter. | |
41 INVALID_PARAMETER, | |
42 // Profile not signed in. | |
43 NOT_SIGNED_IN, | |
44 // Previous asynchronous operation is still pending to finish. Certain | |
45 // operation, like register, is only allowed one at a time. | |
46 ASYNC_OPERATION_PENDING, | |
47 // Network socket error. | |
48 NETWORK_ERROR, | |
49 // Problem at the server. | |
50 SERVER_ERROR, | |
51 // Exceeded the specified TTL during message sending. | |
52 TTL_EXCEEDED, | |
53 // Other errors. | |
54 UNKNOWN_ERROR | |
55 }; | |
56 | |
57 // Message data consisting of key-value pairs. | |
58 typedef std::map<std::string, std::string> MessageData; | |
59 | |
60 // Message to be delivered to the other party. | |
61 struct GCM_EXPORT OutgoingMessage { | |
62 OutgoingMessage(); | |
63 ~OutgoingMessage(); | |
64 | |
65 // Message ID. | |
66 std::string id; | |
67 // In seconds. | |
68 int time_to_live; | |
69 MessageData data; | |
70 }; | |
71 | |
72 // Message being received from the other party. | |
73 struct GCM_EXPORT IncomingMessage { | |
74 IncomingMessage(); | |
75 ~IncomingMessage(); | |
76 | |
77 MessageData data; | |
78 std::string collapse_key; | |
79 std::string sender_id; | |
80 }; | |
81 | |
82 // Detailed information of the Send Error event. | |
83 struct GCM_EXPORT SendErrorDetails { | |
84 SendErrorDetails(); | |
85 ~SendErrorDetails(); | |
86 | |
87 std::string message_id; | |
88 MessageData additional_data; | |
89 Result result; | |
90 }; | |
91 | |
92 // Internal states and activity statistics of a GCM client. | 38 // Internal states and activity statistics of a GCM client. |
93 struct GCM_EXPORT GCMStatistics { | 39 struct GCM_EXPORT GCMStatistics { |
94 public: | 40 public: |
95 GCMStatistics(); | 41 GCMStatistics(); |
96 ~GCMStatistics(); | 42 ~GCMStatistics(); |
97 | 43 |
98 bool is_recording; | 44 bool is_recording; |
99 bool gcm_client_created; | 45 bool gcm_client_created; |
100 std::string gcm_client_state; | 46 std::string gcm_client_state; |
101 bool connection_client_created; | 47 bool connection_client_created; |
(...skipping 15 matching lines...) Expand all Loading... |
117 // |registration_id|: non-empty if the registration completed successfully. | 63 // |registration_id|: non-empty if the registration completed successfully. |
118 // |result|: the type of the error if an error occured, success otherwise. | 64 // |result|: the type of the error if an error occured, success otherwise. |
119 virtual void OnRegisterFinished(const std::string& app_id, | 65 virtual void OnRegisterFinished(const std::string& app_id, |
120 const std::string& registration_id, | 66 const std::string& registration_id, |
121 Result result) = 0; | 67 Result result) = 0; |
122 | 68 |
123 // Called when the unregistration completed. | 69 // Called when the unregistration completed. |
124 // |app_id|: application ID. | 70 // |app_id|: application ID. |
125 // |result|: result of the unregistration. | 71 // |result|: result of the unregistration. |
126 virtual void OnUnregisterFinished(const std::string& app_id, | 72 virtual void OnUnregisterFinished(const std::string& app_id, |
127 GCMClient::Result result) = 0; | 73 Result result) = 0; |
128 | 74 |
129 // Called when the message is scheduled to send successfully or an error | 75 // Called when the message is scheduled to send successfully or an error |
130 // occurs. | 76 // occurs. |
131 // |app_id|: application ID. | 77 // |app_id|: application ID. |
132 // |message_id|: ID of the message being sent. | 78 // |message_id|: ID of the message being sent. |
133 // |result|: the type of the error if an error occured, success otherwise. | 79 // |result|: the type of the error if an error occured, success otherwise. |
134 virtual void OnSendFinished(const std::string& app_id, | 80 virtual void OnSendFinished(const std::string& app_id, |
135 const std::string& message_id, | 81 const std::string& message_id, |
136 Result result) = 0; | 82 Result result) = 0; |
137 | 83 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // Clear all recorded GCM activity logs. | 167 // Clear all recorded GCM activity logs. |
222 virtual void ClearActivityLogs() = 0; | 168 virtual void ClearActivityLogs() = 0; |
223 | 169 |
224 // Gets internal states and statistics. | 170 // Gets internal states and statistics. |
225 virtual GCMStatistics GetStatistics() const = 0; | 171 virtual GCMStatistics GetStatistics() const = 0; |
226 }; | 172 }; |
227 | 173 |
228 } // namespace gcm | 174 } // namespace gcm |
229 | 175 |
230 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_H_ | 176 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_H_ |
OLD | NEW |