OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 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 file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_UTIL_USER_SETTINGS_H_ |
| 6 #define CHROME_BROWSER_SYNC_UTIL_USER_SETTINGS_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "chrome/browser/sync/util/pthread_helpers.h" |
| 13 #include "chrome/browser/sync/util/signin.h" |
| 14 #include "chrome/browser/sync/util/sync_types.h" |
| 15 |
| 16 extern "C" struct sqlite3; |
| 17 |
| 18 namespace browser_sync { |
| 19 |
| 20 class URLFactory; |
| 21 |
| 22 class UserSettings { |
| 23 public: |
| 24 // db_path is used for the main user settings. |
| 25 // passwords_file contains hashes of passwords. |
| 26 UserSettings(); |
| 27 ~UserSettings(); |
| 28 // Returns false (failure) if the db is a newer version. |
| 29 bool Init(const PathString& settings_path); |
| 30 void StoreHashedPassword(const std::string& email, |
| 31 const std::string& password); |
| 32 bool VerifyAgainstStoredHash(const std::string& email, |
| 33 const std::string& password); |
| 34 |
| 35 // Set the username. |
| 36 void SwitchUser(const std::string& email); |
| 37 |
| 38 // Saves the email address and the named service token for the given user. |
| 39 // Call this multiple times with the same email parameter to save |
| 40 // multiple service tokens. |
| 41 void SetAuthTokenForService(const std::string& email, |
| 42 const std::string& service_name, |
| 43 const std::string& long_lived_service_token); |
| 44 // Erases all saved service tokens. |
| 45 void ClearAllServiceTokens(); |
| 46 |
| 47 // Returns the user name whose credentials have been persisted. |
| 48 bool GetLastUser(std::string* username); |
| 49 |
| 50 // Returns the user name whose credentials have been persisted as well as |
| 51 // a service token for the named service |
| 52 bool GetLastUserAndServiceToken(const std::string& service_name, |
| 53 std::string* username, |
| 54 std::string* service_token); |
| 55 |
| 56 void RememberSigninType(const std::string& signin, SignIn signin_type); |
| 57 SignIn RecallSigninType(const std::string& signin, SignIn default_type); |
| 58 |
| 59 void RemoveAllGuestSettings(); |
| 60 |
| 61 void RemoveShare(const PathString& share_path); |
| 62 |
| 63 void StoreEmailForSignin(const std::string& signin, |
| 64 const std::string& primary_email); |
| 65 |
| 66 // Multiple email addresses can map to the same Google Account. This method |
| 67 // returns the primary Google Account email associated with |signin|, which |
| 68 // is used as both input and output. |
| 69 bool GetEmailForSignin(std::string* signin); |
| 70 |
| 71 |
| 72 std::string email() const; |
| 73 |
| 74 // Get a unique ID suitable for use as the client ID. This ID |
| 75 // has the lifetime of the user settings database. You may use this ID if |
| 76 // your operating environment does not provide its own unique client ID. |
| 77 std::string GetClientId(); |
| 78 |
| 79 protected: |
| 80 struct ScopedDBHandle { |
| 81 ScopedDBHandle(UserSettings* settings); |
| 82 inline sqlite3* get() const { return *handle_; } |
| 83 PThreadScopedLock<PThreadMutex> mutex_lock_; |
| 84 sqlite3** const handle_; |
| 85 }; |
| 86 |
| 87 friend struct ScopedDBHandle; |
| 88 friend class URLFactory; |
| 89 |
| 90 void MigrateOldVersionsAsNeeded(sqlite3* const handle, int current_version); |
| 91 |
| 92 private: |
| 93 std::string email_; |
| 94 mutable PThreadMutex mutex_; // protects email_ |
| 95 typedef PThreadScopedLock<PThreadMutex> ScopedLock; |
| 96 |
| 97 // We keep a single dbhandle. |
| 98 sqlite3* dbhandle_; |
| 99 PThreadMutex dbhandle_mutex_; |
| 100 |
| 101 // TODO(sync): Use in-memory cache for service auth tokens on posix. |
| 102 // Have someone competent in Windows switch it over to not use Sqlite in the |
| 103 // future. |
| 104 #ifndef OS_WINDOWS |
| 105 typedef std::map<std::string, std::string> ServiceTokenMap; |
| 106 ServiceTokenMap service_tokens_; |
| 107 #endif // OS_WINDOWS |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(UserSettings); |
| 110 }; |
| 111 |
| 112 } // namespace browser_sync |
| 113 |
| 114 #endif // CHROME_BROWSER_SYNC_UTIL_USER_SETTINGS_H_ |
OLD | NEW |