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 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_MODEL_GET_PAGES_TASK_H_ 6 #define COMPONENTS_OFFLINE_PAGES_CORE_MODEL_GET_PAGES_TASK_H_ 7 8 #include <vector> 9 10 #include "base/macros.h" 11 #include "base/memory/weak_ptr.h" 12 #include "components/offline_pages/core/client_id.h" 13 #include "components/offline_pages/core/offline_page_item.h" 14 #include "components/offline_pages/core/offline_page_metadata_store.h" 15 #include "components/offline_pages/core/offline_page_types.h" 16 #include "components/offline_pages/core/page_criteria.h" 17 #include "components/offline_pages/task/task.h" 18 19 namespace offline_pages { 20 21 // Gets offline pages that match the criteria. 22 class GetPagesTask : public Task { 23 public: 24 // Structure defining and intermediate read result. 25 struct ReadResult { 26 ReadResult(); 27 ReadResult(const ReadResult& other); 28 ~ReadResult(); 29 30 bool success = false; 31 std::vector<OfflinePageItem> pages; 32 }; 33 34 GetPagesTask(OfflinePageMetadataStore* store, 35 const PageCriteria& criteria, 36 MultipleOfflinePageItemCallback callback); 37 38 ~GetPagesTask() override; 39 40 // Reads and returns all pages matching |criteria|. This function reads 41 // from the database and should be called from within an 42 // |SqlStoreBase::Execute()| call. 43 static ReadResult ReadPagesWithCriteriaSync( 44 const PageCriteria& criteria, 45 sql::Database* db); 46 47 private: 48 // Task implementation: 49 void Run() override; 50 51 void CompleteWithResult(ReadResult result); 52 53 OfflinePageMetadataStore* store_; 54 PageCriteria criteria_; 55 MultipleOfflinePageItemCallback callback_; 56 57 base::WeakPtrFactory<GetPagesTask> weak_ptr_factory_{this}; 58 DISALLOW_COPY_AND_ASSIGN(GetPagesTask); 59 }; 60 61 } // namespace offline_pages 62 63 #endif // COMPONENTS_OFFLINE_PAGES_CORE_MODEL_GET_PAGES_TASK_H_ 64