Joseph Arhar | 9c1334b | 2017-08-08 18:35:20 | [diff] [blame] | 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 REMOTING_HOST_FILE_TRANSFER_MESSAGE_HANDLER_H_ |
| 6 | #define REMOTING_HOST_FILE_TRANSFER_MESSAGE_HANDLER_H_ |
| 7 | |
Joseph Arhar | 10e5edd | 2017-08-28 22:12:50 | [diff] [blame] | 8 | #include <cstdint> |
| 9 | #include <memory> |
| 10 | #include <string> |
| 11 | |
Joseph Arhar | 91537d5 | 2017-08-14 22:31:10 | [diff] [blame] | 12 | #include "remoting/host/file_proxy_wrapper.h" |
Joseph Arhar | 10e5edd | 2017-08-28 22:12:50 | [diff] [blame] | 13 | #include "remoting/proto/file_transfer.pb.h" |
Joseph Arhar | 9c1334b | 2017-08-08 18:35:20 | [diff] [blame] | 14 | #include "remoting/protocol/named_message_pipe_handler.h" |
| 15 | |
| 16 | namespace remoting { |
| 17 | |
Joseph Arhar | 91537d5 | 2017-08-14 22:31:10 | [diff] [blame] | 18 | constexpr char kFileTransferDataChannelPrefix[] = "filetransfer-"; |
| 19 | |
Joseph Arhar | 9c1334b | 2017-08-08 18:35:20 | [diff] [blame] | 20 | class FileTransferMessageHandler : public protocol::NamedMessagePipeHandler { |
| 21 | public: |
| 22 | FileTransferMessageHandler(const std::string& name, |
Joseph Arhar | 91537d5 | 2017-08-14 22:31:10 | [diff] [blame] | 23 | std::unique_ptr<protocol::MessagePipe> pipe, |
| 24 | std::unique_ptr<FileProxyWrapper> file_proxy); |
Joseph Arhar | 9c1334b | 2017-08-08 18:35:20 | [diff] [blame] | 25 | ~FileTransferMessageHandler() override; |
| 26 | |
| 27 | // protocol::NamedMessagePipeHandler implementation. |
| 28 | void OnConnected() override; |
| 29 | void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message) override; |
| 30 | void OnDisconnecting() override; |
Joseph Arhar | 10e5edd | 2017-08-28 22:12:50 | [diff] [blame] | 31 | |
| 32 | private: |
| 33 | void StatusCallback( |
| 34 | FileProxyWrapper::State state, |
| 35 | base::Optional<protocol::FileTransferResponse_ErrorCode> error); |
| 36 | void SendToFileProxy(std::unique_ptr<CompoundBuffer> buffer); |
| 37 | void ParseNewRequest(std::unique_ptr<CompoundBuffer> buffer); |
| 38 | void CancelAndSendError(const std::string& error); |
| 39 | |
| 40 | std::unique_ptr<FileProxyWrapper> file_proxy_wrapper_; |
| 41 | std::unique_ptr<protocol::FileTransferRequest> request_; |
| 42 | uint64_t total_bytes_written_ = 0; |
Joseph Arhar | 9c1334b | 2017-08-08 18:35:20 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | } // namespace remoting |
| 46 | |
| 47 | #endif // REMOTING_HOST_FILE_TRANSFER_MESSAGE_HANDLER_H_ |