Home | History | Annotate | Download | only in webdata
      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 #include "chrome/browser/webdata/logins_table.h"
      6 
      7 #include <limits>
      8 
      9 #include "base/logging.h"
     10 #include "components/webdata/common/web_database.h"
     11 #include "sql/statement.h"
     12 
     13 namespace {
     14 
     15 WebDatabaseTable::TypeKey GetKey() {
     16   // We just need a unique constant. Use the address of a static that
     17   // COMDAT folding won't touch in an optimizing linker.
     18   static int table_key = 0;
     19   return reinterpret_cast<void*>(&table_key);
     20 }
     21 
     22 }  // namespace
     23 
     24 LoginsTable* LoginsTable::FromWebDatabase(WebDatabase* db) {
     25   return static_cast<LoginsTable*>(db->GetTable(GetKey()));
     26 }
     27 
     28 WebDatabaseTable::TypeKey LoginsTable::GetTypeKey() const {
     29   return GetKey();
     30 }
     31 
     32 bool LoginsTable::Init(sql::Connection* db, sql::MetaTable* meta_table) {
     33   WebDatabaseTable::Init(db, meta_table);
     34 
     35   if (db_->DoesTableExist("logins")) {
     36     // We don't check for success. It doesn't matter that much.
     37     // If we fail we'll just try again later anyway.
     38     ignore_result(db_->Execute("DROP TABLE logins"));
     39   }
     40 
     41 #if defined(OS_WIN)
     42   if (!db_->DoesTableExist("ie7_logins")) {
     43     if (!db_->Execute("CREATE TABLE ie7_logins ("
     44                       "url_hash VARCHAR NOT NULL, "
     45                       "password_value BLOB, "
     46                       "date_created INTEGER NOT NULL,"
     47                       "UNIQUE "
     48                       "(url_hash))")) {
     49       NOTREACHED();
     50       return false;
     51     }
     52     if (!db_->Execute("CREATE INDEX ie7_logins_hash ON "
     53                       "ie7_logins (url_hash)")) {
     54       NOTREACHED();
     55       return false;
     56     }
     57   }
     58 #endif
     59 
     60   return true;
     61 }
     62 
     63 bool LoginsTable::IsSyncable() {
     64   return true;
     65 }
     66 
     67 bool LoginsTable::MigrateToVersion(int version,
     68                                    bool* update_compatible_version) {
     69   return true;
     70 }
     71