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

Side by Side 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: Addressed review comments Created 4 years, 11 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_
6 #define SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_
7
8 #include <type_traits>
9
10 #include "base/macros.h"
11 #include "mojo/services/files/interfaces/files.mojom.h"
12
13 namespace authentication {
14
15 // TODO(ukode): Stuff copied from mojo/public/cpp/bindings/lib/template_util.h.
16 typedef char YesType;
17
18 struct NoType {
19 YesType dummy[2];
20 };
21
22 template <typename T>
23 struct IsMoveOnlyType {
24 template <typename U>
25 static YesType Test(const typename U::MoveOnlyTypeForCPP03*);
26
27 template <typename U>
28 static NoType Test(...);
29
30 static const bool value =
31 sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value;
32 };
33
34 template <typename T>
35 typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) {
36 return t;
37 }
38
39 template <typename T>
40 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type Forward(T& t) {
41 return t.Pass();
42 }
43 // TODO(ukode): (End of stuff copied from template_util.h.)
44
45 template <typename T1>
46 mojo::Callback<void(T1)> Capture(T1* t1) {
47 return [t1](T1 got_t1) { *t1 = Forward(got_t1); };
48 }
49
50 template <typename T1, typename T2>
51 mojo::Callback<void(T1, T2)> Capture(T1* t1, T2* t2) {
52 return [t1, t2](T1 got_t1, T2 got_t2) {
53 *t1 = Forward(got_t1);
54 *t2 = Forward(got_t2);
55 };
56 }
57
58 // Implementation of user account management service on systems like FNL. This
59 // uses native mojo files service as the underlying mechanism to store user
60 // credentials and supports operations such as to add a new user account, update
61 // existing user credentials and fetching current credentials for a given user.
62 class AccountsDbManager {
63 public:
64 AccountsDbManager();
65 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.
66 ~AccountsDbManager();
67 // Updates or adds new auth credentials for a given user account.
68 bool UpdateAccount(const mojo::String& username,
69 const mojo::String& account_data);
70 // Fetches auth credentials for a given user account.
71 void GetAccountDataForUser(const mojo::String& username,
72 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.
73 // Fetches all user account credentials.
74 mojo::Array<uint8_t> FetchAllAccounts();
75
76 private:
77 // Generates new contents of the accounts database during an update operation.
78 // Performs one of the two operations:
79 // 1. If the user already exists, updates the existing record in database.
80 // 2. If its a new user, adds a new record to the existing database content.
81 void GetUpdatedDbContents(const mojo::String& username,
82 const mojo::String& new_account_data,
83 bool user_exists,
84 mojo::String& new_db_contents);
qsr 2016/01/13 12:01:00 Same for out parameters.
ukode 2016/02/09 00:20:18 Done.
85
86 // File pointer to the stored accounts db file.
87 mojo::files::FilePtr file_;
88 // Stores the cached account data for all users.
89 std::string contents_;
90
91 DISALLOW_COPY_AND_ASSIGN(AccountsDbManager);
92 };
93
94 } // namespace authentication
95
96 #endif // SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698