Don't preload rarely seen large images
[chromium-blink-merge.git] / components / webdata / common / web_database.h
blobc6d0c1d51ef068f0b96566c9c0dd11333d993a74
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;
30 // The newest version of the database Chrome will NOT try to migrate.
31 static const int kDeprecatedVersionNumber;
33 WebDatabase();
34 virtual ~WebDatabase();
36 // Adds a database table. Ownership remains with the caller, which
37 // must ensure that the lifetime of |table| exceeds this object's
38 // lifetime. Must only be called before Init.
39 void AddTable(WebDatabaseTable* table);
41 // Retrieves a table based on its |key|.
42 WebDatabaseTable* GetTable(WebDatabaseTable::TypeKey key);
44 // Initialize the database given a name. The name defines where the SQLite
45 // file is. If this returns an error code, no other method should be called.
47 // Before calling this method, you must call AddTable for any
48 // WebDatabaseTable objects that are supposed to participate in
49 // managing the database.
50 sql::InitStatus Init(const base::FilePath& db_name);
52 // Transactions management
53 void BeginTransaction();
54 void CommitTransaction();
56 // Exposed for testing only.
57 sql::Connection* GetSQLConnection();
59 private:
60 // Used by |Init()| to migration database schema from older versions to
61 // current version.
62 sql::InitStatus MigrateOldVersionsAsNeeded();
64 // Migrates this database to |version|. Returns false if there was
65 // migration work to do and it failed, true otherwise.
67 // Implementations may set |*update_compatible_version| to true if
68 // the compatible version should be changed to |version|.
69 // Implementations should otherwise not modify this parameter.
70 bool MigrateToVersion(int version,
71 bool* update_compatible_version);
73 // Migration method for version 58.
74 bool MigrateToVersion58DropWebAppsAndIntents();
76 sql::Connection db_;
77 sql::MetaTable meta_table_;
79 // Map of all the different tables that have been added to this
80 // object. Non-owning.
81 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap;
82 TableMap tables_;
84 DISALLOW_COPY_AND_ASSIGN(WebDatabase);
87 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_