blob: dbda188170970251b4abc836f573f81328822620 [file] [log] [blame]
// Copyright 2018 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 CHROME_BROWSER_ANDROID_EXPLORE_SITES_IMPORT_CATALOG_TASK_H_
#define CHROME_BROWSER_ANDROID_EXPLORE_SITES_IMPORT_CATALOG_TASK_H_
#include "chrome/browser/android/explore_sites/catalog.pb.h"
#include "chrome/browser/android/explore_sites/explore_sites_store.h"
#include "components/offline_pages/task/task.h"
using offline_pages::Task;
namespace explore_sites {
// Takes a Catalog proto and adds records to the store as the "downloading"
// version. Another task promotes "downloading" to "current".
// It has the following behavior in edge cases:
// * If the timestamp matches the "current" version, it does nothing. This
// prevents stomping on the currently viewable catalog.
// * If the timestamp matches the "downloading" version, it overwrites it,
// since that version is not yet viewable by the user.
class ImportCatalogTask : public Task {
public:
ImportCatalogTask(ExploreSitesStore* store,
int64_t catalog_timestamp,
std::unique_ptr<Catalog> catalog_proto);
~ImportCatalogTask() override;
bool complete() const { return complete_; }
bool result() const { return result_; }
private:
// Task implementation:
void Run() override;
void FinishedExecuting(bool result);
ExploreSitesStore* store_; // outlives this class.
int64_t catalog_timestamp_;
std::unique_ptr<Catalog> catalog_proto_;
bool complete_ = false;
bool result_ = false;
base::WeakPtrFactory<ImportCatalogTask> weak_ptr_factory_;
};
} // namespace explore_sites
#endif // CHROME_BROWSER_ANDROID_EXPLORE_SITES_IMPORT_CATALOG_TASK_H_