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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// Copyright (c) 2012 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.
// The InMemoryHistoryBackend is a wrapper around the in-memory URL database.
// It maintains an in-memory cache of a subset of history that is required for
// low-latency operations, such as in-line autocomplete.
//
// The in-memory cache provides the following guarantees:
// (1.) It will always contain URLRows that either have a |typed_count| > 0; or
// that have a corresponding search term, in which case information about
// the search term is also stored.
// (2.) It will be an actual subset, i.e., it will contain verbatim data, and
// will never contain more data that can be found in the main database.
//
// The InMemoryHistoryBackend is created on the history thread and passed to the
// main thread where operations can be completed synchronously. It listens for
// notifications from the "regular" history backend and keeps itself in sync.
#ifndef COMPONENTS_HISTORY_CORE_BROWSER_IN_MEMORY_HISTORY_BACKEND_H_
#define COMPONENTS_HISTORY_CORE_BROWSER_IN_MEMORY_HISTORY_BACKEND_H_
#include <string>
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/scoped_observer.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/keyword_id.h"
namespace base {
class FilePath;
}
namespace history {
class HistoryBackendTestBase;
class HistoryService;
class InMemoryDatabase;
class InMemoryHistoryBackendTest;
class URLDatabase;
class URLRow;
class InMemoryHistoryBackend : public HistoryServiceObserver {
public:
InMemoryHistoryBackend();
~InMemoryHistoryBackend() override;
// Initializes the backend from the history database pointed to by the
// full path in |history_filename|.
bool Init(const base::FilePath& history_filename);
// Does initialization work when this object is attached to the history
// system on the main thread. The argument is the profile with which the
// attached history service is under.
void AttachToHistoryService(HistoryService* history_service);
// Deletes all search terms for the specified keyword.
void DeleteAllSearchTermsForKeyword(KeywordID keyword_id);
// Returns the underlying database associated with this backend. The current
// autocomplete code was written fro this, but it should probably be removed
// so that it can deal directly with this object, rather than the DB.
InMemoryDatabase* db() const { return db_.get(); }
private:
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
FRIEND_TEST_ALL_PREFIXES(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse);
friend class HistoryBackendTestBase;
friend class InMemoryHistoryBackendTest;
// HistoryServiceObserver:
void OnURLVisited(HistoryService* history_service,
ui::PageTransition transition,
const URLRow& row,
const RedirectList& redirects,
base::Time visit_time) override;
void OnURLsModified(HistoryService* history_service,
const URLRows& changed_urls) override;
void OnURLsDeleted(HistoryService* history_service,
bool all_history,
bool expired,
const URLRows& deleted_rows,
const std::set<GURL>& favicon_urls) override;
void OnKeywordSearchTermUpdated(HistoryService* history_service,
const URLRow& row,
KeywordID keyword_id,
const base::string16& term) override;
void OnKeywordSearchTermDeleted(HistoryService* history_service,
URLID url_id) override;
// Handler for HISTORY_URL_VISITED and HISTORY_URLS_MODIFIED.
void OnURLVisitedOrModified(const URLRow& url_row);
scoped_ptr<InMemoryDatabase> db_;
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_;
DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend);
};
} // namespace history
#endif // COMPONENTS_HISTORY_CORE_BROWSER_IN_MEMORY_HISTORY_BACKEND_H_
|