Chromium Code Reviews| 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_BREAKING_NEWS_CONTENT_SUGGESTIONS_GCM_APP_HANDLE R_H_ | |
| 6 #define COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_CONTENT_SUGGESTIONS_GCM_APP_HANDLE R_H_ | |
| 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/subscription_manager.h" | |
| 12 #include "components/prefs/pref_registry_simple.h" | |
| 13 #include "components/prefs/pref_service.h" | |
| 14 | |
| 15 class PrefRegistrySimple; | |
| 16 | |
| 17 namespace gcm { | |
| 18 class GCMDriver; | |
| 19 } | |
| 20 | |
| 21 namespace instance_id { | |
| 22 class InstanceIDDriver; | |
| 23 } | |
| 24 | |
| 25 namespace ntp_snippets { | |
| 26 | |
| 27 // Class responsible for GCM functionality. It retrieves a subscription token | |
|
sfiera
2017/06/07 11:34:38
"Class responsible for GCM functionality" seems a
mamir
2017/06/07 14:29:17
Done.
| |
| 28 // from the GCM server, registers/unregisters itself with the GCM service to be | |
| 29 // called upon received push content suggestions. | |
|
sfiera
2017/06/07 11:34:38
This sentence isn't complete; should the comma be
mamir
2017/06/07 14:29:17
Yes
| |
| 30 class ContentSuggestionsGCMAppHandler : public gcm::GCMAppHandler { | |
| 31 public: | |
| 32 ContentSuggestionsGCMAppHandler( | |
| 33 gcm::GCMDriver* gcm_driver, | |
| 34 instance_id::InstanceIDDriver* instance_id_driver, | |
| 35 PrefService* pref_service_, | |
| 36 std::unique_ptr<SubscriptionManager> subscription_manager); | |
| 37 | |
| 38 // If still listening, calls StopListening() | |
| 39 ~ContentSuggestionsGCMAppHandler() override; | |
| 40 | |
| 41 // Subscribe to the GCM service if necessary and start listening for pushed | |
| 42 // content suggestions. Must not be called if already listening. | |
| 43 void StartListening(); | |
| 44 | |
| 45 // Remove the handler, and stop listening for incoming GCM messages. Any | |
| 46 // further pushed content suggestions will be ignored. Must be called while | |
| 47 // listening. | |
| 48 void StopListening(); | |
| 49 | |
| 50 // GCMAppHandler overrides. | |
| 51 void ShutdownHandler() override; | |
| 52 void OnStoreReset() override; | |
| 53 void OnMessage(const std::string& app_id, | |
| 54 const gcm::IncomingMessage& message) override; | |
| 55 void OnMessagesDeleted(const std::string& app_id) override; | |
| 56 void OnSendError(const std::string& app_id, | |
| 57 const gcm::GCMClient::SendErrorDetails& details) override; | |
| 58 void OnSendAcknowledged(const std::string& app_id, | |
| 59 const std::string& message_id) override; | |
| 60 | |
| 61 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | |
| 62 | |
| 63 private: | |
| 64 // Retrieves a subscription token that allows the content suggestions server | |
| 65 // to push content via GCM messages. Calling this method multiple times is not | |
| 66 // necessary but does not harm since the same token is returned everytime. | |
| 67 void Subscribe(); | |
| 68 | |
| 69 // Called after the subscription is obtained from the GCM server. | |
| 70 void DidSubscribe(const std::string& subscription_id, | |
| 71 instance_id::InstanceID::Result result); | |
| 72 | |
| 73 gcm::GCMDriver* const gcm_driver_; | |
| 74 instance_id::InstanceIDDriver* const instance_id_driver_; | |
| 75 PrefService* const pref_service_; | |
| 76 const std::unique_ptr<SubscriptionManager> subscription_manager_; | |
| 77 base::WeakPtrFactory<ContentSuggestionsGCMAppHandler> weak_factory_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsGCMAppHandler); | |
| 80 }; | |
| 81 } // namespace ntp_snippets | |
| 82 | |
| 83 #endif // COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_CONTENT_SUGGESTIONS_GCM_APP_HAN DLER_H_ | |
| OLD | NEW |