| 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 | 14 |
| 15 namespace base { | |
| 16 class TaskRunner; | |
| 17 } | |
| 18 | |
| 19 namespace gcm { | 15 namespace gcm { |
| 20 | 16 |
| 21 // Interface that encapsulates the network communications with the Google Cloud | 17 // Interface that encapsulates the network communications with the Google Cloud |
| 22 // Messaging server. This interface is not supposed to be thread-safe. | 18 // Messaging server. This interface is not supposed to be thread-safe. |
| 23 class GCM_EXPORT GCMClient { | 19 class GCM_EXPORT GCMClient { |
| 24 public: | 20 public: |
| 25 enum Result { | 21 enum Result { |
| 26 // Successful operation. | 22 // Successful operation. |
| 27 SUCCESS, | 23 SUCCESS, |
| 28 // Invalid parameter. | 24 // Invalid parameter. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 Result result) = 0; | 118 Result result) = 0; |
| 123 | 119 |
| 124 // Returns the checkin info associated with this user. The delegate class | 120 // Returns the checkin info associated with this user. The delegate class |
| 125 // is expected to persist the checkin info that is provided by | 121 // is expected to persist the checkin info that is provided by |
| 126 // OnCheckInFinished. | 122 // OnCheckInFinished. |
| 127 virtual CheckinInfo GetCheckinInfo() const = 0; | 123 virtual CheckinInfo GetCheckinInfo() const = 0; |
| 128 | 124 |
| 129 // Called when the loading from the persistent store is done. The loading | 125 // Called when the loading from the persistent store is done. The loading |
| 130 // is triggered asynchronously when GCMClient is created. | 126 // is triggered asynchronously when GCMClient is created. |
| 131 virtual void OnLoadingCompleted() = 0; | 127 virtual void OnLoadingCompleted() = 0; |
| 132 | |
| 133 // Returns a task runner for file operations that may block. This is used | |
| 134 // in writing to or reading from the persistent store. | |
| 135 virtual base::TaskRunner* GetFileTaskRunner() = 0; | |
| 136 }; | 128 }; |
| 137 | 129 |
| 138 // Returns the single instance. Multiple profiles share the same client | 130 GCMClient(); |
| 139 // that makes use of the same MCS connection. | 131 virtual ~GCMClient(); |
| 140 static GCMClient* Get(); | |
| 141 | |
| 142 // Passes a mocked instance for testing purpose. | |
| 143 typedef GCMClient* (*TestingFactoryFunction)(); | |
| 144 static void SetTestingFactory(TestingFactoryFunction factory); | |
| 145 | 132 |
| 146 // Sets the delegate to interact with related to a specific user. | 133 // Sets the delegate to interact with related to a specific user. |
| 147 // |username|: the username (email address) used to check in with the server. | 134 // |username|: the username (email address) used to check in with the server. |
| 148 // |delegate|: the delegate whose methods will be called asynchronously in | 135 // |delegate|: the delegate whose methods will be called asynchronously in |
| 149 // response to events and messages. | 136 // response to events and messages. |
| 150 virtual void SetUserDelegate(const std::string& username, | 137 virtual void SetUserDelegate(const std::string& username, |
| 151 Delegate* delegate) = 0; | 138 Delegate* delegate) = 0; |
| 152 | 139 |
| 153 // Checks in the user to use GCM. If the device has not been checked in, it | 140 // Checks in the user to use GCM. If the device has not been checked in, it |
| 154 // will be done first. | 141 // will be done first. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 182 // |app_id|: application ID. | 169 // |app_id|: application ID. |
| 183 // |receiver_id|: registration ID of the receiver party. | 170 // |receiver_id|: registration ID of the receiver party. |
| 184 // |message|: message to be sent. | 171 // |message|: message to be sent. |
| 185 virtual void Send(const std::string& username, | 172 virtual void Send(const std::string& username, |
| 186 const std::string& app_id, | 173 const std::string& app_id, |
| 187 const std::string& receiver_id, | 174 const std::string& receiver_id, |
| 188 const OutgoingMessage& message) = 0; | 175 const OutgoingMessage& message) = 0; |
| 189 | 176 |
| 190 // Returns true if the loading from the persistent store is still in progress. | 177 // Returns true if the loading from the persistent store is still in progress. |
| 191 virtual bool IsLoading() const = 0; | 178 virtual bool IsLoading() const = 0; |
| 192 | |
| 193 protected: | |
| 194 virtual ~GCMClient() {} | |
| 195 }; | 179 }; |
| 196 | 180 |
| 197 } // namespace gcm | 181 } // namespace gcm |
| 198 | 182 |
| 199 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_H_ | 183 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_H_ |
| OLD | NEW |