Vitaly Buka | 4615e0d | 2015-10-14 15:35:12 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 5 | #ifndef LIBWEAVE_SRC_NOTIFICATION_PULL_CHANNEL_H_ |
| 6 | #define LIBWEAVE_SRC_NOTIFICATION_PULL_CHANNEL_H_ |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include <base/macros.h> |
| 12 | #include <base/memory/weak_ptr.h> |
Vitaly Buka | 0d50107 | 2015-08-18 18:09:46 -0700 | [diff] [blame] | 13 | #include <base/time/time.h> |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 14 | |
Stefan Sauer | 2d16dfa | 2015-09-25 17:08:35 +0200 | [diff] [blame] | 15 | #include "src/notification/notification_channel.h" |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 16 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 17 | namespace weave { |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 18 | |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 19 | namespace provider { |
Vitaly Buka | 823fdda | 2015-08-13 00:33:00 -0700 | [diff] [blame] | 20 | class TaskRunner; |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 21 | } // namespace |
Vitaly Buka | 823fdda | 2015-08-13 00:33:00 -0700 | [diff] [blame] | 22 | |
Alex Vakulenko | e07c29d | 2015-10-22 10:31:12 -0700 | [diff] [blame] | 23 | extern const char kPullChannelName[]; |
| 24 | |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 25 | class PullChannel : public NotificationChannel { |
| 26 | public: |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 27 | PullChannel(base::TimeDelta pull_interval, provider::TaskRunner* task_runner); |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 28 | ~PullChannel() override = default; |
| 29 | |
| 30 | // Overrides from NotificationChannel. |
| 31 | std::string GetName() const override; |
Alex Vakulenko | 6b028ae | 2015-05-29 09:38:59 -0700 | [diff] [blame] | 32 | bool IsConnected() const override; |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 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(); |
Vitaly Buka | bf415b2 | 2015-08-12 21:30:30 -0700 | [diff] [blame] | 41 | void RePost(); |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 42 | |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 43 | base::TimeDelta pull_interval_; |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 44 | provider::TaskRunner* task_runner_{nullptr}; |
Vitaly Buka | bf415b2 | 2015-08-12 21:30:30 -0700 | [diff] [blame] | 45 | NotificationDelegate* delegate_{nullptr}; |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 46 | |
| 47 | base::WeakPtrFactory<PullChannel> weak_ptr_factory_{this}; |
| 48 | DISALLOW_COPY_AND_ASSIGN(PullChannel); |
| 49 | }; |
| 50 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 51 | } // namespace weave |
Alex Vakulenko | d05725f | 2015-05-27 15:48:19 -0700 | [diff] [blame] | 52 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 53 | #endif // LIBWEAVE_SRC_NOTIFICATION_PULL_CHANNEL_H_ |