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

Side by Side Diff: chrome/browser/devtools/devtools_ui_bindings.cc

Issue 969573002: DevTools: response writers need to post to the UI while sending into streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@loadNetwork
Patch Set: same with no streamfinish Created 5 years, 9 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
« no previous file with comments | « no previous file | content/shell/browser/shell_devtools_frontend.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/devtools/devtools_ui_bindings.h" 5 #include "chrome/browser/devtools/devtools_ui_bindings.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 InfoBarService* DefaultBindingsDelegate::GetInfoBarService() { 237 InfoBarService* DefaultBindingsDelegate::GetInfoBarService() {
238 return InfoBarService::FromWebContents(web_contents_); 238 return InfoBarService::FromWebContents(web_contents_);
239 } 239 }
240 240
241 // ResponseWriter ------------------------------------------------------------- 241 // ResponseWriter -------------------------------------------------------------
242 242
243 class ResponseWriter : public net::URLFetcherResponseWriter { 243 class ResponseWriter : public net::URLFetcherResponseWriter {
244 public: 244 public:
245 ResponseWriter(DevToolsUIBindings* bindings, int stream_id); 245 ResponseWriter(base::WeakPtr<DevToolsUIBindings> bindings, int stream_id);
246 ~ResponseWriter() override; 246 ~ResponseWriter() override;
247 247
248 // URLFetcherResponseWriter overrides: 248 // URLFetcherResponseWriter overrides:
249 int Initialize(const net::CompletionCallback& callback) override; 249 int Initialize(const net::CompletionCallback& callback) override;
250 int Write(net::IOBuffer* buffer, 250 int Write(net::IOBuffer* buffer,
251 int num_bytes, 251 int num_bytes,
252 const net::CompletionCallback& callback) override; 252 const net::CompletionCallback& callback) override;
253 int Finish(const net::CompletionCallback& callback) override; 253 int Finish(const net::CompletionCallback& callback) override;
254 254
255 private: 255 private:
256 DevToolsUIBindings* bindings_; 256 base::WeakPtr<DevToolsUIBindings> bindings_;
257 int stream_id_; 257 int stream_id_;
258 258
259 DISALLOW_COPY_AND_ASSIGN(ResponseWriter); 259 DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
260 }; 260 };
261 261
262 ResponseWriter::ResponseWriter(DevToolsUIBindings* bindings, 262 ResponseWriter::ResponseWriter(base::WeakPtr<DevToolsUIBindings> bindings,
263 int stream_id) 263 int stream_id)
264 : bindings_(bindings), 264 : bindings_(bindings),
265 stream_id_(stream_id) { 265 stream_id_(stream_id) {
266 } 266 }
267 267
268 ResponseWriter::~ResponseWriter() { 268 ResponseWriter::~ResponseWriter() {
269 } 269 }
270 270
271 int ResponseWriter::Initialize(const net::CompletionCallback& callback) { 271 int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
272 return net::OK; 272 return net::OK;
273 } 273 }
274 274
275 int ResponseWriter::Write(net::IOBuffer* buffer, 275 int ResponseWriter::Write(net::IOBuffer* buffer,
276 int num_bytes, 276 int num_bytes,
277 const net::CompletionCallback& callback) { 277 const net::CompletionCallback& callback) {
278 base::FundamentalValue id(stream_id_); 278 base::FundamentalValue* id = new base::FundamentalValue(stream_id_);
279 base::StringValue chunk(std::string(buffer->data(), num_bytes)); 279 base::StringValue* chunk =
280 bindings_->CallClientFunction( 280 new base::StringValue(std::string(buffer->data(), num_bytes));
281 "DevToolsAPI.streamWrite", &id, &chunk, nullptr); 281
282 content::BrowserThread::PostTask(
283 content::BrowserThread::UI, FROM_HERE,
284 base::Bind(&DevToolsUIBindings::CallClientFunction,
285 bindings_, "DevToolsAPI.streamWrite",
286 base::Owned(id), base::Owned(chunk), nullptr));
282 return num_bytes; 287 return num_bytes;
283 } 288 }
284 289
285 int ResponseWriter::Finish(const net::CompletionCallback& callback) { 290 int ResponseWriter::Finish(const net::CompletionCallback& callback) {
286 base::FundamentalValue id(stream_id_);
287 bindings_->CallClientFunction(
288 "DevToolsAPI.streamFinish", &id, nullptr, nullptr);
289 return net::OK; 291 return net::OK;
290 } 292 }
291 293
292 } // namespace 294 } // namespace
293 295
294 // DevToolsUIBindings::FrontendWebContentsObserver ---------------------------- 296 // DevToolsUIBindings::FrontendWebContentsObserver ----------------------------
295 297
296 class DevToolsUIBindings::FrontendWebContentsObserver 298 class DevToolsUIBindings::FrontendWebContentsObserver
297 : public content::WebContentsObserver { 299 : public content::WebContentsObserver {
298 public: 300 public:
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 SendMessageAck(request_id, &response); 582 SendMessageAck(request_id, &response);
581 return; 583 return;
582 } 584 }
583 585
584 net::URLFetcher* fetcher = 586 net::URLFetcher* fetcher =
585 net::URLFetcher::Create(gurl, net::URLFetcher::GET, this); 587 net::URLFetcher::Create(gurl, net::URLFetcher::GET, this);
586 pending_requests_[fetcher] = request_id; 588 pending_requests_[fetcher] = request_id;
587 fetcher->SetRequestContext(profile_->GetRequestContext()); 589 fetcher->SetRequestContext(profile_->GetRequestContext());
588 fetcher->SetExtraRequestHeaders(headers); 590 fetcher->SetExtraRequestHeaders(headers);
589 fetcher->SaveResponseWithWriter(scoped_ptr<net::URLFetcherResponseWriter>( 591 fetcher->SaveResponseWithWriter(scoped_ptr<net::URLFetcherResponseWriter>(
590 new ResponseWriter(this, stream_id))); 592 new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id)));
591 fetcher->Start(); 593 fetcher->Start();
592 } 594 }
593 595
594 void DevToolsUIBindings::OpenInNewTab(int request_id, const std::string& url) { 596 void DevToolsUIBindings::OpenInNewTab(int request_id, const std::string& url) {
595 delegate_->OpenInNewTab(url); 597 delegate_->OpenInNewTab(url);
596 } 598 }
597 599
598 void DevToolsUIBindings::SaveToFile(int request_id, 600 void DevToolsUIBindings::SaveToFile(int request_id,
599 const std::string& url, 601 const std::string& url,
600 const std::string& content, 602 const std::string& content,
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 if (frontend_loaded_) 1025 if (frontend_loaded_)
1024 return; 1026 return;
1025 frontend_loaded_ = true; 1027 frontend_loaded_ = true;
1026 1028
1027 // Call delegate first - it seeds importants bit of information. 1029 // Call delegate first - it seeds importants bit of information.
1028 delegate_->OnLoadCompleted(); 1030 delegate_->OnLoadCompleted();
1029 1031
1030 UpdateTheme(); 1032 UpdateTheme();
1031 AddDevToolsExtensionsToClient(); 1033 AddDevToolsExtensionsToClient();
1032 } 1034 }
OLDNEW
« no previous file with comments | « no previous file | content/shell/browser/shell_devtools_frontend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698