Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: services/authentication/accounts_db_manager.h

Issue 1466733002: Google OAuth Device Flow support for FNL (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Updated comments for authentication.mojom Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7fcf27836bf7770b91fff9aa5504380c5c8d15d8
--- /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::FilesPtr files);
+ ~AccountsDbManager();
+ // Updates account credentials for a given user.
+ bool UpdateAccount(const mojo::String& username,
+ const mojo::String& account_data);
+ // Fetches account credentials for a given user.
+ void GetAccountDataForUser(const mojo::String& username,
+ mojo::String& user_data);
+ // Fetches all user 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,
+ const bool user_exists,
+ mojo::String& new_db_contents);
+
+ // Directory pointer to the stored accounts db file.
+ mojo::files::DirectoryPtr directory_;
+ // Stores the cached account data in between account operations.
+ std::string contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(AccountsDbManager);
+};
+
+} // namespace authentication
+
+#endif // SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698