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