1 // Copyright 2018 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_OFFLINE_PAGES_CORE_PREFETCH_TASKS_GET_VISUALS_INFO_TASK_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_TASKS_GET_VISUALS_INFO_TASK_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/memory/weak_ptr.h"
13 #include "components/offline_pages/task/task.h"
14 #include "url/gurl.h"
15 
16 namespace offline_pages {
17 class PrefetchStore;
18 
19 // Task that attempts to get thumbnail information about an offline item in the
20 // prefetch store.
21 class GetVisualsInfoTask : public Task {
22  public:
23   // Gives URLS for the offline item's thumbnail and favicon. They are empty if
24   // the offline item was not found, or if the item had no thumbnail or favicon
25   // URLs stored.
26   struct Result {
27     GURL thumbnail_url;
28     GURL favicon_url;
29   };
30   using ResultCallback = base::OnceCallback<void(Result)>;
31 
32   GetVisualsInfoTask(PrefetchStore* store,
33                      int64_t offline_id,
34                      ResultCallback callback);
35   ~GetVisualsInfoTask() override;
36 
37  private:
38   // Task implementation.
39   void Run() override;
40   void CompleteTaskAndForwardResult(Result result);
41   PrefetchStore* prefetch_store_;
42   int64_t offline_id_;
43   ResultCallback callback_;
44 
45   base::WeakPtrFactory<GetVisualsInfoTask> weak_factory_{this};
46 
47   DISALLOW_COPY_AND_ASSIGN(GetVisualsInfoTask);
48 };
49 
50 }  // namespace offline_pages
51 
52 #endif  // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_TASKS_GET_VISUALS_INFO_TASK_H_
53