Chromium Code Reviews| Index: chrome/browser/chromeos/certificate_provider/pin_dialog_manager.h |
| diff --git a/chrome/browser/chromeos/certificate_provider/pin_dialog_manager.h b/chrome/browser/chromeos/certificate_provider/pin_dialog_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..91a1f7ea0e491c71d417d08ea020e67697191003 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/certificate_provider/pin_dialog_manager.h |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2016 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 CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/chromeos/ui/request_pin_view.h" |
| + |
| +namespace chromeos { |
| + |
| +enum RequestPinResponse { SUCCESS, INVALID_ID, OTHER_FLOW_IN_PROGRESS }; |
| + |
| +// Manages the state of the dialog that requests the PIN from user. |
| +class PinDialogManager { |
| + public: |
| + PinDialogManager(); |
| + virtual ~PinDialogManager(); |
| + |
| + // The user provided input to dialog. |closed| tells whether the dialog was |
| + // closed by the user without providing any input. |
| + void OnPinDialogInput(const std::string& extension_id, const bool closed); |
| + |
| + // 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.
|
| + // dialog while the last input is still processing at extension side. |value| |
| + // is not used, but checked that it's empty. |
| + void OnFlowInterrupted(const base::string16& value); |
| + |
| + // Returns whether the last PIN dialog from this extension was closed by the |
| + // user. |
| + bool LastPinDialogClosed(const std::string& extension_id); |
| + |
| + // Updates the existing dialog with new error message. Uses |callback| with |
| + // empty string when user closes the dialog. Returns whether the provided |
| + // |extension_id| matches the extension owning the active dialog. |
| + bool UpdatePinDialog(const std::string& extension_id, |
| + RequestPinErrorType error_type, |
| + const bool accept_input, |
| + const RequestPinView::RequestPinCallback& callback); |
| + |
| + // Creates a new RequestPinView object and displays it in a dialog or reuses |
| + // the old dialog if active one exists just updating the parameters. The |
| + // |extension_id| and |extension_name| should be the ID and the name of |
| + // the extension requesting the dialog. If a dialog is present already and |
| + // was initialized by another extension, the method returns an error. |
| + // |sign_request_id| should be the ID given by Chrome when the extension was |
| + // asked to sign the data. It should be a valid, not expired ID at the time |
| + // the extension is requesting PIN the first time. |code_type| is the type |
| + // of input requested: either "PIN" or "PUK". |error_type| is the error |
| + // template to be displayed inside the dialog if not NONE. |attempts_left| |
| + // should be the number of attempts the user has to try the code. It is |
| + // informational only, and enforced on Chrome side only in case it's zero. In |
| + // that case the textfield is disabled and the user can't provide any input to |
| + // extension. If nullptr the textfield from the dialog is enabled but no |
| + // information about the attepts left is not given to the user. |callback| is |
| + // used to notify about the user input in the text_field from the dialog. |
| + // 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.
|
| + // the specific error is returned. |
| + RequestPinResponse ShowPinDialog( |
| + const std::string& extension_id, |
| + const std::string& extension_name, |
| + const long long sign_request_id, |
| + RequestPinCodeType code_type, |
| + RequestPinErrorType error_type, |
| + std::unique_ptr<int> attempts_left, |
| + const RequestPinView::RequestPinCallback& callback); |
| + |
| + // 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.
|
| + // The active dialog is closed if the |extension_id| matches the |
| + // |active_dialog_extension_id_|. Returns whether the dialog was closed. |
| + bool CloseDialog(const std::string& extension_id); |
| + |
| + // Stores internally the |signRequestId| along with current timestamp. Also |
| + // cleans up the storage from expired IDs. In unlikely case that the ID |
| + // exists in the storage, returns false. Otherwise returns true. |
| + bool AddSignRequestId(const uint64_t signRequestId); |
| + |
| + // Resets the manager data related to the extension. |
| + void ExtensionUnloaded(const std::string& extension_id); |
| + |
| + RequestPinView* active_view_for_testing() { return active_pin_dialog_; } |
| + views::Widget* active_window_for_testing() { return active_window_; } |
| + |
| + private: |
| + // Cleans the map of sign request ids, removing the ones that have expired. |
| + void RemoveExpiredSignRequests(timeval* tv); |
| + |
| + // State about the last response from user to the requestPin from extension. |
| + 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.
|
| + |
| + // The map with sign request ids issued by Chrome as key and the time when the |
| + // id was generated as value. |
| + 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.
|
| + |
| + // There can be only one active dialog to request PIN from this extension. |
| + // Keeps the ownership. |
| + 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
|
| + std::string active_dialog_extension_id_; |
| + views::Widget* active_window_ = nullptr; |
| + |
| + base::WeakPtrFactory<PinDialogManager> weak_factory_; |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ |