blob: 780a59dfcc6d2d0ebd66a1e818d5d37b240f767b (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// 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_client_impl.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/logging.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/history/core/browser/history_service.h"
#include "ios/chrome/browser/history/history_backend_client_impl.h"
#include "ios/chrome/browser/history/history_utils.h"
#include "url/gurl.h"
HistoryClientImpl::HistoryClientImpl(bookmarks::BookmarkModel* bookmark_model)
: bookmark_model_(bookmark_model), is_bookmark_model_observer_(false) {
}
HistoryClientImpl::~HistoryClientImpl() {
}
void HistoryClientImpl::OnHistoryServiceCreated(
history::HistoryService* history_service) {
DCHECK(!is_bookmark_model_observer_);
if (bookmark_model_) {
on_bookmarks_removed_ =
base::Bind(&history::HistoryService::URLsNoLongerBookmarked,
base::Unretained(history_service));
favicons_changed_subscription_ =
history_service->AddFaviconsChangedCallback(
base::Bind(&bookmarks::BookmarkModel::OnFaviconsChanged,
base::Unretained(bookmark_model_)));
bookmark_model_->AddObserver(this);
is_bookmark_model_observer_ = true;
}
}
void HistoryClientImpl::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.
if (bookmark_model_) {
if (is_bookmark_model_observer_) {
is_bookmark_model_observer_ = false;
bookmark_model_->RemoveObserver(this);
favicons_changed_subscription_.reset();
on_bookmarks_removed_.Reset();
}
bookmark_model_->Shutdown();
}
}
bool HistoryClientImpl::CanAddURL(const GURL& url) {
return ios::CanAddURLToHistory(url);
}
void HistoryClientImpl::NotifyProfileError(sql::InitStatus init_status) {
}
scoped_ptr<history::HistoryBackendClient>
HistoryClientImpl::CreateBackendClient() {
return make_scoped_ptr(new HistoryBackendClientImpl(bookmark_model_));
}
void HistoryClientImpl::BookmarkModelChanged() {
}
void HistoryClientImpl::BookmarkNodeRemoved(
bookmarks::BookmarkModel* model,
const bookmarks::BookmarkNode* parent,
int old_index,
const bookmarks::BookmarkNode* node,
const std::set<GURL>& no_longer_bookmarked) {
if (!on_bookmarks_removed_.is_null())
on_bookmarks_removed_.Run(no_longer_bookmarked);
}
void HistoryClientImpl::BookmarkAllUserNodesRemoved(
bookmarks::BookmarkModel* model,
const std::set<GURL>& removed_urls) {
if (!on_bookmarks_removed_.is_null())
on_bookmarks_removed_.Run(removed_urls);
}
|