Index: services/authentication/accounts_db_manager.h |
diff --git a/services/authentication/accounts_db_manager.h b/services/authentication/accounts_db_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d154387c3eed6e31dbb2451b595cda93370a6250 |
--- /dev/null |
+++ b/services/authentication/accounts_db_manager.h |
@@ -0,0 +1,96 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_ |
+#define SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_ |
+ |
+#include <type_traits> |
+ |
+#include "base/macros.h" |
+#include "mojo/services/files/interfaces/files.mojom.h" |
+ |
+namespace authentication { |
+ |
+// TODO(ukode): Stuff copied from mojo/public/cpp/bindings/lib/template_util.h. |
+typedef char YesType; |
+ |
+struct NoType { |
+ YesType dummy[2]; |
+}; |
+ |
+template <typename T> |
+struct IsMoveOnlyType { |
+ template <typename U> |
+ static YesType Test(const typename U::MoveOnlyTypeForCPP03*); |
+ |
+ template <typename U> |
+ static NoType Test(...); |
+ |
+ static const bool value = |
+ sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value; |
+}; |
+ |
+template <typename T> |
+typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) { |
+ return t; |
+} |
+ |
+template <typename T> |
+typename std::enable_if<IsMoveOnlyType<T>::value, T>::type Forward(T& t) { |
+ return t.Pass(); |
+} |
+// TODO(ukode): (End of stuff copied from template_util.h.) |
+ |
+template <typename T1> |
+mojo::Callback<void(T1)> Capture(T1* t1) { |
+ return [t1](T1 got_t1) { *t1 = Forward(got_t1); }; |
+} |
+ |
+template <typename T1, typename T2> |
+mojo::Callback<void(T1, T2)> Capture(T1* t1, T2* t2) { |
+ return [t1, t2](T1 got_t1, T2 got_t2) { |
+ *t1 = Forward(got_t1); |
+ *t2 = Forward(got_t2); |
+ }; |
+} |
+ |
+// Implementation of user account management service on systems like FNL. This |
+// uses native mojo files service as the underlying mechanism to store user |
+// credentials and supports operations such as to add a new user account, update |
+// existing user credentials and fetching current credentials for a given user. |
+class AccountsDbManager { |
+ public: |
+ AccountsDbManager(); |
+ explicit AccountsDbManager(mojo::files::DirectoryPtr& directory); |
qsr
2016/01/13 12:01:00
const mojo::files::DirectoryPtr& ? or use a pointe
ukode
2016/02/09 00:20:18
Done.
|
+ ~AccountsDbManager(); |
+ // Updates or adds new auth credentials for a given user account. |
+ bool UpdateAccount(const mojo::String& username, |
+ const mojo::String& account_data); |
+ // Fetches auth credentials for a given user account. |
+ void GetAccountDataForUser(const mojo::String& username, |
+ mojo::String& user_data); |
qsr
2016/01/13 12:01:00
You should use a pointer for out values.
ukode
2016/02/09 00:20:18
Done.
|
+ // Fetches all user account credentials. |
+ mojo::Array<uint8_t> FetchAllAccounts(); |
+ |
+ private: |
+ // Generates new contents of the accounts database during an update operation. |
+ // Performs one of the two operations: |
+ // 1. If the user already exists, updates the existing record in database. |
+ // 2. If its a new user, adds a new record to the existing database content. |
+ void GetUpdatedDbContents(const mojo::String& username, |
+ const mojo::String& new_account_data, |
+ bool user_exists, |
+ mojo::String& new_db_contents); |
qsr
2016/01/13 12:01:00
Same for out parameters.
ukode
2016/02/09 00:20:18
Done.
|
+ |
+ // File pointer to the stored accounts db file. |
+ mojo::files::FilePtr file_; |
+ // Stores the cached account data for all users. |
+ std::string contents_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AccountsDbManager); |
+}; |
+ |
+} // namespace authentication |
+ |
+#endif // SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_ |