#ifndef COMPONENTS_BOOKMARKS_BROWSER_MODEL_LOADER_H_
#define COMPONENTS_BOOKMARKS_BROWSER_MODEL_LOADER_H_
#include <memory>
#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/synchronization/waitable_event.h"
#include "components/bookmarks/browser/bookmark_client.h"
namespace base {
class FilePath;
class SequencedTaskRunner;
}
namespace bookmarks {
class BookmarkLoadDetails;
class HistoryBookmarkModel;
class ModelLoader : public base::RefCountedThreadSafe<ModelLoader> {
public:
using LoadCallback =
base::OnceCallback<void(std::unique_ptr<BookmarkLoadDetails>)>;
static scoped_refptr<ModelLoader> Create(
const base::FilePath& local_or_syncable_file_path,
const base::FilePath& account_file_path,
LoadManagedNodeCallback load_managed_node_callback,
LoadCallback callback);
ModelLoader(const ModelLoader&) = delete;
ModelLoader& operator=(const ModelLoader&) = delete;
void BlockTillLoaded();
HistoryBookmarkModel* history_bookmark_model() {
return history_bookmark_model_.get();
}
static scoped_refptr<ModelLoader> CreateForTest(
LoadManagedNodeCallback load_managed_node_callback,
BookmarkLoadDetails* details);
private:
friend class base::RefCountedThreadSafe<ModelLoader>;
ModelLoader();
~ModelLoader();
std::unique_ptr<BookmarkLoadDetails> DoLoadOnBackgroundThread(
const base::FilePath& local_or_syncable_file_path,
const base::FilePath& account_file_path,
LoadManagedNodeCallback load_managed_node_callback);
scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
scoped_refptr<HistoryBookmarkModel> history_bookmark_model_;
base::WaitableEvent loaded_signal_;
};
}
#endif