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 "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 : callback_(callback) { | 21 : callback_(callback) { |
22 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 22 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
23 GURL blob_url; | 23 GURL blob_url; |
24 if (StartsWithASCII(blob_uuid, "blob:blobinternal", true)) { | 24 if (StartsWithASCII(blob_uuid, "blob:blobinternal", true)) { |
25 // TODO(michaeln): remove support for deprecated blob urls | 25 // TODO(michaeln): remove support for deprecated blob urls |
26 blob_url = GURL(blob_uuid); | 26 blob_url = GURL(blob_uuid); |
27 } else { | 27 } else { |
28 blob_url = GURL(std::string("blob:uuid/") + blob_uuid); | 28 blob_url = GURL(std::string("blob:uuid/") + blob_uuid); |
29 } | 29 } |
30 DCHECK(blob_url.is_valid()); | 30 DCHECK(blob_url.is_valid()); |
31 fetcher_.reset(net::URLFetcher::Create( | 31 fetcher_ = net::URLFetcher::Create(blob_url, net::URLFetcher::GET, this); |
32 blob_url, net::URLFetcher::GET, | |
33 this)); | |
34 fetcher_->SetRequestContext(profile->GetRequestContext()); | 32 fetcher_->SetRequestContext(profile->GetRequestContext()); |
35 } | 33 } |
36 | 34 |
37 BlobReader::~BlobReader() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); } | 35 BlobReader::~BlobReader() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); } |
38 | 36 |
39 void BlobReader::SetByteRange(int64 offset, int64 length) { | 37 void BlobReader::SetByteRange(int64 offset, int64 length) { |
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
41 CHECK_GE(offset, 0); | 39 CHECK_GE(offset, 0); |
42 CHECK_GT(length, 0); | 40 CHECK_GT(length, 0); |
43 CHECK_LE(offset, kint64max - length); | 41 CHECK_LE(offset, kint64max - length); |
(...skipping 15 matching lines...) Expand all Loading... |
59 void BlobReader::OnURLFetchComplete(const net::URLFetcher* source) { | 57 void BlobReader::OnURLFetchComplete(const net::URLFetcher* source) { |
60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
61 scoped_ptr<std::string> response(new std::string); | 59 scoped_ptr<std::string> response(new std::string); |
62 int64 first = 0, last = 0, length = 0; | 60 int64 first = 0, last = 0, length = 0; |
63 source->GetResponseAsString(response.get()); | 61 source->GetResponseAsString(response.get()); |
64 source->GetResponseHeaders()->GetContentRange(&first, &last, &length); | 62 source->GetResponseHeaders()->GetContentRange(&first, &last, &length); |
65 callback_.Run(response.Pass(), length); | 63 callback_.Run(response.Pass(), length); |
66 | 64 |
67 delete this; | 65 delete this; |
68 } | 66 } |
OLD | NEW |