Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_IMPL _H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_IMPL _H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback_forward.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "chrome/browser/chromeos/extensions/public_session_permission_helper.h" | |
| 15 #include "chrome/browser/extensions/extension_install_prompt.h" | |
| 16 #include "extensions/common/permissions/api_permission.h" | |
| 17 #include "extensions/common/permissions/api_permission_set.h" | |
| 18 | |
| 19 namespace extensions { | |
| 20 namespace permission_helper { | |
| 21 | |
| 22 struct RequestCallback { | |
|
Devlin
2017/01/23 22:59:48
Can this be internal to the class (i.e., a private
Ivan Šandrk
2017/01/24 19:57:22
Done.
| |
| 23 RequestCallback(const base::Closure& success_callback, | |
| 24 const base::Closure& failure_callback, | |
| 25 const PermissionHelperSet& permission_list); | |
| 26 RequestCallback(const RequestCallback& other); | |
| 27 ~RequestCallback(); | |
| 28 base::Closure success_callback; | |
| 29 base::Closure failure_callback; | |
| 30 PermissionHelperSet permission_list; | |
| 31 }; | |
| 32 using RequestCallbackList = std::vector<RequestCallback>; | |
| 33 | |
| 34 class PublicSessionPermissionHelperImpl { | |
|
Devlin
2017/01/23 22:59:48
It looks to me like this class can probably be com
Ivan Šandrk
2017/01/24 19:57:22
In one of the earlier iterations I had it all in o
Devlin
2017/01/25 16:00:31
To elaborate a little here.
Currently, PublicSess
Ivan Šandrk
2017/01/26 18:53:22
Ah I see, excellent idea! Done!
| |
| 35 public: | |
| 36 PublicSessionPermissionHelperImpl(); | |
| 37 PublicSessionPermissionHelperImpl(PublicSessionPermissionHelperImpl&& other); | |
| 38 ~PublicSessionPermissionHelperImpl(); | |
| 39 | |
| 40 // Sets up the prompt asking the user for additional permission(s), handles | |
| 41 // the result, caches it, and then runs either success_callback or | |
| 42 // failure_callback depending on all permissions being allowed. | |
| 43 // Supports handling multiple requests for the same permission(s). Only the | |
| 44 // first request causes the prompt to be shown, subsequent ones are just | |
| 45 // enqueued to be called when the permission(s) is resolved. | |
| 46 // Caller must ensure that web_contents is valid. Must be called on UI thread. | |
| 47 // If finer resolving is needed, pass the same function in both callbacks and | |
| 48 // check the individual permissions by calling GetUserChoice inside your | |
| 49 // function. | |
| 50 void HandlePermissionRequest(const Extension* extension, | |
| 51 PermissionHelperSet requested_permissions, | |
| 52 content::WebContents* web_contents, | |
| 53 const base::Closure& success_callback, | |
| 54 const base::Closure& failure_callback); | |
| 55 | |
| 56 | |
| 57 PermissionState GetUserChoice(APIPermission::ID permission_id); | |
| 58 | |
| 59 private: | |
| 60 void SetUserChoice(APIPermission::ID permission_id, PermissionState value); | |
|
Devlin
2017/01/23 22:59:48
Never defined
Ivan Šandrk
2017/01/24 19:57:22
Right, had a cleanup and missed this. Thanks!
| |
| 61 | |
| 62 void ResolvePermissionPrompt(const Extension* extension, | |
| 63 PermissionIDSet unprompted_permissions, | |
| 64 ExtensionInstallPrompt::Result prompt_result); | |
| 65 | |
| 66 std::map<APIPermission::ID, std::unique_ptr<ExtensionInstallPrompt>> | |
| 67 prompt_map_; | |
| 68 PermissionIDSet prompted_permission_set_; | |
| 69 PermissionIDSet allowed_permission_set_; | |
| 70 PermissionIDSet denied_permission_set_; | |
| 71 RequestCallbackList callbacks_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(PublicSessionPermissionHelperImpl); | |
| 74 }; | |
| 75 | |
| 76 } // namespace permission_helper | |
| 77 } // namespace extensions | |
| 78 | |
| 79 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_I MPL_H_ | |
| OLD | NEW |