OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_CONTENT_SUGGESTIONS_GCM_APP_HANDLE
R_H_ | 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_ | 6 #define COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_CONTENT_SUGGESTIONS_GCM_APP_HANDLE
R_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "components/gcm_driver/gcm_app_handler.h" | 9 #include "components/gcm_driver/gcm_app_handler.h" |
10 #include "components/gcm_driver/instance_id/instance_id.h" | 10 #include "components/gcm_driver/instance_id/instance_id.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 class InstanceIDDriver; | 22 class InstanceIDDriver; |
23 } | 23 } |
24 | 24 |
25 namespace ntp_snippets { | 25 namespace ntp_snippets { |
26 | 26 |
27 // Handler for pushed GCM content suggestions. It retrieves a subscription token | 27 // Handler for pushed GCM content suggestions. It retrieves a subscription token |
28 // from the GCM server and registers/unregisters itself with the GCM service to | 28 // from the GCM server and registers/unregisters itself with the GCM service to |
29 // be called upon received push content suggestions. | 29 // be called upon received push content suggestions. |
30 class ContentSuggestionsGCMAppHandler : public gcm::GCMAppHandler { | 30 class ContentSuggestionsGCMAppHandler : public gcm::GCMAppHandler { |
31 public: | 31 public: |
| 32 // TODO(mamir): Check if a better paramater datatype makes more sense. |
| 33 using OnNewContentCallback = base::Callback<void(const std::string& content)>; |
| 34 |
32 ContentSuggestionsGCMAppHandler( | 35 ContentSuggestionsGCMAppHandler( |
33 gcm::GCMDriver* gcm_driver, | 36 gcm::GCMDriver* gcm_driver, |
34 instance_id::InstanceIDDriver* instance_id_driver, | 37 instance_id::InstanceIDDriver* instance_id_driver, |
35 PrefService* pref_service_, | 38 PrefService* pref_service_, |
36 std::unique_ptr<SubscriptionManager> subscription_manager); | 39 std::unique_ptr<SubscriptionManager> subscription_manager); |
37 | 40 |
38 // If still listening, calls StopListening() | 41 // If still listening, calls StopListening() |
39 ~ContentSuggestionsGCMAppHandler() override; | 42 ~ContentSuggestionsGCMAppHandler() override; |
40 | 43 |
41 // Subscribe to the GCM service if necessary and start listening for pushed | 44 // Subscribe to the GCM service if necessary and start listening for pushed |
42 // content suggestions. Must not be called if already listening. | 45 // content suggestions. Must not be called if already listening. |
43 void StartListening(); | 46 void StartListening(OnNewContentCallback on_new_content_callback); |
44 | 47 |
45 // Remove the handler, and stop listening for incoming GCM messages. Any | 48 // Remove the handler, and stop listening for incoming GCM messages. Any |
46 // further pushed content suggestions will be ignored. Must be called while | 49 // further pushed content suggestions will be ignored. Must be called while |
47 // listening. | 50 // listening. |
48 void StopListening(); | 51 void StopListening(); |
49 | 52 |
50 // GCMAppHandler overrides. | 53 // GCMAppHandler overrides. |
51 void ShutdownHandler() override; | 54 void ShutdownHandler() override; |
52 void OnStoreReset() override; | 55 void OnStoreReset() override; |
53 void OnMessage(const std::string& app_id, | 56 void OnMessage(const std::string& app_id, |
(...skipping 15 matching lines...) Expand all Loading... |
69 // Called after the subscription is obtained from the GCM server. | 72 // Called after the subscription is obtained from the GCM server. |
70 void DidSubscribe(const std::string& subscription_id, | 73 void DidSubscribe(const std::string& subscription_id, |
71 instance_id::InstanceID::Result result); | 74 instance_id::InstanceID::Result result); |
72 | 75 |
73 gcm::GCMDriver* const gcm_driver_; | 76 gcm::GCMDriver* const gcm_driver_; |
74 instance_id::InstanceIDDriver* const instance_id_driver_; | 77 instance_id::InstanceIDDriver* const instance_id_driver_; |
75 PrefService* const pref_service_; | 78 PrefService* const pref_service_; |
76 const std::unique_ptr<SubscriptionManager> subscription_manager_; | 79 const std::unique_ptr<SubscriptionManager> subscription_manager_; |
77 base::WeakPtrFactory<ContentSuggestionsGCMAppHandler> weak_factory_; | 80 base::WeakPtrFactory<ContentSuggestionsGCMAppHandler> weak_factory_; |
78 | 81 |
| 82 // Called after everytime a new message is received in OnMessage() to notify |
| 83 // the content provider. |
| 84 OnNewContentCallback on_new_content_callback_; |
| 85 |
79 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsGCMAppHandler); | 86 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsGCMAppHandler); |
80 }; | 87 }; |
81 } // namespace ntp_snippets | 88 } // namespace ntp_snippets |
82 | 89 |
83 #endif // COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_CONTENT_SUGGESTIONS_GCM_APP_HAN
DLER_H_ | 90 #endif // COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_CONTENT_SUGGESTIONS_GCM_APP_HAN
DLER_H_ |
OLD | NEW |