Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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/histogram_internals_url_loader.h" | |
| 6 | |
| 7 #include "base/metrics/histogram_macros.h" | |
| 8 #include "base/metrics/statistics_recorder.h" | |
| 9 #include "content/browser/histogram_internals_request_job.h" | |
| 10 #include "mojo/common/data_pipe_utils.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 void StartHistogramInternalsURLLoader(const ResourceRequest& request, | |
| 15 mojom::URLLoaderClientPtr client) { | |
| 16 scoped_refptr<net::HttpResponseHeaders> headers( | |
| 17 new net::HttpResponseHeaders("HTTP/1.1 200 OK")); | |
| 18 ResourceResponseHead resource_response; | |
| 19 resource_response.headers = headers; | |
| 20 resource_response.mime_type = "text/html"; | |
| 21 client->OnReceiveResponse(resource_response, base::nullopt, nullptr); | |
| 22 | |
| 23 base::StatisticsRecorder::ImportProvidedHistograms(); | |
| 24 std::string data = HistogramInternalsRequestJob::GenerateHTML(request.url); | |
| 25 | |
| 26 MojoCreateDataPipeOptions options; | |
| 27 options.struct_size = sizeof(MojoCreateDataPipeOptions); | |
| 28 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | |
| 29 options.element_num_bytes = 1; | |
| 30 options.capacity_num_bytes = data.size(); | |
| 31 mojo::DataPipe data_pipe(options); | |
| 32 | |
| 33 DCHECK(data_pipe.producer_handle.is_valid()); | |
| 34 DCHECK(data_pipe.consumer_handle.is_valid()); | |
| 35 | |
| 36 CHECK(mojo::common::BlockingCopyFromString(data, data_pipe.producer_handle)); | |
|
yzshen1
2017/05/10 15:13:43
The data pipe API doesn't guarantee that we could
jam
2017/05/10 15:29:58
Re blocking, I think it's fine for testing pages l
| |
| 37 | |
| 38 client->OnStartLoadingResponseBody(std::move(data_pipe.consumer_handle)); | |
| 39 | |
| 40 ResourceRequestCompletionStatus request_complete_data; | |
| 41 request_complete_data.error_code = net::OK; | |
| 42 request_complete_data.exists_in_cache = false; | |
| 43 request_complete_data.completion_time = base::TimeTicks::Now(); | |
| 44 request_complete_data.encoded_data_length = data.size(); | |
| 45 request_complete_data.encoded_body_length = data.size(); | |
| 46 client->OnComplete(request_complete_data); | |
| 47 } | |
| 48 | |
| 49 } // namespace content | |
| OLD | NEW |