summaryrefslogtreecommitdiff
path: root/chromium/components/feed/core/v2/web_feed_subscriptions/fetch_subscribed_web_feeds_task.h
blob: 280fd9e082e2daa741ef80dbd2ad287f222cce00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_FEED_CORE_V2_WEB_FEED_SUBSCRIPTIONS_FETCH_SUBSCRIBED_WEB_FEEDS_TASK_H_
#define COMPONENTS_FEED_CORE_V2_WEB_FEED_SUBSCRIPTIONS_FETCH_SUBSCRIBED_WEB_FEEDS_TASK_H_

#include "components/feed/core/proto/v2/store.pb.h"
#include "components/feed/core/proto/v2/wire/web_feeds.pb.h"
#include "components/feed/core/v2/enums.h"
#include "components/feed/core/v2/feed_network.h"
#include "components/feed/core/v2/operation_token.h"
#include "components/feed/core/v2/public/types.h"
#include "components/offline_pages/task/task.h"

namespace feed {
class FeedStream;

// Fetches and returns the subscribed web feeds.
class FetchSubscribedWebFeedsTask : public offline_pages::Task {
 public:
  struct Result {
    Result();
    ~Result();
    Result(const Result&);
    Result(Result&&);
    Result& operator=(const Result&);
    Result& operator=(Result&&);
    WebFeedRefreshStatus status = WebFeedRefreshStatus::kNoStatus;
    std::vector<feedstore::WebFeedInfo> subscribed_web_feeds;
  };

  FetchSubscribedWebFeedsTask(FeedStream* stream,
                              const OperationToken& operation_token,
                              base::OnceCallback<void(Result)> callback);
  ~FetchSubscribedWebFeedsTask() override;
  FetchSubscribedWebFeedsTask(const FetchSubscribedWebFeedsTask&) = delete;
  FetchSubscribedWebFeedsTask& operator=(const FetchSubscribedWebFeedsTask&) =
      delete;

 private:
  void Run() override;
  void RequestComplete(
      FeedNetwork::ApiResult<feedwire::webfeed::ListWebFeedsResponse> response);
  void Done(WebFeedRefreshStatus status);

  FeedStream& stream_;
  OperationToken operation_token_;
  Result result_;
  base::OnceCallback<void(Result)> callback_;
};

}  // namespace feed

#endif  // COMPONENTS_FEED_CORE_V2_WEB_FEED_SUBSCRIPTIONS_FETCH_SUBSCRIBED_WEB_FEEDS_TASK_H_