1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_
6 #define CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_
8 #include "base/basictypes.h"
9 #include "chrome/browser/history/url_database.h"
10 #include "chrome/browser/history/visit_database.h"
11 #include "sql/connection.h"
12 #include "sql/init_status.h"
13 #include "sql/meta_table.h"
21 // Encapsulates the database operations for archived history.
23 // IMPORTANT NOTE: The IDs in this system for URLs and visits will be
24 // different than those in the main database. This is to eliminate the
25 // dependency between them so we can deal with each one on its own.
26 class ArchivedDatabase : public URLDatabase,
27 public VisitDatabase {
29 // Must call Init() before using other members.
31 virtual ~ArchivedDatabase();
33 // Initializes the database connection. This must return true before any other
34 // functions on this class are called.
35 bool Init(const base::FilePath& file_name);
37 // Try to trim the cache memory used by the database. If |aggressively| is
38 // true try to trim all unused cache, otherwise trim by half.
39 void TrimMemory(bool aggressively);
41 // Transactions on the database. We support nested transactions and only
42 // commit when the outermost one is committed (sqlite doesn't support true
43 // nested transactions).
44 void BeginTransaction();
45 void CommitTransaction();
47 // Returns the current version that we will generate archived databases with.
48 static int GetCurrentVersion();
53 // Implemented for the specialized databases.
54 virtual sql::Connection& GetDB() OVERRIDE;
56 // Makes sure the version is up-to-date, updating if necessary. If the
57 // database is too old to migrate, the user will be notified. In this case, or
58 // for other errors, false will be returned. True means it is up-to-date and
61 // This assumes it is called from the init function inside a transaction. It
62 // may commit the transaction and start a new one if migration requires it.
63 sql::InitStatus EnsureCurrentVersion();
67 sql::MetaTable meta_table_;
69 DISALLOW_COPY_AND_ASSIGN(ArchivedDatabase);
72 } // namespace history
74 #endif // CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_