1// Copyright (c) 2009 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 CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_
6#define CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_
7#pragma once
8
9#include "app/sql/connection.h"
10#include "app/sql/init_status.h"
11#include "app/sql/meta_table.h"
12#include "base/basictypes.h"
13#include "chrome/browser/history/url_database.h"
14#include "chrome/browser/history/visit_database.h"
15
16class FilePath;
17
18namespace history {
19
20// Encapsulates the database operations for archived history.
21//
22// IMPORTANT NOTE: The IDs in this system for URLs and visits will be
23// different than those in the main database. This is to eliminate the
24// dependency between them so we can deal with each one on its own.
25class ArchivedDatabase : public URLDatabase,
26                         public VisitDatabase {
27 public:
28  // Must call Init() before using other members.
29  ArchivedDatabase();
30  virtual ~ArchivedDatabase();
31
32  // Initializes the database connection. This must return true before any other
33  // functions on this class are called.
34  bool Init(const FilePath& file_name);
35
36  // Transactions on the database. We support nested transactions and only
37  // commit when the outermost one is committed (sqlite doesn't support true
38  // nested transactions).
39  void BeginTransaction();
40  void CommitTransaction();
41
42 private:
43  // Implemented for the specialized databases.
44  virtual sql::Connection& GetDB();
45
46  // Makes sure the version is up-to-date, updating if necessary. If the
47  // database is too old to migrate, the user will be notified. In this case, or
48  // for other errors, false will be returned. True means it is up-to-date and
49  // ready for use.
50  //
51  // This assumes it is called from the init function inside a transaction. It
52  // may commit the transaction and start a new one if migration requires it.
53  sql::InitStatus EnsureCurrentVersion();
54
55  // The database.
56  sql::Connection db_;
57  sql::MetaTable meta_table_;
58
59  DISALLOW_COPY_AND_ASSIGN(ArchivedDatabase);
60};
61
62}  // namespace history
63
64#endif  // CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_
65