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 "webkit/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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "net/base/request_priority.h" | 11 #include "net/base/request_priority.h" |
12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
13 #include "net/url_request/url_request_job_factory.h" | 13 #include "net/url_request/url_request_job_factory.h" |
14 #include "webkit/browser/blob/blob_data_handle.h" | 14 #include "storage/browser/blob/blob_data_handle.h" |
15 #include "webkit/browser/blob/blob_storage_context.h" | 15 #include "storage/browser/blob/blob_storage_context.h" |
16 #include "webkit/browser/blob/blob_url_request_job.h" | 16 #include "storage/browser/blob/blob_url_request_job.h" |
17 #include "webkit/browser/fileapi/file_system_context.h" | 17 #include "storage/browser/fileapi/file_system_context.h" |
18 | 18 |
19 namespace webkit_blob { | 19 namespace storage { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 int kUserDataKey; // The value is not important, the addr is a key. | 23 int kUserDataKey; // The value is not important, the addr is a key. |
24 | 24 |
25 BlobDataHandle* GetRequestedBlobDataHandle(net::URLRequest* request) { | 25 BlobDataHandle* GetRequestedBlobDataHandle(net::URLRequest* request) { |
26 return static_cast<BlobDataHandle*>(request->GetUserData(&kUserDataKey)); | 26 return static_cast<BlobDataHandle*>(request->GetUserData(&kUserDataKey)); |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
(...skipping 12 matching lines...) Expand all Loading... |
42 | 42 |
43 // static | 43 // static |
44 void BlobProtocolHandler::SetRequestedBlobDataHandle( | 44 void BlobProtocolHandler::SetRequestedBlobDataHandle( |
45 net::URLRequest* request, | 45 net::URLRequest* request, |
46 scoped_ptr<BlobDataHandle> blob_data_handle) { | 46 scoped_ptr<BlobDataHandle> blob_data_handle) { |
47 request->SetUserData(&kUserDataKey, blob_data_handle.release()); | 47 request->SetUserData(&kUserDataKey, blob_data_handle.release()); |
48 } | 48 } |
49 | 49 |
50 BlobProtocolHandler::BlobProtocolHandler( | 50 BlobProtocolHandler::BlobProtocolHandler( |
51 BlobStorageContext* context, | 51 BlobStorageContext* context, |
52 fileapi::FileSystemContext* file_system_context, | 52 storage::FileSystemContext* file_system_context, |
53 base::MessageLoopProxy* loop_proxy) | 53 base::MessageLoopProxy* loop_proxy) |
54 : file_system_context_(file_system_context), | 54 : file_system_context_(file_system_context), file_loop_proxy_(loop_proxy) { |
55 file_loop_proxy_(loop_proxy) { | |
56 if (context) | 55 if (context) |
57 context_ = context->AsWeakPtr(); | 56 context_ = context->AsWeakPtr(); |
58 } | 57 } |
59 | 58 |
60 BlobProtocolHandler::~BlobProtocolHandler() { | 59 BlobProtocolHandler::~BlobProtocolHandler() { |
61 } | 60 } |
62 | 61 |
63 net::URLRequestJob* BlobProtocolHandler::MaybeCreateJob( | 62 net::URLRequestJob* BlobProtocolHandler::MaybeCreateJob( |
64 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { | 63 net::URLRequest* request, |
65 return new webkit_blob::BlobURLRequestJob( | 64 net::NetworkDelegate* network_delegate) const { |
66 request, network_delegate, LookupBlobData(request), | 65 return new storage::BlobURLRequestJob(request, |
67 file_system_context_, file_loop_proxy_); | 66 network_delegate, |
| 67 LookupBlobData(request), |
| 68 file_system_context_, |
| 69 file_loop_proxy_); |
68 } | 70 } |
69 | 71 |
70 scoped_refptr<webkit_blob::BlobData> | 72 scoped_refptr<storage::BlobData> BlobProtocolHandler::LookupBlobData( |
71 BlobProtocolHandler::LookupBlobData(net::URLRequest* request) const { | 73 net::URLRequest* request) const { |
72 BlobDataHandle* blob_data_handle = GetRequestedBlobDataHandle(request); | 74 BlobDataHandle* blob_data_handle = GetRequestedBlobDataHandle(request); |
73 if (blob_data_handle) | 75 if (blob_data_handle) |
74 return blob_data_handle->data(); | 76 return blob_data_handle->data(); |
75 if (!context_.get()) | 77 if (!context_.get()) |
76 return NULL; | 78 return NULL; |
77 | 79 |
78 // Support looking up based on uuid, the FeedbackExtensionAPI relies on this. | 80 // Support looking up based on uuid, the FeedbackExtensionAPI relies on this. |
79 // TODO(michaeln): Replace this use case and others like it with a BlobReader | 81 // TODO(michaeln): Replace this use case and others like it with a BlobReader |
80 // impl that does not depend on urlfetching to perform this function. | 82 // impl that does not depend on urlfetching to perform this function. |
81 const std::string kPrefix("blob:uuid/"); | 83 const std::string kPrefix("blob:uuid/"); |
82 if (!StartsWithASCII(request->url().spec(), kPrefix, true)) | 84 if (!StartsWithASCII(request->url().spec(), kPrefix, true)) |
83 return NULL; | 85 return NULL; |
84 std::string uuid = request->url().spec().substr(kPrefix.length()); | 86 std::string uuid = request->url().spec().substr(kPrefix.length()); |
85 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(uuid); | 87 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(uuid); |
86 return handle.get() ? handle->data() : NULL; | 88 return handle.get() ? handle->data() : NULL; |
87 } | 89 } |
88 | 90 |
89 } // namespace webkit_blob | 91 } // namespace storage |
OLD | NEW |