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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/shell/browser/shell_devtools_frontend.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/devtools_ui_bindings.cc
diff --git a/chrome/browser/devtools/devtools_ui_bindings.cc b/chrome/browser/devtools/devtools_ui_bindings.cc
index 8ecab6e921c5ba4fae985a046276644eb4e783a1..1ace00dfda9c9358d4c9355410914d13b79a2a2a 100644
--- a/chrome/browser/devtools/devtools_ui_bindings.cc
+++ b/chrome/browser/devtools/devtools_ui_bindings.cc
@@ -242,7 +242,7 @@ InfoBarService* DefaultBindingsDelegate::GetInfoBarService() {
class ResponseWriter : public net::URLFetcherResponseWriter {
public:
- ResponseWriter(DevToolsUIBindings* bindings, int stream_id);
+ ResponseWriter(base::WeakPtr<DevToolsUIBindings> bindings, int stream_id);
~ResponseWriter() override;
// URLFetcherResponseWriter overrides:
@@ -253,13 +253,13 @@ class ResponseWriter : public net::URLFetcherResponseWriter {
int Finish(const net::CompletionCallback& callback) override;
private:
- DevToolsUIBindings* bindings_;
+ base::WeakPtr<DevToolsUIBindings> bindings_;
int stream_id_;
DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
};
-ResponseWriter::ResponseWriter(DevToolsUIBindings* bindings,
+ResponseWriter::ResponseWriter(base::WeakPtr<DevToolsUIBindings> bindings,
int stream_id)
: bindings_(bindings),
stream_id_(stream_id) {
@@ -275,17 +275,19 @@ int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
int ResponseWriter::Write(net::IOBuffer* buffer,
int num_bytes,
const net::CompletionCallback& callback) {
- base::FundamentalValue id(stream_id_);
- base::StringValue chunk(std::string(buffer->data(), num_bytes));
- bindings_->CallClientFunction(
- "DevToolsAPI.streamWrite", &id, &chunk, nullptr);
+ base::FundamentalValue* id = new base::FundamentalValue(stream_id_);
+ base::StringValue* chunk =
+ new base::StringValue(std::string(buffer->data(), num_bytes));
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&DevToolsUIBindings::CallClientFunction,
+ bindings_, "DevToolsAPI.streamWrite",
+ base::Owned(id), base::Owned(chunk), nullptr));
return num_bytes;
}
int ResponseWriter::Finish(const net::CompletionCallback& callback) {
- base::FundamentalValue id(stream_id_);
- bindings_->CallClientFunction(
- "DevToolsAPI.streamFinish", &id, nullptr, nullptr);
return net::OK;
}
@@ -587,7 +589,7 @@ void DevToolsUIBindings::LoadNetworkResource(int request_id,
fetcher->SetRequestContext(profile_->GetRequestContext());
fetcher->SetExtraRequestHeaders(headers);
fetcher->SaveResponseWithWriter(scoped_ptr<net::URLFetcherResponseWriter>(
- new ResponseWriter(this, stream_id)));
+ new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id)));
fetcher->Start();
}
« 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