summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/chrome_history_client.cc
blob: 13b511db6038c8fdce11c9bece750d27c6a02b14 (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
51
52
53
54
55
56
57
// Copyright 2014 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 "chrome/browser/history/chrome_history_client.h"

#include "base/logging.h"
#include "chrome/browser/ui/profile_error_dialog.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"

ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model)
    : bookmark_model_(bookmark_model) {
  DCHECK(bookmark_model_);
}

void ChromeHistoryClient::BlockUntilBookmarksLoaded() {
  bookmark_model_->BlockTillLoaded();
}

bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
  return bookmark_model_->IsBookmarked(url);
}

void ChromeHistoryClient::GetBookmarks(
    std::vector<history::URLAndTitle>* bookmarks) {
  std::vector<BookmarkModel::URLAndTitle> bookmarks_url_and_title;
  bookmark_model_->GetBookmarks(&bookmarks_url_and_title);

  bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size());
  for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) {
    history::URLAndTitle value = {
      bookmarks_url_and_title[i].url,
      bookmarks_url_and_title[i].title,
    };
    bookmarks->push_back(value);
  }
}

void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) {
  ShowProfileErrorDialog(
      PROFILE_ERROR_HISTORY,
      (init_status == sql::INIT_FAILURE) ?
      IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
}

void ChromeHistoryClient::Shutdown() {
  // It's possible that bookmarks haven't loaded and history is waiting for
  // bookmarks to complete loading. In such a situation history can't shutdown
  // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To
  // break the deadlock we tell BookmarkModel it's about to be deleted so that
  // it can release the signal history is waiting on, allowing history to
  // shutdown (HistoryService::Cleanup to complete). In such a scenario history
  // sees an incorrect view of bookmarks, but it's better than a deadlock.
  bookmark_model_->Shutdown();
}