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

Side by Side Diff: components/copresence/handlers/gcm_handler.h

Issue 710513004: Adding GCM support to the copresence component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 6 years, 1 month 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
(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_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback_forward.h"
12 #include "base/cancelable_callback.h"
13 #include "components/gcm_driver/gcm_app_handler.h"
14 #include "components/gcm_driver/gcm_client.h"
15
16 namespace gcm {
17 class GCMDriver;
18 }
19
20 namespace copresence {
21
22 class DirectiveHandler;
23
24 // This class handles GCM messages from the Copresence server.
25 class GCMHandler final : public gcm::GCMAppHandler {
26 public:
27 // Callback to report that registration has completed.
28 // Returns an empty ID if registration failed.
29 using RegistrationCallback = base::Callback<void(const std::string&)>;
30
31 static const char kCopresenceAppId[];
32 static const char kCopresenceSenderId[];
33 static const char kGcmMessageKey[];
34
35 // |gcm_driver| is required, but may disappear if we get a ShutdownHandler()
36 // call first. |directive_handler| must outlive us. The caller owns both.
37 GCMHandler(gcm::GCMDriver* gcm_driver,
38 DirectiveHandler* directive_handler);
39 ~GCMHandler() override;
40
41 // Request the GCM ID. It may be returned now or later, via the callback.
42 void GetGcmId(const RegistrationCallback& callback);
43
44 // GCMAppHandler implementation
45
rkc 2014/11/07 20:24:15 Remove all the newlines between these functions. M
Charlie 2014/11/07 20:50:12 Done.
46 void ShutdownHandler() override;
47
48 void OnMessage(const std::string& app_id,
49 const gcm::GCMClient::IncomingMessage& message) override;
50 void OnMessagesDeleted(const std::string& app_id) override;
51
52 void OnSendError(
53 const std::string& app_id,
54 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
55 void OnSendAcknowledged(const std::string& app_id,
56 const std::string& message_id) override;
57
58 bool CanHandle(const std::string& app_id) const override;
59
60 private:
61 // GCM Registration has finished. Notify clients as appropriate.
62 void RegistrationComplete(const std::string& registration_id,
63 gcm::GCMClient::Result result);
64
65 gcm::GCMDriver* driver_;
66 DirectiveHandler* const directive_handler_;
67
68 // If we are destructed before GCM registration completes,
69 // we cancel this callback.
70 base::CancelableCallback<void(const std::string&,
71 gcm::GCMClient::Result)> registration_callback_;
72
73 std::string gcm_id_;
74 std::vector<RegistrationCallback> pending_id_requests_;
75
76 DISALLOW_COPY_AND_ASSIGN(GCMHandler);
77 };
78
79 } // namespace copresence
80
81 #endif // COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698