Disable firewall check. It takes signifficant time, need to be on FILE thread.
[chromium-blink-merge.git] / components / webdata / common / web_database.h
blobe7fedf072b29e964d177d854e540e4330cc946e7
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 sql::Connection db_;
63 sql::MetaTable meta_table_;
65 // Map of all the different tables that have been added to this
66 // object. Non-owning.
67 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap;
68 TableMap tables_;
70 DISALLOW_COPY_AND_ASSIGN(WebDatabase);
73 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_