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.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_
6 #define COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "components/proximity_auth/cryptauth/cryptauth_client.h"
10 #include "components/proximity_auth/logging/log_buffer.h"
11 #include "components/proximity_auth/webui/proximity_auth_ui_delegate.h"
12 #include "content/public/browser/web_ui_message_handler.h"
18 namespace proximity_auth
{
20 class ProximityAuthUIDelegate
;
22 // Handles messages from the chrome://proximity-auth page.
23 class ProximityAuthWebUIHandler
: public content::WebUIMessageHandler
,
24 public LogBuffer::Observer
{
26 // |delegate| is not owned and must outlive this instance.
27 explicit ProximityAuthWebUIHandler(ProximityAuthUIDelegate
* delegate
);
28 ~ProximityAuthWebUIHandler() override
;
30 // content::WebUIMessageHandler:
31 void RegisterMessages() override
;
34 // LogBuffer::Observer:
35 void OnLogMessageAdded(const LogBuffer::LogMessage
& log_message
) override
;
36 void OnLogBufferCleared() override
;
38 // Message handler callbacks.
39 void GetLogMessages(const base::ListValue
* args
);
40 void ClearLogBuffer(const base::ListValue
* args
);
41 void FindEligibleUnlockDevices(const base::ListValue
* args
);
43 // Called when a CryptAuth request fails.
44 void OnCryptAuthClientError(const std::string
& error_message
);
46 // Called when the findEligibleUnlockDevices request succeeds.
47 void OnFoundEligibleUnlockDevices(
48 const cryptauth::FindEligibleUnlockDevicesResponse
& response
);
50 // The delegate used to fetch dependencies. Must outlive this instance.
51 ProximityAuthUIDelegate
* delegate_
;
53 // Creates CryptAuth client instances to make API calls.
54 scoped_ptr
<CryptAuthClientFactory
> cryptauth_client_factory_
;
56 // We only support one concurrent API call.
57 scoped_ptr
<CryptAuthClient
> cryptauth_client_
;
59 base::WeakPtrFactory
<ProximityAuthWebUIHandler
> weak_ptr_factory_
;
61 DISALLOW_COPY_AND_ASSIGN(ProximityAuthWebUIHandler
);
64 } // namespace proximity_auth
66 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_