OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "chrome/browser/chromeos/ui/request_pin_view.h" | |
13 | |
14 namespace chromeos { | |
15 | |
16 enum RequestPinResponse { SUCCESS, INVALID_ID, OTHER_FLOW_IN_PROGRESS }; | |
17 | |
18 // Manages the state of the dialog that requests the PIN from user. | |
19 class PinDialogManager { | |
20 public: | |
21 PinDialogManager(); | |
22 virtual ~PinDialogManager(); | |
23 | |
24 // The user provided input to dialog. |closed| tells whether the dialog was | |
25 // closed by the user without providing any input. | |
26 void OnPinDialogInput(const std::string& extension_id, const bool closed); | |
27 | |
28 // This callback function is called by the view when user closes the PIN | |
stevenjb
2016/08/11 01:58:55
s/This callback function is called/Called/
igorcov1
2016/08/11 16:15:23
Done.
| |
29 // dialog while the last input is still processing at extension side. |value| | |
30 // is not used, but checked that it's empty. | |
31 void OnFlowInterrupted(const base::string16& value); | |
32 | |
33 // Returns whether the last PIN dialog from this extension was closed by the | |
34 // user. | |
35 bool LastPinDialogClosed(const std::string& extension_id); | |
36 | |
37 // Updates the existing dialog with new error message. Uses |callback| with | |
38 // empty string when user closes the dialog. Returns whether the provided | |
39 // |extension_id| matches the extension owning the active dialog. | |
40 bool UpdatePinDialog(const std::string& extension_id, | |
41 RequestPinErrorType error_type, | |
42 const bool accept_input, | |
43 const RequestPinView::RequestPinCallback& callback); | |
44 | |
45 // Creates a new RequestPinView object and displays it in a dialog or reuses | |
46 // the old dialog if active one exists just updating the parameters. The | |
47 // |extension_id| and |extension_name| should be the ID and the name of | |
48 // the extension requesting the dialog. If a dialog is present already and | |
49 // was initialized by another extension, the method returns an error. | |
50 // |sign_request_id| should be the ID given by Chrome when the extension was | |
51 // asked to sign the data. It should be a valid, not expired ID at the time | |
52 // the extension is requesting PIN the first time. |code_type| is the type | |
53 // of input requested: either "PIN" or "PUK". |error_type| is the error | |
54 // template to be displayed inside the dialog if not NONE. |attempts_left| | |
55 // should be the number of attempts the user has to try the code. It is | |
56 // informational only, and enforced on Chrome side only in case it's zero. In | |
57 // that case the textfield is disabled and the user can't provide any input to | |
58 // extension. If nullptr the textfield from the dialog is enabled but no | |
59 // information about the attepts left is not given to the user. |callback| is | |
60 // used to notify about the user input in the text_field from the dialog. | |
61 // Returns SUCCESS if the dialog is displayed and extension owns it. Otherwise | |
stevenjb
2016/08/11 01:58:55
Can you break this up to make it more readable, e.
igorcov1
2016/08/11 16:15:23
Done.
| |
62 // the specific error is returned. | |
63 RequestPinResponse ShowPinDialog( | |
64 const std::string& extension_id, | |
65 const std::string& extension_name, | |
66 const long long sign_request_id, | |
67 RequestPinCodeType code_type, | |
68 RequestPinErrorType error_type, | |
69 std::unique_ptr<int> attempts_left, | |
70 const RequestPinView::RequestPinCallback& callback); | |
71 | |
72 // This function is called when extension calls the stopPinRequest method. | |
stevenjb
2016/08/11 01:58:55
s/This function is called when/Called when/
igorcov1
2016/08/11 16:15:23
Done.
| |
73 // The active dialog is closed if the |extension_id| matches the | |
74 // |active_dialog_extension_id_|. Returns whether the dialog was closed. | |
75 bool CloseDialog(const std::string& extension_id); | |
76 | |
77 // Stores internally the |signRequestId| along with current timestamp. Also | |
78 // cleans up the storage from expired IDs. In unlikely case that the ID | |
79 // exists in the storage, returns false. Otherwise returns true. | |
80 bool AddSignRequestId(const uint64_t signRequestId); | |
81 | |
82 // Resets the manager data related to the extension. | |
83 void ExtensionUnloaded(const std::string& extension_id); | |
84 | |
85 RequestPinView* active_view_for_testing() { return active_pin_dialog_; } | |
86 views::Widget* active_window_for_testing() { return active_window_; } | |
87 | |
88 private: | |
89 // Cleans the map of sign request ids, removing the ones that have expired. | |
90 void RemoveExpiredSignRequests(timeval* tv); | |
91 | |
92 // State about the last response from user to the requestPin from extension. | |
93 std::map<std::string, bool> last_rejected_; | |
stevenjb
2016/08/11 01:58:55
last_response_rejected_
igorcov1
2016/08/11 16:15:23
Done.
| |
94 | |
95 // The map with sign request ids issued by Chrome as key and the time when the | |
96 // id was generated as value. | |
97 std::map<uint64_t, uint64_t> sign_request_ids_; | |
stevenjb
2016/08/11 01:58:55
'sign_request_ids_' implies this is a set of ids.
igorcov1
2016/08/11 16:15:23
Done.
| |
98 | |
99 // There can be only one active dialog to request PIN from this extension. | |
100 // Keeps the ownership. | |
101 chromeos::RequestPinView* active_pin_dialog_ = nullptr; | |
stevenjb
2016/08/11 01:58:55
Can we use a unique_ptr here? The code as written
igorcov1
2016/08/11 16:15:23
I'm sorry, the comment is wrong here. It is manage
| |
102 std::string active_dialog_extension_id_; | |
103 views::Widget* active_window_ = nullptr; | |
104 | |
105 base::WeakPtrFactory<PinDialogManager> weak_factory_; | |
106 }; | |
107 | |
108 } // namespace chromeos | |
109 | |
110 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ | |
OLD | NEW |