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/sync/util/user_settings.h" | 5 #include "chrome/browser/sync/util/user_settings.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/sync/util/data_encryption.h" | 10 #include "chrome/browser/sync/util/data_encryption.h" |
11 #include "chrome/browser/sync/util/sqlite_utils.h" | 11 #include "chrome/browser/sync/util/sqlite_utils.h" |
12 | 12 |
13 using std::string; | 13 using std::string; |
14 | 14 |
15 namespace browser_sync { | 15 namespace browser_sync { |
16 | 16 |
17 void UserSettings::SetAuthTokenForService(const string& email, | 17 void UserSettings::SetAuthTokenForService(const string& email, |
18 const string& service_name, const string& long_lived_service_token) { | 18 const string& service_name, const string& long_lived_service_token) { |
19 ScopedDBHandle dbhandle(this); | 19 ScopedDBHandle dbhandle(this); |
20 SQLStatement statement; | 20 sqlite_utils::SQLStatement statement; |
21 statement.prepare(dbhandle.get(), | 21 statement.prepare(dbhandle.get(), |
22 "INSERT INTO cookies " | 22 "INSERT INTO cookies " |
23 "(email, service_name, service_token) " | 23 "(email, service_name, service_token) " |
24 "values (?, ?, ?)"); | 24 "values (?, ?, ?)"); |
25 statement.bind_string(0, email); | 25 statement.bind_string(0, email); |
26 statement.bind_string(1, service_name); | 26 statement.bind_string(1, service_name); |
27 statement.bind_blob(2, &EncryptData(long_lived_service_token)); | 27 statement.bind_blob(2, &EncryptData(long_lived_service_token)); |
28 if (SQLITE_DONE != statement.step()) { | 28 if (SQLITE_DONE != statement.step()) { |
29 LOG(FATAL) << sqlite3_errmsg(dbhandle.get()); | 29 LOG(FATAL) << sqlite3_errmsg(dbhandle.get()); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 // Returns the username whose credentials have been persisted as well as | 33 // Returns the username whose credentials have been persisted as well as |
34 // a service token for the named service. | 34 // a service token for the named service. |
35 bool UserSettings::GetLastUserAndServiceToken(const string& service_name, | 35 bool UserSettings::GetLastUserAndServiceToken(const string& service_name, |
36 string* username, | 36 string* username, |
37 string* service_token) { | 37 string* service_token) { |
38 ScopedDBHandle dbhandle(this); | 38 ScopedDBHandle dbhandle(this); |
39 SQLStatement query; | 39 sqlite_utils::SQLStatement query; |
40 query.prepare(dbhandle.get(), | 40 query.prepare(dbhandle.get(), |
41 "SELECT email, service_token FROM cookies" | 41 "SELECT email, service_token FROM cookies" |
42 " WHERE service_name = ?"); | 42 " WHERE service_name = ?"); |
43 query.bind_string(0, service_name.c_str()); | 43 query.bind_string(0, service_name.c_str()); |
44 | 44 |
45 if (SQLITE_ROW == query.step()) { | 45 if (SQLITE_ROW == query.step()) { |
46 *username = query.column_string(0); | 46 *username = query.column_string(0); |
47 | 47 |
48 std::vector<uint8> encrypted_service_token; | 48 std::vector<uint8> encrypted_service_token; |
49 query.column_blob_as_vector(1, &encrypted_service_token); | 49 query.column_blob_as_vector(1, &encrypted_service_token); |
50 DecryptData(encrypted_service_token, service_token); | 50 DecryptData(encrypted_service_token, service_token); |
51 return true; | 51 return true; |
52 } | 52 } |
53 | 53 |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
57 } // namespace browser_sync | 57 } // namespace browser_sync |
OLD | NEW |