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