OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 entry. |
| 4 |
| 5 #include "chrome/browser/sync/util/user_settings.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "chrome/browser/sync/util/crypto_helpers.h" |
| 10 #include "chrome/browser/sync/util/data_encryption.h" |
| 11 #include "chrome/browser/sync/util/query_helpers.h" |
| 12 |
| 13 using std::string; |
| 14 |
| 15 namespace browser_sync { |
| 16 |
| 17 bool UserSettings::GetLastUser(string* username) { |
| 18 ScopedDBHandle dbhandle(this); |
| 19 ScopedStatement query(PrepareQuery(dbhandle.get(), |
| 20 "SELECT email FROM cookies")); |
| 21 if (SQLITE_ROW == sqlite3_step(query.get())) { |
| 22 GetColumn(query.get(), 0, username); |
| 23 return true; |
| 24 } else { |
| 25 return false; |
| 26 } |
| 27 } |
| 28 |
| 29 void UserSettings::ClearAllServiceTokens() { |
| 30 ScopedDBHandle dbhandle(this); |
| 31 ExecOrDie(dbhandle.get(), "DELETE FROM cookies"); |
| 32 } |
| 33 |
| 34 void UserSettings::SetAuthTokenForService(const string& email, |
| 35 const string& service_name, const string& long_lived_service_token) { |
| 36 ScopedDBHandle dbhandle(this); |
| 37 ExecOrDie(dbhandle.get(), "INSERT INTO cookies " |
| 38 "(email, service_name, service_token) " |
| 39 "values (?, ?, ?)", email, service_name, |
| 40 EncryptData(long_lived_service_token)); |
| 41 } |
| 42 |
| 43 // Returns the username whose credentials have been persisted as well as |
| 44 // a service token for the named service. |
| 45 bool UserSettings::GetLastUserAndServiceToken(const string& service_name, |
| 46 string* username, |
| 47 string* service_token) { |
| 48 ScopedDBHandle dbhandle(this); |
| 49 ScopedStatement query(PrepareQuery( |
| 50 dbhandle.get(), |
| 51 "SELECT email, service_token FROM cookies WHERE service_name = ?", |
| 52 service_name)); |
| 53 |
| 54 if (SQLITE_ROW == sqlite3_step(query.get())) { |
| 55 GetColumn(query.get(), 0, username); |
| 56 |
| 57 std::vector<uint8> encrypted_service_token; |
| 58 GetColumn(query.get(), 1, &encrypted_service_token); |
| 59 DecryptData(encrypted_service_token, service_token); |
| 60 return true; |
| 61 } |
| 62 |
| 63 return false; |
| 64 } |
| 65 |
| 66 } // namespace browser_sync |
| 67 |
OLD | NEW |