0

Simplify chrome_pdf::URLLoaderWrapper::GetByteRange().

Change it to GetByteRangeStart(), since no caller actually cares about
the end of the byte range.

Fix some nits along the way.

Change-Id: Ia7846923bcf0e5923dd677f85bfe2c5c0ea187c4
Reviewed-on: https://chromium-review.googlesource.com/810005
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523188}
This commit is contained in:
Lei Zhang
2017-12-11 20:25:48 +00:00
committed by Commit Bot
parent 95534df7ca
commit 02a3a0f728
5 changed files with 40 additions and 36 deletions

@ -262,27 +262,27 @@ void DocumentLoader::DidOpenPartial(int32_t result) {
// Leave position untouched for multiparted responce for now, when we read the
// data we'll get it.
if (!loader_->IsMultipart()) {
// Need to make sure that the server returned a byte-range, since it's
// possible for a server to just ignore our byte-range request and just
// return the entire document even if it supports byte-range requests.
// i.e. sniff response to
// http://www.act.org/compass/sample/pdf/geometry.pdf
int start_pos = 0;
int end_pos = 0;
if (loader_->GetByteRange(&start_pos, &end_pos)) {
if (start_pos % DataStream::kChunkSize != 0) {
return ReadComplete();
}
DCHECK(!chunk_.chunk_data);
chunk_.chunk_index = chunk_stream_.GetChunkIndex(start_pos);
} else {
SetPartialLoadingEnabled(false);
}
return ContinueDownload();
if (loader_->IsMultipart()) {
// Needs more data to calc chunk index.
return ReadMore();
}
// Needs more data to calc chunk index.
return ReadMore();
// Need to make sure that the server returned a byte-range, since it's
// possible for a server to just ignore our byte-range request and just
// return the entire document even if it supports byte-range requests.
// i.e. sniff response to
// http://www.act.org/compass/sample/pdf/geometry.pdf
int start_pos = 0;
if (loader_->GetByteRangeStart(&start_pos)) {
if (start_pos % DataStream::kChunkSize != 0)
return ReadComplete();
DCHECK(!chunk_.chunk_data);
chunk_.chunk_index = chunk_stream_.GetChunkIndex(start_pos);
} else {
SetPartialLoadingEnabled(false);
}
return ContinueDownload();
}
void DocumentLoader::ReadMore() {
@ -306,19 +306,16 @@ void DocumentLoader::DidRead(int32_t result) {
}
if (loader_->IsMultipart()) {
int start_pos = 0;
int end_pos = 0;
if (!loader_->GetByteRange(&start_pos, &end_pos)) {
if (!loader_->GetByteRangeStart(&start_pos))
return ReadComplete();
}
DCHECK(!chunk_.chunk_data);
chunk_.chunk_index = chunk_stream_.GetChunkIndex(start_pos);
}
if (!SaveChunkData(buffer_, result)) {
if (!SaveChunkData(buffer_, result))
return ReadMore();
}
if (IsDocumentComplete()) {
if (IsDocumentComplete())
return ReadComplete();
}
return ContinueDownload();
}

@ -4,6 +4,7 @@
#include "pdf/document_loader.h"
#include <algorithm>
#include <memory>
#include <string>
@ -155,9 +156,8 @@ class TestURLLoader : public URLLoaderWrapper {
bool IsMultipart() const override { return data_->is_multipart(); }
bool GetByteRange(int* start, int* end) const override {
bool GetByteRangeStart(int* start) const override {
*start = data_->byte_range().start();
*end = data_->byte_range().end();
return data_->byte_range().IsValid();
}

@ -18,30 +18,39 @@ class URLLoaderWrapper {
// Returns length of content, will be -1, if it is unknown.
virtual int GetContentLength() const = 0;
// Returns if the response headers contains "accept-ranges".
virtual bool IsAcceptRangesBytes() const = 0;
// Returns if the content encoded in response.
virtual bool IsContentEncoded() const = 0;
// Returns response content type.
virtual std::string GetContentType() const = 0;
// Returns response content disposition.
virtual std::string GetContentDisposition() const = 0;
// Returns response status code.
virtual int GetStatusCode() const = 0;
// Returns if the response contains multi parts.
virtual bool IsMultipart() const = 0;
// If true, [start,end] - is byte range contains in response (include end).
// If false, response contains full document, start/end will be undefined.
virtual bool GetByteRange(int* start, int* end) const = 0;
// If true, |start| contains the start of the byte range.
// If false, response contains full document and |start| will be undefined.
virtual bool GetByteRangeStart(int* start) const = 0;
// Close connection.
virtual void Close() = 0;
// Open new connection and send http range request.
virtual void OpenRange(const std::string& url,
const std::string& referrer_url,
uint32_t position,
uint32_t size,
const pp::CompletionCallback& cc) = 0;
// Read the response body. The size of the buffer must be large enough to
// hold the specified number of bytes to read.
// This function might perform a partial read.

@ -156,11 +156,9 @@ bool URLLoaderWrapperImpl::IsMultipart() const {
return is_multipart_;
}
bool URLLoaderWrapperImpl::GetByteRange(int* start, int* end) const {
bool URLLoaderWrapperImpl::GetByteRangeStart(int* start) const {
DCHECK(start);
DCHECK(end);
*start = byte_range_.start();
*end = byte_range_.end();
return byte_range_.IsValid();
}

@ -34,7 +34,7 @@ class URLLoaderWrapperImpl : public URLLoaderWrapper {
std::string GetContentDisposition() const override;
int GetStatusCode() const override;
bool IsMultipart() const override;
bool GetByteRange(int* start, int* end) const override;
bool GetByteRangeStart(int* start) const override;
bool GetDownloadProgress(int64_t* bytes_received,
int64_t* total_bytes_to_be_received) const override;
void Close() override;