OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This class isn't pretty. It's just a step better than globals, which is what | 5 // This class isn't pretty. It's just a step better than globals, which is what |
6 // these were previously. | 6 // these were previously. |
7 | 7 |
8 #include "chrome/browser/sync/util/user_settings.h" | 8 #include "chrome/browser/sync/util/user_settings.h" |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 static const int kCurrentDBVersion = 12; | 72 static const int kCurrentDBVersion = 12; |
73 | 73 |
74 UserSettings::ScopedDBHandle::ScopedDBHandle(UserSettings* settings) | 74 UserSettings::ScopedDBHandle::ScopedDBHandle(UserSettings* settings) |
75 : mutex_lock_(settings->dbhandle_mutex_), handle_(&settings->dbhandle_) { | 75 : mutex_lock_(settings->dbhandle_mutex_), handle_(&settings->dbhandle_) { |
76 } | 76 } |
77 | 77 |
78 UserSettings::UserSettings() : dbhandle_(NULL) { | 78 UserSettings::UserSettings() : dbhandle_(NULL) { |
79 } | 79 } |
80 | 80 |
81 string UserSettings::email() const { | 81 string UserSettings::email() const { |
82 AutoLock lock(mutex_); | 82 base::AutoLock lock(mutex_); |
83 return email_; | 83 return email_; |
84 } | 84 } |
85 | 85 |
86 static void MakeSigninsTable(sqlite3* const dbhandle) { | 86 static void MakeSigninsTable(sqlite3* const dbhandle) { |
87 // Multiple email addresses can map to the same Google Account. This table | 87 // Multiple email addresses can map to the same Google Account. This table |
88 // keeps a map of sign-in email addresses to primary Google Account email | 88 // keeps a map of sign-in email addresses to primary Google Account email |
89 // addresses. | 89 // addresses. |
90 ExecOrDie(dbhandle, | 90 ExecOrDie(dbhandle, |
91 "CREATE TABLE signins" | 91 "CREATE TABLE signins" |
92 " (signin, primary_email, " | 92 " (signin, primary_email, " |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 if (salt.empty() || hash == kInvalidHash) | 414 if (salt.empty() || hash == kInvalidHash) |
415 return false; | 415 return false; |
416 MD5Calculator md5; | 416 MD5Calculator md5; |
417 md5.AddData(salt.data(), salt.size()); | 417 md5.AddData(salt.data(), salt.size()); |
418 md5.AddData(password.data(), password.size()); | 418 md5.AddData(password.data(), password.size()); |
419 return hash == GetHashFromDigest(md5.GetDigest()); | 419 return hash == GetHashFromDigest(md5.GetDigest()); |
420 } | 420 } |
421 | 421 |
422 void UserSettings::SwitchUser(const string& username) { | 422 void UserSettings::SwitchUser(const string& username) { |
423 { | 423 { |
424 AutoLock lock(mutex_); | 424 base::AutoLock lock(mutex_); |
425 email_ = username; | 425 email_ = username; |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 string UserSettings::GetClientId() { | 429 string UserSettings::GetClientId() { |
430 ScopedDBHandle dbhandle(this); | 430 ScopedDBHandle dbhandle(this); |
431 SQLStatement statement; | 431 SQLStatement statement; |
432 statement.prepare(dbhandle.get(), "SELECT id FROM client_id"); | 432 statement.prepare(dbhandle.get(), "SELECT id FROM client_id"); |
433 int query_result = statement.step(); | 433 int query_result = statement.step(); |
434 string client_id; | 434 string client_id; |
(...skipping 13 matching lines...) Expand all Loading... |
448 query.prepare(dbhandle.get(), "SELECT email FROM cookies"); | 448 query.prepare(dbhandle.get(), "SELECT email FROM cookies"); |
449 if (SQLITE_ROW == query.step()) { | 449 if (SQLITE_ROW == query.step()) { |
450 *username = query.column_string(0); | 450 *username = query.column_string(0); |
451 return true; | 451 return true; |
452 } else { | 452 } else { |
453 return false; | 453 return false; |
454 } | 454 } |
455 } | 455 } |
456 | 456 |
457 } // namespace browser_sync | 457 } // namespace browser_sync |
OLD | NEW |