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

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

Issue 1307073002: DevTools: provide an option to return traces as streams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months 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
(Empty)
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.
4
5 #include "content/browser/devtools/protocol/io_handler.h"
6
7 #include <stdint.h>
8
9 #include "base/bind.h"
10 #include "base/files/file.h"
11 #include "base/files/file_util.h"
12 #include "base/memory/ref_counted_delete_on_message_loop.h"
13 #include "base/memory/ref_counted_memory.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "content/browser/devtools/devtools_io_context.h"
16 #include "content/public/browser/browser_thread.h"
17
18 namespace content {
19 namespace devtools {
20 namespace io {
21
22 using Response = DevToolsProtocolClient::Response;
23
24 IOHandler::IOHandler(DevToolsIOContext* io_context)
25 : io_context_(io_context)
26 , weak_factory_(this) {}
27
28 IOHandler::~IOHandler() {}
29
30 void IOHandler::SetClient(scoped_ptr<Client> client) {
31 client_.swap(client);
32 }
33
34 Response IOHandler::Read(DevToolsCommandId command_id, const std::string& id,
35 const int* offset, const int* max_size) {
36 static const size_t kDefaultChunkSize = 10 * 1024 * 1024;
37
38 scoped_refptr<DevToolsIOContext::Stream> stream = io_context_->GetById(id);
39 if (!stream)
40 return Response::InvalidParams("id");
41 stream->Read(offset ? *offset : -1,
42 max_size && *max_size ? *max_size : kDefaultChunkSize,
43 base::Bind(&IOHandler::ReadComplete,
44 weak_factory_.GetWeakPtr(), command_id));
45 return Response::OK();
46 }
47
48 void IOHandler::ReadComplete(DevToolsCommandId command_id,
49 const scoped_refptr<base::RefCountedString>& data,
50 int status) {
51 if (status == DevToolsIOContext::Stream::StatusFailure) {
pfeldman 2015/08/24 18:17:55 Close upon failure?
52 client_->SendError(command_id, Response::ServerError("Read failed"));
53 return;
54 }
55 bool eof = status == DevToolsIOContext::Stream::StatusEOF;
56 client_->SendReadResponse(command_id,
57 ReadResponse::Create()->set_data(data->data())->set_eof(eof));
58 }
59
60 Response IOHandler::Close(const std::string& id) {
61 return io_context_->Close(id) ? Response::OK()
62 : Response::InvalidParams("id");
63 }
64
65 } // namespace io
66 } // namespace devtools
67 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698