OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "storage/browser/blob/blob_url_request_job_factory.h" | 5 #include "storage/browser/blob/blob_url_request_job_factory.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/request_priority.h" | 9 #include "net/base/request_priority.h" |
10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 file_task_runner_(task_runner) { | 52 file_task_runner_(task_runner) { |
53 if (context) | 53 if (context) |
54 context_ = context->AsWeakPtr(); | 54 context_ = context->AsWeakPtr(); |
55 } | 55 } |
56 | 56 |
57 BlobProtocolHandler::~BlobProtocolHandler() { | 57 BlobProtocolHandler::~BlobProtocolHandler() { |
58 } | 58 } |
59 | 59 |
60 net::URLRequestJob* BlobProtocolHandler::MaybeCreateJob( | 60 net::URLRequestJob* BlobProtocolHandler::MaybeCreateJob( |
61 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { | 61 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
62 return new storage::BlobURLRequestJob(request, | 62 return new storage::BlobURLRequestJob( |
63 network_delegate, | 63 request, network_delegate, LookupBlobHandle(request), |
64 LookupBlobData(request), | 64 file_system_context_.get(), file_task_runner_.get()); |
65 file_system_context_.get(), | |
66 file_task_runner_.get()); | |
67 } | 65 } |
68 | 66 |
69 scoped_ptr<BlobDataSnapshot> BlobProtocolHandler::LookupBlobData( | 67 BlobDataHandle* BlobProtocolHandler::LookupBlobHandle( |
70 net::URLRequest* request) const { | 68 net::URLRequest* request) const { |
71 BlobDataHandle* blob_data_handle = GetRequestedBlobDataHandle(request); | 69 BlobDataHandle* blob_data_handle = GetRequestedBlobDataHandle(request); |
72 if (blob_data_handle) | 70 if (blob_data_handle) |
73 return blob_data_handle->CreateSnapshot().Pass(); | 71 return blob_data_handle; |
74 if (!context_.get()) | 72 if (!context_.get()) |
75 return NULL; | 73 return NULL; |
76 | 74 |
77 // Support looking up based on uuid, the FeedbackExtensionAPI relies on this. | 75 // Support looking up based on uuid, the FeedbackExtensionAPI relies on this. |
78 // TODO(michaeln): Replace this use case and others like it with a BlobReader | 76 // TODO(michaeln): Replace this use case and others like it with a BlobReader |
79 // impl that does not depend on urlfetching to perform this function. | 77 // impl that does not depend on urlfetching to perform this function. |
80 const std::string kPrefix("blob:uuid/"); | 78 const std::string kPrefix("blob:uuid/"); |
81 if (!base::StartsWith(request->url().spec(), kPrefix, | 79 if (!base::StartsWith(request->url().spec(), kPrefix, |
82 base::CompareCase::SENSITIVE)) | 80 base::CompareCase::SENSITIVE)) |
83 return NULL; | 81 return NULL; |
84 std::string uuid = request->url().spec().substr(kPrefix.length()); | 82 std::string uuid = request->url().spec().substr(kPrefix.length()); |
85 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(uuid); | 83 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(uuid); |
86 scoped_ptr<BlobDataSnapshot> snapshot; | 84 BlobDataHandle* handle_ptr = handle.get(); |
87 if (handle) { | 85 if (handle) { |
88 snapshot = handle->CreateSnapshot().Pass(); | |
89 SetRequestedBlobDataHandle(request, handle.Pass()); | 86 SetRequestedBlobDataHandle(request, handle.Pass()); |
90 } | 87 } |
91 return snapshot.Pass(); | 88 return handle_ptr; |
92 } | 89 } |
93 | 90 |
94 } // namespace storage | 91 } // namespace storage |
OLD | NEW |