Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: content/browser/devtools/protocol/io_handler.cc

Issue 2500093002: [DevTools] Move IO and Tracing to new generator. (Closed)
Patch Set: roll Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/devtools/protocol/io_handler.h" 5 #include "content/browser/devtools/protocol/io_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file.h" 11 #include "base/files/file.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/memory/ref_counted_delete_on_message_loop.h" 13 #include "base/memory/ref_counted_delete_on_message_loop.h"
14 #include "base/memory/ref_counted_memory.h" 14 #include "base/memory/ref_counted_memory.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "content/browser/devtools/devtools_io_context.h" 16 #include "content/browser/devtools/devtools_io_context.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 18
19 namespace content { 19 namespace content {
20 namespace devtools { 20 namespace protocol {
21 namespace io {
22
23 using Response = DevToolsProtocolClient::Response;
24 21
25 IOHandler::IOHandler(DevToolsIOContext* io_context) 22 IOHandler::IOHandler(DevToolsIOContext* io_context)
26 : io_context_(io_context) 23 : io_context_(io_context)
27 , weak_factory_(this) {} 24 , weak_factory_(this) {}
28 25
29 IOHandler::~IOHandler() {} 26 IOHandler::~IOHandler() {}
30 27
31 void IOHandler::SetClient(std::unique_ptr<Client> client) { 28 void IOHandler::Wire(UberDispatcher* dispatcher) {
32 client_.swap(client); 29 frontend_.reset(new IO::Frontend(dispatcher->channel()));
30 IO::Dispatcher::wire(dispatcher, this);
33 } 31 }
34 32
35 Response IOHandler::Read(DevToolsCommandId command_id, 33 Response IOHandler::Disable() {
36 const std::string& handle, const int* offset, const int* max_size) { 34 return Response::OK();
35 }
36
37 void IOHandler::Read(
38 const std::string& handle,
39 Maybe<int> offset,
40 Maybe<int> max_size,
41 std::unique_ptr<ReadCallback> callback) {
37 static const size_t kDefaultChunkSize = 10 * 1024 * 1024; 42 static const size_t kDefaultChunkSize = 10 * 1024 * 1024;
38 43
39 scoped_refptr<DevToolsIOContext::Stream> stream = 44 scoped_refptr<DevToolsIOContext::Stream> stream =
40 io_context_->GetByHandle(handle); 45 io_context_->GetByHandle(handle);
41 if (!stream) 46 if (!stream) {
42 return Response::InvalidParams("Invalid stream handle"); 47 callback->sendFailure(Response::InvalidParams("Invalid stream handle"));
43 stream->Read(offset ? *offset : -1, 48 return;
44 max_size && *max_size ? *max_size : kDefaultChunkSize, 49 }
50 stream->Read(offset.fromMaybe(-1),
51 max_size.fromMaybe(kDefaultChunkSize),
45 base::Bind(&IOHandler::ReadComplete, 52 base::Bind(&IOHandler::ReadComplete,
46 weak_factory_.GetWeakPtr(), command_id)); 53 weak_factory_.GetWeakPtr(),
47 return Response::OK(); 54 base::Passed(std::move(callback))));
48 } 55 }
49 56
50 void IOHandler::ReadComplete(DevToolsCommandId command_id, 57 void IOHandler::ReadComplete(std::unique_ptr<ReadCallback> callback,
51 const scoped_refptr<base::RefCountedString>& data, 58 const scoped_refptr<base::RefCountedString>& data,
52 int status) { 59 int status) {
53 if (status == DevToolsIOContext::Stream::StatusFailure) { 60 if (status == DevToolsIOContext::Stream::StatusFailure) {
54 client_->SendError(command_id, Response::ServerError("Read failed")); 61 callback->sendFailure(Response::Error("Read failed"));
55 return; 62 return;
56 } 63 }
57 bool eof = status == DevToolsIOContext::Stream::StatusEOF; 64 bool eof = status == DevToolsIOContext::Stream::StatusEOF;
58 client_->SendReadResponse(command_id, 65 callback->sendSuccess(data->data(), eof);
59 ReadResponse::Create()->set_data(data->data())->set_eof(eof));
60 } 66 }
61 67
62 Response IOHandler::Close(const std::string& handle) { 68 Response IOHandler::Close(const std::string& handle) {
63 return io_context_->Close(handle) ? Response::OK() 69 return io_context_->Close(handle) ? Response::OK()
64 : Response::InvalidParams("Invalid stream handle"); 70 : Response::InvalidParams("Invalid stream handle");
65 } 71 }
66 72
67 } // namespace io 73 } // namespace protocol
68 } // namespace devtools
69 } // namespace content 74 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/io_handler.h ('k') | content/browser/devtools/protocol/tracing_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698