- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / webdata / logins_table_win.cc
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 #include "chrome/browser/webdata/logins_table.h"
6
7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h"
10 #include "components/webdata/encryptor/ie7_password_win.h"
11 #include "sql/statement.h"
12
13 bool LoginsTable::AddIE7Login(const IE7PasswordInfo& info) {
14   sql::Statement s(db_->GetUniqueStatement(
15       "INSERT OR REPLACE INTO ie7_logins "
16       "(url_hash, password_value, date_created) "
17       "VALUES (?,?,?)"));
18   s.BindString(0, WideToUTF8(info.url_hash));
19   s.BindBlob(1, &info.encrypted_data.front(),
20              static_cast<int>(info.encrypted_data.size()));
21   s.BindInt64(2, info.date_created.ToTimeT());
22
23   return s.Run();
24 }
25
26 bool LoginsTable::RemoveIE7Login(const IE7PasswordInfo& info) {
27   // Remove a login by UNIQUE-constrained fields.
28   sql::Statement s(db_->GetUniqueStatement(
29       "DELETE FROM ie7_logins WHERE url_hash = ?"));
30   s.BindString(0, WideToUTF8(info.url_hash));
31
32   return s.Run();
33 }
34
35 bool LoginsTable::GetIE7Login(const IE7PasswordInfo& info,
36                               IE7PasswordInfo* result) {
37   DCHECK(result);
38   sql::Statement s(db_->GetUniqueStatement(
39       "SELECT password_value, date_created FROM ie7_logins "
40       "WHERE url_hash == ? "));
41   s.BindString16(0, info.url_hash);
42
43   if (s.Step()) {
44     s.ColumnBlobAsVector(0, &result->encrypted_data);
45     result->date_created = base::Time::FromTimeT(s.ColumnInt64(1));
46     result->url_hash = info.url_hash;
47   }
48   return s.Succeeded();
49 }