Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: google_apis/gcm/gcm_client.h

Issue 98173009: GCM Checkin implementation with unit tests and protobufs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcm-store
Patch Set: Updating the copyright notice Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // Message being received from the other party. 58 // Message being received from the other party.
59 struct GCM_EXPORT IncomingMessage { 59 struct GCM_EXPORT IncomingMessage {
60 IncomingMessage(); 60 IncomingMessage();
61 ~IncomingMessage(); 61 ~IncomingMessage();
62 62
63 MessageData data; 63 MessageData data;
64 }; 64 };
65 65
66 // The check-in info for the user. Returned by the server. 66 // The check-in info for the user. Returned by the server.
67 struct GCM_EXPORT CheckInInfo { 67 struct GCM_EXPORT CheckinInfo {
68 CheckInInfo() : android_id(0), secret(0) {} 68 CheckinInfo() : android_id(0), secret(0) {}
69 bool IsValid() const { return android_id != 0 && secret != 0; } 69 bool IsValid() const { return android_id != 0 && secret != 0; }
70 void Reset() { 70 void Reset() {
71 android_id = 0; 71 android_id = 0;
72 secret = 0; 72 secret = 0;
73 } 73 }
74 74
75 uint64 android_id; 75 uint64 android_id;
76 uint64 secret; 76 uint64 secret;
77 }; 77 };
78 78
79 // A delegate interface that allows the GCMClient instance to interact with 79 // A delegate interface that allows the GCMClient instance to interact with
80 // its caller, i.e. notifying asynchronous event. 80 // its caller, i.e. notifying asynchronous event.
81 class Delegate { 81 class Delegate {
82 public: 82 public:
83 // Called when the user has been checked in successfully or an error occurs. 83 // Called when the user has been checked in successfully or an error occurs.
84 // |checkin_info|: valid if the checkin completed successfully. 84 // |checkin_info|: valid if the CheckIn(..) completed successfully.
85 // |result|: the type of the error if an error occured, success otherwise. 85 // |result|: the type of the error if an error occured, success otherwise.
86 virtual void OnCheckInFinished(const CheckInInfo& checkin_info, 86 virtual void OnCheckInFinished(const CheckinInfo& checkin_info,
87 Result result) = 0; 87 Result result) = 0;
88 88
89 // Called when the registration completed successfully or an error occurs. 89 // Called when the registration completed successfully or an error occurs.
90 // |app_id|: application ID. 90 // |app_id|: application ID.
91 // |registration_id|: non-empty if the registration completed successfully. 91 // |registration_id|: non-empty if the registration completed successfully.
92 // |result|: the type of the error if an error occured, success otherwise. 92 // |result|: the type of the error if an error occured, success otherwise.
93 virtual void OnRegisterFinished(const std::string& app_id, 93 virtual void OnRegisterFinished(const std::string& app_id,
94 const std::string& registration_id, 94 const std::string& registration_id,
95 Result result) = 0; 95 Result result) = 0;
96 96
(...skipping 20 matching lines...) Expand all
117 // |app_id|: application ID. 117 // |app_id|: application ID.
118 // |message_id|: ID of the message being sent. 118 // |message_id|: ID of the message being sent.
119 // |result|: the type of the error if an error occured, success otherwise. 119 // |result|: the type of the error if an error occured, success otherwise.
120 virtual void OnMessageSendError(const std::string& app_id, 120 virtual void OnMessageSendError(const std::string& app_id,
121 const std::string& message_id, 121 const std::string& message_id,
122 Result result) = 0; 122 Result result) = 0;
123 123
124 // Returns the checkin info associated with this user. The delegate class 124 // Returns the checkin info associated with this user. The delegate class
125 // is expected to persist the checkin info that is provided by 125 // is expected to persist the checkin info that is provided by
126 // OnCheckInFinished. 126 // OnCheckInFinished.
127 virtual CheckInInfo GetCheckInInfo() const = 0; 127 virtual CheckinInfo GetCheckinInfo() const = 0;
128 128
129 // Called when the loading from the persistent store is done. The loading 129 // Called when the loading from the persistent store is done. The loading
130 // is triggered asynchronously when GCMClient is created. 130 // is triggered asynchronously when GCMClient is created.
131 virtual void OnLoadingCompleted() = 0; 131 virtual void OnLoadingCompleted() = 0;
132 132
133 // Returns a task runner for file operations that may block. This is used 133 // Returns a task runner for file operations that may block. This is used
134 // in writing to or reading from the persistent store. 134 // in writing to or reading from the persistent store.
135 virtual base::TaskRunner* GetFileTaskRunner() = 0; 135 virtual base::TaskRunner* GetFileTaskRunner() = 0;
136 }; 136 };
137 137
(...skipping 12 matching lines...) Expand all
150 virtual void SetUserDelegate(const std::string& username, 150 virtual void SetUserDelegate(const std::string& username,
151 Delegate* delegate) = 0; 151 Delegate* delegate) = 0;
152 152
153 // Checks in the user to use GCM. If the device has not been checked in, it 153 // Checks in the user to use GCM. If the device has not been checked in, it
154 // will be done first. 154 // will be done first.
155 // |username|: the username (email address) used to check in with the server. 155 // |username|: the username (email address) used to check in with the server.
156 virtual void CheckIn(const std::string& username) = 0; 156 virtual void CheckIn(const std::string& username) = 0;
157 157
158 // Registers the application for GCM. Delegate::OnRegisterFinished will be 158 // Registers the application for GCM. Delegate::OnRegisterFinished will be
159 // called asynchronously upon completion. 159 // called asynchronously upon completion.
160 // |username|: the username (email address) passed in CheckIn. 160 // |username|: the username (email address) passed in CheckIn(..).
161 // |app_id|: application ID. 161 // |app_id|: application ID.
162 // |cert|: SHA-1 of public key of the application, in base16 format. 162 // |cert|: SHA-1 of public key of the application, in base16 format.
163 // |sender_ids|: list of IDs of the servers that are allowed to send the 163 // |sender_ids|: list of IDs of the servers that are allowed to send the
164 // messages to the application. These IDs are assigned by the 164 // messages to the application. These IDs are assigned by the
165 // Google API Console. 165 // Google API Console.
166 virtual void Register(const std::string& username, 166 virtual void Register(const std::string& username,
167 const std::string& app_id, 167 const std::string& app_id,
168 const std::string& cert, 168 const std::string& cert,
169 const std::vector<std::string>& sender_ids) = 0; 169 const std::vector<std::string>& sender_ids) = 0;
170 170
171 // Unregisters the application from GCM when it is uninstalled. 171 // Unregisters the application from GCM when it is uninstalled.
172 // Delegate::OnUnregisterFinished will be called asynchronously upon 172 // Delegate::OnUnregisterFinished will be called asynchronously upon
173 // completion. 173 // completion.
174 // |username|: the username (email address) passed in CheckIn. 174 // |username|: the username (email address) passed in CheckIn(..).
175 // |app_id|: application ID. 175 // |app_id|: application ID.
176 virtual void Unregister(const std::string& username, 176 virtual void Unregister(const std::string& username,
177 const std::string& app_id) = 0; 177 const std::string& app_id) = 0;
178 178
179 // Sends a message to a given receiver. Delegate::OnSendFinished will be 179 // Sends a message to a given receiver. Delegate::OnSendFinished will be
180 // called asynchronously upon completion. 180 // called asynchronously upon completion.
181 // |username|: the username (email address) passed in CheckIn. 181 // |username|: the username (email address) passed in CheckIn(..).
182 // |app_id|: application ID. 182 // |app_id|: application ID.
183 // |receiver_id|: registration ID of the receiver party. 183 // |receiver_id|: registration ID of the receiver party.
184 // |message|: message to be sent. 184 // |message|: message to be sent.
185 virtual void Send(const std::string& username, 185 virtual void Send(const std::string& username,
186 const std::string& app_id, 186 const std::string& app_id,
187 const std::string& receiver_id, 187 const std::string& receiver_id,
188 const OutgoingMessage& message) = 0; 188 const OutgoingMessage& message) = 0;
189 189
190 // Returns true if the loading from the persistent store is still in progress. 190 // Returns true if the loading from the persistent store is still in progress.
191 virtual bool IsLoading() const = 0; 191 virtual bool IsLoading() const = 0;
192 192
193 protected: 193 protected:
194 virtual ~GCMClient() {} 194 virtual ~GCMClient() {}
195 }; 195 };
196 196
197 } // namespace gcm 197 } // namespace gcm
198 198
199 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_H_ 199 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698