• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_IN_MEMORY_DATABASE_H_
6 #define COMPONENTS_HISTORY_CORE_BROWSER_IN_MEMORY_DATABASE_H_
7 
8 #include "base/basictypes.h"
9 #include "components/history/core/browser/url_database.h"
10 #include "sql/connection.h"
11 
12 namespace base {
13 class FilePath;
14 }
15 
16 namespace history {
17 
18 // Class used for a fast in-memory cache of typed URLs. Used for inline
19 // autocomplete since it is fast enough to be called synchronously as the user
20 // is typing.
21 class InMemoryDatabase : public URLDatabase {
22  public:
23   InMemoryDatabase();
24   virtual ~InMemoryDatabase();
25 
26   // Creates an empty in-memory database.
27   bool InitFromScratch();
28 
29   // Initializes the database by directly slurping the data from the given
30   // file. Conceptually, the InMemoryHistoryBackend should do the populating
31   // after this object does some common initialization, but that would be
32   // much slower.
33   bool InitFromDisk(const base::FilePath& history_name);
34 
35  protected:
36   // Implemented for URLDatabase.
37   virtual sql::Connection& GetDB() OVERRIDE;
38 
39  private:
40   // Initializes the database connection, this is the shared code between
41   // InitFromScratch() and InitFromDisk() above. Returns true on success.
42   bool InitDB();
43 
44   sql::Connection db_;
45 
46   DISALLOW_COPY_AND_ASSIGN(InMemoryDatabase);
47 };
48 
49 }  // namespace history
50 
51 #endif  // COMPONENTS_HISTORY_CORE_BROWSER_IN_MEMORY_DATABASE_H_
52