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

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

Issue 712833002: Undoing revert, cl is not the cause of gcm crash on canary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2214
Patch Set: 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.h"
12 #include "base/memory/weak_ptr.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 base::SupportsWeakPtr<GCMHandler> {
27 public:
28 // Callback to report that registration has completed.
29 // Returns an empty ID if registration failed.
30 using RegistrationCallback = base::Callback<void(const std::string&)>;
31
32 static const char kCopresenceAppId[];
33 static const char kCopresenceSenderId[];
34 static const char kGcmMessageKey[];
35
36 // |gcm_driver| is required, but may disappear if we get a ShutdownHandler()
37 // call first. |directive_handler| must outlive us. The caller owns both.
38 GCMHandler(gcm::GCMDriver* gcm_driver,
39 DirectiveHandler* directive_handler);
40 ~GCMHandler() override;
41
42 // Request the GCM ID. It may be returned now or later, via the callback.
43 void GetGcmId(const RegistrationCallback& callback);
44
45 // GCMAppHandler overrides
46 void ShutdownHandler() override;
47 void OnMessage(const std::string& app_id,
48 const gcm::GCMClient::IncomingMessage& message) override;
49 void OnMessagesDeleted(const std::string& app_id) override;
50 void OnSendError(
51 const std::string& /* app_id */,
52 const gcm::GCMClient::SendErrorDetails& /* send_error_details */)
53 override;
54 void OnSendAcknowledged(const std::string& /* app_id */,
55 const std::string& /* message_id */) override;
56 bool CanHandle(const std::string& app_id) const override;
57
58 private:
59 // GCM Registration has finished. Notify clients as appropriate.
60 void RegistrationComplete(const std::string& registration_id,
61 gcm::GCMClient::Result result);
62
63 gcm::GCMDriver* driver_;
64 DirectiveHandler* const directive_handler_;
65
66 // TODO(ckehoe): Change this to a CancelableCallback.
67 base::Callback<void(const std::string&,
68 gcm::GCMClient::Result)> registration_callback_;
69
70 std::string gcm_id_;
71 std::vector<RegistrationCallback> pending_id_requests_;
72
73 DISALLOW_COPY_AND_ASSIGN(GCMHandler);
74 };
75
76 } // namespace copresence
77
78 #endif // COMPONENTS_COPRESENCE_HANDLERS_GCM_HANDLER_H_
OLDNEW
« no previous file with comments | « components/copresence/copresence_manager_impl.cc ('k') | components/copresence/handlers/gcm_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698