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_COPRESENCE_HANDLERS_GCM_HANDLER_IMPL_H_ | 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_IMPL_H_ |
6 #define COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_IMPL_H_ | 6 #define COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
13 #include "components/copresence/handlers/gcm_handler.h" | 13 #include "components/copresence/handlers/gcm_handler.h" |
| 14 #include "components/copresence/public/copresence_constants.h" |
14 #include "components/gcm_driver/gcm_app_handler.h" | 15 #include "components/gcm_driver/gcm_app_handler.h" |
15 #include "components/gcm_driver/gcm_client.h" | 16 #include "components/gcm_driver/gcm_client.h" |
16 | 17 |
17 namespace gcm { | 18 namespace gcm { |
18 class GCMDriver; | 19 class GCMDriver; |
19 } | 20 } |
20 | 21 |
21 namespace copresence { | 22 namespace copresence { |
22 | 23 |
23 class DirectiveHandler; | 24 class DirectiveHandler; |
24 | 25 |
25 // This class handles GCM messages from the Copresence server. | 26 // This class handles GCM messages from the Copresence server. |
26 class GCMHandlerImpl final : public GCMHandler, | 27 class GCMHandlerImpl final : public GCMHandler, |
27 public gcm::GCMAppHandler { | 28 public gcm::GCMAppHandler { |
28 public: | 29 public: |
29 // Callback to report that registration has completed. | 30 // Callback to report that registration has completed. |
30 // Returns an empty ID if registration failed. | 31 // Returns an empty ID if registration failed. |
31 using RegistrationCallback = base::Callback<void(const std::string&)>; | 32 using RegistrationCallback = base::Callback<void(const std::string&)>; |
32 | 33 |
33 static const char kCopresenceAppId[]; | 34 static const char kCopresenceAppId[]; |
34 static const char kCopresenceSenderId[]; | 35 static const char kCopresenceSenderId[]; |
35 static const char kGcmMessageKey[]; | 36 static const char kGcmMessageKey[]; |
36 | 37 |
37 // |gcm_driver| is required, but may disappear if we get a ShutdownHandler() | 38 // |gcm_driver| is required, but may disappear if we get a ShutdownHandler() |
38 // call first. |directive_handler| must outlive us. The caller owns both. | 39 // call first. |directive_handler| must outlive us. The caller owns both. |
39 GCMHandlerImpl(gcm::GCMDriver* gcm_driver, | 40 GCMHandlerImpl(gcm::GCMDriver* gcm_driver, |
40 DirectiveHandler* directive_handler); | 41 DirectiveHandler* directive_handler, |
| 42 const MessagesCallback& new_messages_callback); |
41 ~GCMHandlerImpl() override; | 43 ~GCMHandlerImpl() override; |
42 | 44 |
43 // GCMHandler override. | 45 // GCMHandler override. |
44 void GetGcmId(const RegistrationCallback& callback) override; | 46 void GetGcmId(const RegistrationCallback& callback) override; |
45 | 47 |
46 private: | 48 private: |
47 friend class GCMHandlerTest; | 49 friend class GCMHandlerTest; |
48 | 50 |
49 // GCMAppHandler overrides | 51 // GCMAppHandler overrides |
50 void ShutdownHandler() override; | 52 void ShutdownHandler() override; |
51 void OnMessage(const std::string& app_id, | 53 void OnMessage(const std::string& app_id, |
52 const gcm::GCMClient::IncomingMessage& message) override; | 54 const gcm::GCMClient::IncomingMessage& message) override; |
53 void OnMessagesDeleted(const std::string& app_id) override; | 55 void OnMessagesDeleted(const std::string& app_id) override; |
54 void OnSendError( | 56 void OnSendError( |
55 const std::string& /* app_id */, | 57 const std::string& /* app_id */, |
56 const gcm::GCMClient::SendErrorDetails& /* send_error_details */) | 58 const gcm::GCMClient::SendErrorDetails& /* send_error_details */) |
57 override; | 59 override; |
58 void OnSendAcknowledged(const std::string& /* app_id */, | 60 void OnSendAcknowledged(const std::string& /* app_id */, |
59 const std::string& /* message_id */) override; | 61 const std::string& /* message_id */) override; |
60 bool CanHandle(const std::string& app_id) const override; | 62 bool CanHandle(const std::string& app_id) const override; |
61 | 63 |
62 // GCM Registration has finished. Notify clients as appropriate. | 64 // GCM Registration has finished. Notify clients as appropriate. |
63 void RegistrationComplete(const std::string& registration_id, | 65 void RegistrationComplete(const std::string& registration_id, |
64 gcm::GCMClient::Result result); | 66 gcm::GCMClient::Result result); |
65 | 67 |
66 gcm::GCMDriver* driver_; | 68 gcm::GCMDriver* driver_; |
67 DirectiveHandler* const directive_handler_; | 69 DirectiveHandler* const directive_handler_; |
| 70 MessagesCallback new_messages_callback_; |
68 | 71 |
69 std::string gcm_id_; | 72 std::string gcm_id_; |
70 std::vector<RegistrationCallback> pending_id_requests_; | 73 std::vector<RegistrationCallback> pending_id_requests_; |
71 | 74 |
72 base::CancelableCallback<void(const std::string&, | 75 base::CancelableCallback<void(const std::string&, |
73 gcm::GCMClient::Result)> registration_callback_; | 76 gcm::GCMClient::Result)> registration_callback_; |
74 | 77 |
75 DISALLOW_COPY_AND_ASSIGN(GCMHandlerImpl); | 78 DISALLOW_COPY_AND_ASSIGN(GCMHandlerImpl); |
76 }; | 79 }; |
77 | 80 |
78 } // namespace copresence | 81 } // namespace copresence |
79 | 82 |
80 #endif // COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_IMPL_H_ | 83 #endif // COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_IMPL_H_ |
OLD | NEW |