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

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

Issue 1408363004: [DevTools] Filter any messages from previous sessions in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 13 matching lines...) Expand all
24 IOHandler::IOHandler(DevToolsIOContext* io_context) 24 IOHandler::IOHandler(DevToolsIOContext* io_context)
25 : io_context_(io_context) 25 : io_context_(io_context)
26 , weak_factory_(this) {} 26 , weak_factory_(this) {}
27 27
28 IOHandler::~IOHandler() {} 28 IOHandler::~IOHandler() {}
29 29
30 void IOHandler::SetClient(scoped_ptr<Client> client) { 30 void IOHandler::SetClient(scoped_ptr<Client> client) {
31 client_.swap(client); 31 client_.swap(client);
32 } 32 }
33 33
34 Response IOHandler::Read(DevToolsCommandId command_id, 34 Response IOHandler::Read(int session_id,
35 const std::string& handle, const int* offset, const int* max_size) { 35 DevToolsCommandId command_id,
36 const std::string& handle,
37 const int* offset,
38 const int* max_size) {
36 static const size_t kDefaultChunkSize = 10 * 1024 * 1024; 39 static const size_t kDefaultChunkSize = 10 * 1024 * 1024;
37 40
38 scoped_refptr<DevToolsIOContext::Stream> stream = 41 scoped_refptr<DevToolsIOContext::Stream> stream =
39 io_context_->GetByHandle(handle); 42 io_context_->GetByHandle(handle);
40 if (!stream) 43 if (!stream)
41 return Response::InvalidParams("Invalid stream handle"); 44 return Response::InvalidParams("Invalid stream handle");
42 stream->Read(offset ? *offset : -1, 45 stream->Read(offset ? *offset : -1,
43 max_size && *max_size ? *max_size : kDefaultChunkSize, 46 max_size && *max_size ? *max_size : kDefaultChunkSize,
44 base::Bind(&IOHandler::ReadComplete, 47 base::Bind(&IOHandler::ReadComplete, weak_factory_.GetWeakPtr(),
45 weak_factory_.GetWeakPtr(), command_id)); 48 session_id, command_id));
46 return Response::OK(); 49 return Response::OK();
47 } 50 }
48 51
49 void IOHandler::ReadComplete(DevToolsCommandId command_id, 52 void IOHandler::ReadComplete(int session_id,
53 DevToolsCommandId command_id,
50 const scoped_refptr<base::RefCountedString>& data, 54 const scoped_refptr<base::RefCountedString>& data,
51 int status) { 55 int status) {
52 if (status == DevToolsIOContext::Stream::StatusFailure) { 56 if (status == DevToolsIOContext::Stream::StatusFailure) {
53 client_->SendError(command_id, Response::ServerError("Read failed")); 57 client_->SendError(session_id, command_id,
58 Response::ServerError("Read failed"));
54 return; 59 return;
55 } 60 }
56 bool eof = status == DevToolsIOContext::Stream::StatusEOF; 61 bool eof = status == DevToolsIOContext::Stream::StatusEOF;
57 client_->SendReadResponse(command_id, 62 client_->SendReadResponse(
63 session_id, command_id,
58 ReadResponse::Create()->set_data(data->data())->set_eof(eof)); 64 ReadResponse::Create()->set_data(data->data())->set_eof(eof));
59 } 65 }
60 66
61 Response IOHandler::Close(const std::string& handle) { 67 Response IOHandler::Close(const std::string& handle) {
62 return io_context_->Close(handle) ? Response::OK() 68 return io_context_->Close(handle) ? Response::OK()
63 : Response::InvalidParams("Invalid stream handle"); 69 : Response::InvalidParams("Invalid stream handle");
64 } 70 }
65 71
66 } // namespace io 72 } // namespace io
67 } // namespace devtools 73 } // namespace devtools
68 } // namespace content 74 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698