- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / archived_database.h
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.
4
5 #ifndef CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_
6 #define CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_
7
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"
14
15 namespace base {
16 class FilePath;
17 }
18
19 namespace history {
20
21 // Encapsulates the database operations for archived history.
22 //
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 {
28  public:
29   // Must call Init() before using other members.
30   ArchivedDatabase();
31   virtual ~ArchivedDatabase();
32
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);
36
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);
40
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();
46
47   // Returns the current version that we will generate archived databases with.
48   static int GetCurrentVersion();
49
50  private:
51   bool InitTables();
52
53   // Implemented for the specialized databases.
54   virtual sql::Connection& GetDB() OVERRIDE;
55
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
59   // ready for use.
60   //
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();
64
65   // The database.
66   sql::Connection db_;
67   sql::MetaTable meta_table_;
68
69   DISALLOW_COPY_AND_ASSIGN(ArchivedDatabase);
70 };
71
72 }  // namespace history
73
74 #endif  // CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_