Home | History | Annotate | Download | only in webdata
      1 // Copyright (c) 2011 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_WEBDATA_WEB_DATABASE_H_
      6 #define CHROME_BROWSER_WEBDATA_WEB_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/memory/scoped_ptr.h"
     13 #include "chrome/browser/webdata/autofill_table.h"
     14 #include "chrome/browser/webdata/keyword_table.h"
     15 #include "chrome/browser/webdata/logins_table.h"
     16 #include "chrome/browser/webdata/token_service_table.h"
     17 #include "chrome/browser/webdata/web_apps_table.h"
     18 
     19 class FilePath;
     20 class NotificationService;
     21 
     22 // This class manages a SQLite database that stores various web page meta data.
     23 class WebDatabase {
     24  public:
     25   WebDatabase();
     26   virtual ~WebDatabase();
     27 
     28   // Initialize the database given a name. The name defines where the SQLite
     29   // file is. If this returns an error code, no other method should be called.
     30   sql::InitStatus Init(const FilePath& db_name);
     31 
     32   // Transactions management
     33   void BeginTransaction();
     34   void CommitTransaction();
     35 
     36   virtual AutofillTable* GetAutofillTable();
     37   virtual KeywordTable* GetKeywordTable();
     38   virtual LoginsTable* GetLoginsTable();
     39   virtual TokenServiceTable* GetTokenServiceTable();
     40   virtual WebAppsTable* GetWebAppsTable();
     41 
     42   // Exposed for testing only.
     43   sql::Connection* GetSQLConnection();
     44 
     45  private:
     46   // Used by |Init()| to migration database schema from older versions to
     47   // current version.
     48   sql::InitStatus MigrateOldVersionsAsNeeded();
     49 
     50   sql::Connection db_;
     51   sql::MetaTable meta_table_;
     52 
     53   scoped_ptr<AutofillTable> autofill_table_;
     54   scoped_ptr<KeywordTable> keyword_table_;
     55   scoped_ptr<LoginsTable> logins_table_;
     56   scoped_ptr<TokenServiceTable> token_service_table_;
     57   scoped_ptr<WebAppsTable> web_apps_table_;
     58 
     59   scoped_ptr<NotificationService> notification_service_;
     60 
     61   DISALLOW_COPY_AND_ASSIGN(WebDatabase);
     62 };
     63 
     64 #endif  // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
     65