OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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_NTP_SNIPPETS_REMOTE_CONTENT_SUGGESTIONS_GCM_APP_HANDLER_H_ | |
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_CONTENT_SUGGESTIONS_GCM_APP_HANDLER_H_ | |
Peter Beverloo
2017/06/02 14:02:03
micro nit: update
mamir
2017/06/04 15:10:14
Done.
| |
7 | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "components/gcm_driver/gcm_app_handler.h" | |
10 #include "components/gcm_driver/instance_id/instance_id.h" | |
11 #include "components/ntp_snippets/breaking_news/breaking_news_subscription_manag er.h" | |
12 | |
13 namespace gcm { | |
14 class GCMDriver; | |
15 } | |
16 | |
17 namespace instance_id { | |
18 class InstanceIDDriver; | |
19 } | |
20 | |
21 namespace ntp_snippets { | |
22 // Class responsible for GCM functionality. It retrieves a subscription token | |
sfiera
2017/06/02 13:41:24
Here and below, I think it's normal style to put a
mamir
2017/06/04 15:10:14
Done.
| |
23 // from the GCM server, registers/deregisters itself with the GCM service to be | |
Peter Beverloo
2017/06/02 14:02:02
micro nit: deregisters -> unregisters (or "subscri
mamir
2017/06/04 15:10:14
I will stay consistent with the rest of Chrome.
| |
24 // called upon received push content suggestions. | |
25 class ContentSuggestionsGCMAppHandler : public gcm::GCMAppHandler { | |
26 public: | |
27 ContentSuggestionsGCMAppHandler( | |
28 gcm::GCMDriver* gcm_driver, | |
29 instance_id::InstanceIDDriver* instance_id_driver, | |
30 std::unique_ptr<BreakingNewsSubscriptionManager> subscriptionManager); | |
Peter Beverloo
2017/06/02 14:02:03
nit: subscription_manager
mamir
2017/06/04 15:10:14
Done.
| |
31 ~ContentSuggestionsGCMAppHandler(); | |
sfiera
2017/06/02 13:41:24
Comment: if still listening, calls StopListening()
Peter Beverloo
2017/06/02 14:02:02
nit: this should be marked as `override` since the
mamir
2017/06/04 15:10:14
Done.
mamir
2017/06/04 15:10:14
Done.
| |
32 // Subscribe to the GCM service if necessary and start listening for pushed | |
33 // content suggestions. Must not be called if already listening. | |
34 void StartListening(); | |
35 // Remove the handler, and stop listening for incoming GCM messages. Any | |
36 // further pushed content suggestions will be ignored. Must be called while | |
37 // listening. | |
38 void StopListening(); | |
39 | |
40 private: | |
41 gcm::GCMDriver* const gcm_driver_; | |
Peter Beverloo
2017/06/02 14:02:02
style nit: methods before member variables.
mamir
2017/06/04 15:10:14
Done.
| |
42 instance_id::InstanceIDDriver* const instance_id_driver_; | |
Peter Beverloo
2017/06/02 14:02:03
In order to guarantee the lifetime of these two po
mamir
2017/06/04 15:10:14
I added it to the constructor. This is enough.
mamir
2017/06/04 16:19:01
Actually, GCMProfileServiceFactory (and InstanceID
| |
43 const std::unique_ptr<BreakingNewsSubscriptionManager> subscription_manager_; | |
44 base::WeakPtrFactory<ContentSuggestionsGCMAppHandler> weak_factory_; | |
45 // Retrieves a subscription token that allows the content suggestions server | |
46 // to push content via GCM messages. Calling this method multiple times is not | |
47 // necessary but does not harm since the same token is returned everytime. | |
48 void Subscribe(); | |
49 // Called after the subscription is obtained from the GCM server. | |
50 void DidSubscribe(const std::string& subscription_id, | |
51 instance_id::InstanceID::Result result); | |
52 | |
53 // GCMAppHandler overrides. | |
54 void ShutdownHandler() override; | |
55 void OnStoreReset() override; | |
56 void OnMessage(const std::string& app_id, | |
57 const gcm::IncomingMessage& message) override; | |
58 void OnMessagesDeleted(const std::string& app_id) override; | |
59 void OnSendError(const std::string& app_id, | |
60 const gcm::GCMClient::SendErrorDetails& details) override; | |
61 void OnSendAcknowledged(const std::string& app_id, | |
62 const std::string& message_id) override; | |
Peter Beverloo
2017/06/02 14:02:02
It doesn't per se hurt, but given that the parent
mamir
2017/06/04 15:10:14
Done.
| |
63 }; | |
Peter Beverloo
2017/06/02 14:02:02
DISALLOW_COPY_AND_ASSIGN
mamir
2017/06/04 15:10:14
Done.
| |
64 } // namespace ntp_snippets | |
65 | |
66 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_CONTENT_SUGGESTIONS_GCM_APP_HANDLER_H_ | |
OLD | NEW |