summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/history/history_backend_client_impl.cc
blob: 4100bce855b43388fb2e3ac046a81367a2755b34 (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
// Copyright 2015 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.

#include "ios/chrome/browser/history/history_backend_client_impl.h"

#include "components/bookmarks/browser/bookmark_model.h"
#include "url/gurl.h"

HistoryBackendClientImpl::HistoryBackendClientImpl(
    bookmarks::BookmarkModel* bookmark_model)
    : bookmark_model_(bookmark_model) {
}

HistoryBackendClientImpl::~HistoryBackendClientImpl() {
}

bool HistoryBackendClientImpl::IsBookmarked(const GURL& url) {
  if (!bookmark_model_)
    return false;

  // HistoryBackendClient is used to determine if an URL is bookmarked. The data
  // is loaded on a separate thread and may not be done when this method is
  // called, therefore blocks until the bookmarks have finished loading.
  bookmark_model_->BlockTillLoaded();
  return bookmark_model_->IsBookmarked(url);
}

void HistoryBackendClientImpl::GetBookmarks(
    std::vector<history::URLAndTitle>* bookmarks) {
  if (!bookmark_model_)
    return;

  // HistoryBackendClient is used to determine the set of bookmarked URLs. The
  // data is loaded on a separate thread and may not be done when this method is
  // called, therefore blocks until the bookmarks have finished loading.
  std::vector<bookmarks::BookmarkModel::URLAndTitle> url_and_titles;
  bookmark_model_->BlockTillLoaded();
  bookmark_model_->GetBookmarks(&url_and_titles);

  bookmarks->reserve(bookmarks->size() + url_and_titles.size());
  for (const auto& url_and_title : url_and_titles) {
    history::URLAndTitle value = {url_and_title.url, url_and_title.title};
    bookmarks->push_back(value);
  }
}

bool HistoryBackendClientImpl::ShouldReportDatabaseError() {
  return false;
}