1 // Copyright 2015 The Weave 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 LIBWEAVE_SRC_NOTIFICATION_PULL_CHANNEL_H_ 6 #define LIBWEAVE_SRC_NOTIFICATION_PULL_CHANNEL_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include <base/macros.h> 12 #include <base/memory/weak_ptr.h> 13 #include <base/time/time.h> 14 15 #include "src/notification/notification_channel.h" 16 17 namespace weave { 18 19 namespace provider { 20 class TaskRunner; 21 } // namespace 22 23 extern const char kPullChannelName[]; 24 25 class PullChannel : public NotificationChannel { 26 public: 27 PullChannel(base::TimeDelta pull_interval, provider::TaskRunner* task_runner); 28 ~PullChannel() override = default; 29 30 // Overrides from NotificationChannel. 31 std::string GetName() const override; 32 bool IsConnected() const override; 33 void AddChannelParameters(base::DictionaryValue* channel_json) override; 34 void Start(NotificationDelegate* delegate) override; 35 void Stop() override; 36 37 void UpdatePullInterval(base::TimeDelta pull_interval); 38 39 private: 40 void OnTimer(); 41 void RePost(); 42 43 base::TimeDelta pull_interval_; 44 provider::TaskRunner* task_runner_{nullptr}; 45 NotificationDelegate* delegate_{nullptr}; 46 47 base::WeakPtrFactory<PullChannel> weak_ptr_factory_{this}; 48 DISALLOW_COPY_AND_ASSIGN(PullChannel); 49 }; 50 51 } // namespace weave 52 53 #endif // LIBWEAVE_SRC_NOTIFICATION_PULL_CHANNEL_H_ 54