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

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: Rebased to master Created 4 years, 9 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 "base/memory/weak_ptr.h"
12 #include "mojo/services/files/interfaces/files.mojom.h"
13 #include "services/authentication/authentication_impl_db.mojom.h"
14 #include "services/authentication/credentials_impl_db.mojom.h"
15
16 namespace authentication {
17
18 // Implementation of user account management service on systems like FNL. This
19 // uses native mojo files service as the underlying mechanism to store user
20 // credentials and supports operations such as to add a new user account, update
21 // existing user credentials and fetching current credentials for a given user.
22 class AccountsDbManager {
23 public:
24 // Constructor that takes a directory handle to create or open existing auth
25 // and credentials db files. It also initializes the in-memory cache with the
26 // file contents from the disk.
27 AccountsDbManager(const mojo::files::DirectoryPtr directory);
28 ~AccountsDbManager();
29 base::WeakPtr<AccountsDbManager> GetWeakPtr();
qsr 2016/03/04 15:06:45 This still seems kind of weird. Now the callers us
ukode 2016/03/11 22:48:52 Acknowledged. Removed the weak ptr and exposed a n
30 // Fetches auth credentials for a given user account.
31 authentication::CredentialsPtr GetCredentials(const mojo::String& username);
32 // Returns a list of all users registered on the device.
33 mojo::Array<mojo::String> GetAllUsers();
34 // Updates or adds new auth credentials for a given user account.
35 void UpdateCredentials(const mojo::String& username,
36 const authentication::CredentialsPtr creds);
37 // Returns previously used account name for the given application or null if
38 // not found.
39 mojo::String GetAuthorizedUserForApp(mojo::String app_url);
40 // Updates the grants database for the given application and username.
41 void UpdateAuthorization(mojo::String app_url, mojo::String username);
42
43 private:
44 // DB Init Options for tracking the init state of in-memory contents.
45 enum DBInitOptions {
46 // Default init state.
47 START_INIT = 0x01,
48 // Creds db in-memory content is populated successfully.
49 CREDS_DB_INIT_SUCCESS = 0x02,
50 // Auth db in-memory content is populated successfully.
51 AUTH_DB_INIT_SUCCESS = 0x04
52 };
53
54 // Populates contents with existing user credentials.
55 void Initialize();
56 // Reads from credentials file and populates in-memory contents cache.
57 void OnCredFileReadResponse(const mojo::files::Error error,
qsr 2016/03/04 15:06:45 Do not use abbreviation, here and everywhere.
ukode 2016/03/11 22:48:52 Done.
58 const mojo::Array<uint8_t> bytes_read);
59 // Parses response from credentials file write operation
60 void OnCredFileWriteResponse(const mojo::files::Error error,
61 const uint32_t num_bytes_written);
62 // Reads from auth file and populates in-memory grants cache.
63 void OnAuthFileReadResponse(const mojo::files::Error error,
64 const mojo::Array<uint8_t> bytes_read);
65 // Parses response from auth file write operation
66 void OnAuthFileWriteResponse(const mojo::files::Error error,
67 const uint32_t num_bytes_written);
68 // Waits for the credsdb file handle to finish the blocking read operation
69 // as part of initialization, before proceeding further.
70 void ensureCredsDbInit();
71 // Waits for the authdb file handle to finish the blocking read operation
72 // as part of initialization, before proceeding further.
73 void ensureAuthDbInit();
74
75 // File pointer to the stored account credentials db file.
76 mojo::files::FilePtr creds_db_file_;
77 // File pointer to the list of authorized modules.
78 mojo::files::FilePtr auth_db_file_;
79 // In-memory store for credential data for all users.
80 authentication::CredentialStore creds_store_;
81 // In-memory store for list of authorized apps.
82 authentication::Db auth_grants_;
83 // Flag to track in-memory contents init state.
84 unsigned char db_init_option_ = START_INIT;
85 base::WeakPtrFactory<AccountsDbManager> weak_ptr_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(AccountsDbManager);
88 };
89
90 } // namespace authentication
91
92 #endif // SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698