| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/blob_reader.h" | 5 #include "chrome/browser/extensions/blob_reader.h" |
| 6 | 6 |
| 7 #include <limits> |
| 8 |
| 7 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 8 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 12 #include "net/http/http_request_headers.h" | 14 #include "net/http/http_request_headers.h" |
| 13 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
| 14 #include "net/url_request/url_fetcher.h" | 16 #include "net/url_request/url_fetcher.h" |
| 15 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 } else { | 30 } else { |
| 29 blob_url = GURL(std::string("blob:uuid/") + blob_uuid); | 31 blob_url = GURL(std::string("blob:uuid/") + blob_uuid); |
| 30 } | 32 } |
| 31 DCHECK(blob_url.is_valid()); | 33 DCHECK(blob_url.is_valid()); |
| 32 fetcher_ = net::URLFetcher::Create(blob_url, net::URLFetcher::GET, this); | 34 fetcher_ = net::URLFetcher::Create(blob_url, net::URLFetcher::GET, this); |
| 33 fetcher_->SetRequestContext(profile->GetRequestContext()); | 35 fetcher_->SetRequestContext(profile->GetRequestContext()); |
| 34 } | 36 } |
| 35 | 37 |
| 36 BlobReader::~BlobReader() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); } | 38 BlobReader::~BlobReader() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); } |
| 37 | 39 |
| 38 void BlobReader::SetByteRange(int64 offset, int64 length) { | 40 void BlobReader::SetByteRange(int64_t offset, int64_t length) { |
| 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 40 CHECK_GE(offset, 0); | 42 CHECK_GE(offset, 0); |
| 41 CHECK_GT(length, 0); | 43 CHECK_GT(length, 0); |
| 42 CHECK_LE(offset, kint64max - length); | 44 CHECK_LE(offset, std::numeric_limits<int64_t>::max() - length); |
| 43 | 45 |
| 44 net::HttpRequestHeaders headers; | 46 net::HttpRequestHeaders headers; |
| 45 headers.SetHeader( | 47 headers.SetHeader( |
| 46 net::HttpRequestHeaders::kRange, | 48 net::HttpRequestHeaders::kRange, |
| 47 base::StringPrintf("bytes=%" PRId64 "-%" PRId64, offset, | 49 base::StringPrintf("bytes=%" PRId64 "-%" PRId64, offset, |
| 48 offset + length - 1)); | 50 offset + length - 1)); |
| 49 fetcher_->SetExtraRequestHeaders(headers.ToString()); | 51 fetcher_->SetExtraRequestHeaders(headers.ToString()); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void BlobReader::Start() { | 54 void BlobReader::Start() { |
| 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 55 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 54 fetcher_->Start(); | 56 fetcher_->Start(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 // Overridden from net::URLFetcherDelegate. | 59 // Overridden from net::URLFetcherDelegate. |
| 58 void BlobReader::OnURLFetchComplete(const net::URLFetcher* source) { | 60 void BlobReader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 60 scoped_ptr<std::string> response(new std::string); | 62 scoped_ptr<std::string> response(new std::string); |
| 61 int64 first = 0, last = 0, length = 0; | 63 int64_t first = 0, last = 0, length = 0; |
| 62 source->GetResponseAsString(response.get()); | 64 source->GetResponseAsString(response.get()); |
| 63 source->GetResponseHeaders()->GetContentRange(&first, &last, &length); | 65 source->GetResponseHeaders()->GetContentRange(&first, &last, &length); |
| 64 callback_.Run(response.Pass(), length); | 66 callback_.Run(response.Pass(), length); |
| 65 | 67 |
| 66 delete this; | 68 delete this; |
| 67 } | 69 } |
| OLD | NEW |