Chromium Code Reviews| 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/token_service_table.h" | 5 #include "chrome/browser/webdata/token_service_table.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 return true; | 23 return true; |
| 24 } | 24 } |
| 25 | 25 |
| 26 bool TokenServiceTable::IsSyncable() { | 26 bool TokenServiceTable::IsSyncable() { |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool TokenServiceTable::RemoveAllTokens() { | 30 bool TokenServiceTable::RemoveAllTokens() { |
| 31 sql::Statement s(db_->GetUniqueStatement( | 31 sql::Statement s(db_->GetUniqueStatement( |
| 32 "DELETE FROM token_service")); | 32 "DELETE FROM token_service")); |
| 33 if (!s) { | |
| 34 NOTREACHED() << "Statement prepare failed"; | |
| 35 return false; | |
| 36 } | |
| 37 | 33 |
| 38 return s.Run(); | 34 return s.Run(); |
| 39 } | 35 } |
| 40 | 36 |
| 41 bool TokenServiceTable::SetTokenForService(const std::string& service, | 37 bool TokenServiceTable::SetTokenForService(const std::string& service, |
| 42 const std::string& token) { | 38 const std::string& token) { |
| 43 // Don't bother with a cached statement since this will be a relatively | 39 // Don't bother with a cached statement since this will be a relatively |
| 44 // infrequent operation. | 40 // infrequent operation. |
| 45 sql::Statement s(db_->GetUniqueStatement( | 41 sql::Statement s(db_->GetUniqueStatement( |
| 46 "INSERT OR REPLACE INTO token_service " | 42 "INSERT OR REPLACE INTO token_service " |
| 47 "(service, encrypted_token) VALUES (?, ?)")); | 43 "(service, encrypted_token) VALUES (?, ?)")); |
| 48 if (!s) { | 44 |
| 49 NOTREACHED() << "Statement prepare failed"; | 45 if (!s.is_valid()) |
| 50 return false; | 46 return false; |
|
Scott Hess - ex-Googler
2011/12/15 23:02:57
Why not remove?
Greg Billock
2011/12/16 17:26:58
I was being conservative about executing EncryptSt
Scott Hess - ex-Googler
2011/12/16 22:37:08
In this case any savings would only happen when th
| |
| 51 } | |
| 52 | 47 |
| 53 std::string encrypted_token; | 48 std::string encrypted_token; |
| 54 | |
| 55 bool encrypted = Encryptor::EncryptString(token, &encrypted_token); | 49 bool encrypted = Encryptor::EncryptString(token, &encrypted_token); |
| 56 if (!encrypted) { | 50 if (!encrypted) { |
| 57 return false; | 51 return false; |
| 58 } | 52 } |
| 59 | 53 |
| 60 s.BindString(0, service); | 54 s.BindString(0, service); |
| 61 s.BindBlob(1, encrypted_token.data(), | 55 s.BindBlob(1, encrypted_token.data(), |
| 62 static_cast<int>(encrypted_token.length())); | 56 static_cast<int>(encrypted_token.length())); |
| 57 | |
| 63 return s.Run(); | 58 return s.Run(); |
| 64 } | 59 } |
| 65 | 60 |
| 66 bool TokenServiceTable::GetAllTokens( | 61 bool TokenServiceTable::GetAllTokens( |
| 67 std::map<std::string, std::string>* tokens) { | 62 std::map<std::string, std::string>* tokens) { |
| 68 sql::Statement s(db_->GetUniqueStatement( | 63 sql::Statement s(db_->GetUniqueStatement( |
| 69 "SELECT service, encrypted_token FROM token_service")); | 64 "SELECT service, encrypted_token FROM token_service")); |
| 70 if (!s) { | 65 |
| 71 NOTREACHED() << "Statement prepare failed"; | 66 if (!s.is_valid()) |
| 72 return false; | 67 return false; |
| 73 } | |
| 74 | 68 |
| 75 while (s.Step()) { | 69 while (s.Step()) { |
| 76 std::string encrypted_token; | 70 std::string encrypted_token; |
| 77 std::string decrypted_token; | 71 std::string decrypted_token; |
| 78 std::string service; | 72 std::string service; |
| 79 service = s.ColumnString(0); | 73 service = s.ColumnString(0); |
| 80 bool entry_ok = !service.empty() && | 74 bool entry_ok = !service.empty() && |
| 81 s.ColumnBlobAsString(1, &encrypted_token); | 75 s.ColumnBlobAsString(1, &encrypted_token); |
| 82 if (entry_ok) { | 76 if (entry_ok) { |
| 83 Encryptor::DecryptString(encrypted_token, &decrypted_token); | 77 Encryptor::DecryptString(encrypted_token, &decrypted_token); |
| 84 (*tokens)[service] = decrypted_token; | 78 (*tokens)[service] = decrypted_token; |
| 85 } else { | 79 } else { |
| 86 NOTREACHED(); | 80 NOTREACHED(); |
| 87 return false; | 81 return false; |
| 88 } | 82 } |
| 89 } | 83 } |
| 90 return true; | 84 return true; |
| 91 } | 85 } |
| 92 | |
| OLD | NEW |