OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/webdata/logins_table.h" | 5 #include "chrome/browser/webdata/logins_table.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/password_manager/ie7_password.h" | 10 #include "chrome/browser/password_manager/ie7_password.h" |
11 #include "sql/statement.h" | 11 #include "sql/statement.h" |
12 | 12 |
13 bool LoginsTable::AddIE7Login(const IE7PasswordInfo& info) { | 13 bool LoginsTable::AddIE7Login(const IE7PasswordInfo& info) { |
14 sql::Statement s(db_->GetUniqueStatement( | 14 sql::Statement s(db_->GetUniqueStatement( |
15 "INSERT OR REPLACE INTO ie7_logins " | 15 "INSERT OR REPLACE INTO ie7_logins " |
16 "(url_hash, password_value, date_created) " | 16 "(url_hash, password_value, date_created) " |
17 "VALUES (?,?,?)")); | 17 "VALUES (?,?,?)")); |
18 if (!s) { | |
19 NOTREACHED() << db_->GetErrorMessage(); | |
20 return false; | |
21 } | |
22 | |
23 s.BindString(0, WideToUTF8(info.url_hash)); | 18 s.BindString(0, WideToUTF8(info.url_hash)); |
24 s.BindBlob(1, &info.encrypted_data.front(), | 19 s.BindBlob(1, &info.encrypted_data.front(), |
25 static_cast<int>(info.encrypted_data.size())); | 20 static_cast<int>(info.encrypted_data.size())); |
26 s.BindInt64(2, info.date_created.ToTimeT()); | 21 s.BindInt64(2, info.date_created.ToTimeT()); |
27 if (!s.Run()) { | 22 |
28 NOTREACHED(); | 23 return s.Run(); |
29 return false; | |
30 } | |
31 return true; | |
32 } | 24 } |
33 | 25 |
34 bool LoginsTable::RemoveIE7Login(const IE7PasswordInfo& info) { | 26 bool LoginsTable::RemoveIE7Login(const IE7PasswordInfo& info) { |
35 // Remove a login by UNIQUE-constrained fields. | 27 // Remove a login by UNIQUE-constrained fields. |
36 sql::Statement s(db_->GetUniqueStatement( | 28 sql::Statement s(db_->GetUniqueStatement( |
37 "DELETE FROM ie7_logins WHERE url_hash = ?")); | 29 "DELETE FROM ie7_logins WHERE url_hash = ?")); |
38 if (!s) { | |
39 NOTREACHED() << db_->GetErrorMessage(); | |
40 return false; | |
41 } | |
42 s.BindString(0, WideToUTF8(info.url_hash)); | 30 s.BindString(0, WideToUTF8(info.url_hash)); |
43 | 31 |
44 if (!s.Run()) { | 32 return s.Run(); |
45 NOTREACHED(); | |
46 return false; | |
47 } | |
48 return true; | |
49 } | 33 } |
50 | 34 |
51 bool LoginsTable::GetIE7Login(const IE7PasswordInfo& info, | 35 bool LoginsTable::GetIE7Login(const IE7PasswordInfo& info, |
52 IE7PasswordInfo* result) { | 36 IE7PasswordInfo* result) { |
53 DCHECK(result); | 37 DCHECK(result); |
54 sql::Statement s(db_->GetUniqueStatement( | 38 sql::Statement s(db_->GetUniqueStatement( |
55 "SELECT password_value, date_created FROM ie7_logins " | 39 "SELECT password_value, date_created FROM ie7_logins " |
56 "WHERE url_hash == ? ")); | 40 "WHERE url_hash == ? ")); |
57 if (!s) { | 41 s.BindString16(0, info.url_hash); |
58 NOTREACHED() << db_->GetErrorMessage(); | |
59 return false; | |
60 } | |
61 | 42 |
62 s.BindString(0, WideToUTF8(info.url_hash)); | |
63 if (s.Step()) { | 43 if (s.Step()) { |
64 s.ColumnBlobAsVector(0, &result->encrypted_data); | 44 s.ColumnBlobAsVector(0, &result->encrypted_data); |
65 result->date_created = base::Time::FromTimeT(s.ColumnInt64(1)); | 45 result->date_created = base::Time::FromTimeT(s.ColumnInt64(1)); |
66 result->url_hash = info.url_hash; | 46 result->url_hash = info.url_hash; |
67 } | 47 } |
68 return s.Succeeded(); | 48 return s.Succeeded(); |
69 } | 49 } |
OLD | NEW |