Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / components / webdata / common / web_database.h
blob22730fe23c4036f72c1857b2a8d1b6f0f8ebf8a4
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 COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_
8 #include <map>
10 #include "base/memory/scoped_ptr.h"
11 #include "components/webdata/common/web_database_table.h"
12 #include "components/webdata/common/webdata_export.h"
13 #include "sql/connection.h"
14 #include "sql/init_status.h"
15 #include "sql/meta_table.h"
17 namespace base {
18 class FilePath;
21 // This class manages a SQLite database that stores various web page meta data.
22 class WEBDATA_EXPORT WebDatabase {
23 public:
24 enum State {
25 COMMIT_NOT_NEEDED,
26 COMMIT_NEEDED
28 // Exposed publicly so the keyword table can access it.
29 static const int kCurrentVersionNumber;
31 WebDatabase();
32 virtual ~WebDatabase();
34 // Adds a database table. Ownership remains with the caller, which
35 // must ensure that the lifetime of |table| exceeds this object's
36 // lifetime. Must only be called before Init.
37 void AddTable(WebDatabaseTable* table);
39 // Retrieves a table based on its |key|.
40 WebDatabaseTable* GetTable(WebDatabaseTable::TypeKey key);
42 // Initialize the database given a name. The name defines where the SQLite
43 // file is. If this returns an error code, no other method should be called.
45 // Before calling this method, you must call AddTable for any
46 // WebDatabaseTable objects that are supposed to participate in
47 // managing the database.
48 sql::InitStatus Init(const base::FilePath& db_name);
50 // Transactions management
51 void BeginTransaction();
52 void CommitTransaction();
54 // Exposed for testing only.
55 sql::Connection* GetSQLConnection();
57 private:
58 // Used by |Init()| to migration database schema from older versions to
59 // current version.
60 sql::InitStatus MigrateOldVersionsAsNeeded();
62 // Migrates this database to |version|. Returns false if there was
63 // migration work to do and it failed, true otherwise.
65 // Implementations may set |*update_compatible_version| to true if
66 // the compatible version should be changed to |version|.
67 // Implementations should otherwise not modify this parameter.
68 bool MigrateToVersion(int version,
69 bool* update_compatible_version);
71 // Migration method for version 58.
72 bool MigrateToVersion58DropWebAppsAndIntents();
74 sql::Connection db_;
75 sql::MetaTable meta_table_;
77 // Map of all the different tables that have been added to this
78 // object. Non-owning.
79 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap;
80 TableMap tables_;
82 DISALLOW_COPY_AND_ASSIGN(WebDatabase);
85 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_