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 "webkit/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/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
12 #include "net/url_request/url_request_job_factory.h" | 13 #include "net/url_request/url_request_job_factory.h" |
13 #include "webkit/browser/blob/blob_data_handle.h" | 14 #include "webkit/browser/blob/blob_data_handle.h" |
14 #include "webkit/browser/blob/blob_storage_context.h" | 15 #include "webkit/browser/blob/blob_storage_context.h" |
15 #include "webkit/browser/blob/blob_url_request_job.h" | 16 #include "webkit/browser/blob/blob_url_request_job.h" |
16 #include "webkit/browser/fileapi/file_system_context.h" | 17 #include "webkit/browser/fileapi/file_system_context.h" |
17 | 18 |
18 namespace webkit_blob { | 19 namespace webkit_blob { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 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. |
23 | 24 |
24 BlobDataHandle* GetRequestedBlobDataHandle(net::URLRequest* request) { | 25 BlobDataHandle* GetRequestedBlobDataHandle(net::URLRequest* request) { |
25 return static_cast<BlobDataHandle*>(request->GetUserData(&kUserDataKey)); | 26 return static_cast<BlobDataHandle*>(request->GetUserData(&kUserDataKey)); |
26 } | 27 } |
27 | 28 |
28 } // namespace | 29 } // namespace |
29 | 30 |
30 // static | 31 // static |
31 net::URLRequest* BlobProtocolHandler::CreateBlobRequest( | 32 scoped_ptr<net::URLRequest> BlobProtocolHandler::CreateBlobRequest( |
32 scoped_ptr<BlobDataHandle> blob_data_handle, | 33 scoped_ptr<BlobDataHandle> blob_data_handle, |
33 const net::URLRequestContext* request_context, | 34 const net::URLRequestContext* request_context, |
34 net::URLRequest::Delegate* request_delegate) { | 35 net::URLRequest::Delegate* request_delegate) { |
35 const GURL kBlobUrl("blob://see_user_data/"); | 36 const GURL kBlobUrl("blob://see_user_data/"); |
36 net::URLRequest* request = request_context->CreateRequest( | 37 scoped_ptr<net::URLRequest> request = request_context->CreateRequest( |
37 kBlobUrl, request_delegate); | 38 kBlobUrl, net::DEFAULT_PRIORITY, request_delegate); |
38 SetRequestedBlobDataHandle(request, blob_data_handle.Pass()); | 39 SetRequestedBlobDataHandle(request.get(), blob_data_handle.Pass()); |
39 return request; | 40 return request.Pass(); |
40 } | 41 } |
41 | 42 |
42 // static | 43 // static |
43 void BlobProtocolHandler::SetRequestedBlobDataHandle( | 44 void BlobProtocolHandler::SetRequestedBlobDataHandle( |
44 net::URLRequest* request, | 45 net::URLRequest* request, |
45 scoped_ptr<BlobDataHandle> blob_data_handle) { | 46 scoped_ptr<BlobDataHandle> blob_data_handle) { |
46 request->SetUserData(&kUserDataKey, blob_data_handle.release()); | 47 request->SetUserData(&kUserDataKey, blob_data_handle.release()); |
47 } | 48 } |
48 | 49 |
49 BlobProtocolHandler::BlobProtocolHandler( | 50 BlobProtocolHandler::BlobProtocolHandler( |
(...skipping 29 matching lines...) Expand all Loading... |
79 // impl that does not depend on urlfetching to perform this function. | 80 // impl that does not depend on urlfetching to perform this function. |
80 const std::string kPrefix("blob:uuid/"); | 81 const std::string kPrefix("blob:uuid/"); |
81 if (!StartsWithASCII(request->url().spec(), kPrefix, true)) | 82 if (!StartsWithASCII(request->url().spec(), kPrefix, true)) |
82 return NULL; | 83 return NULL; |
83 std::string uuid = request->url().spec().substr(kPrefix.length()); | 84 std::string uuid = request->url().spec().substr(kPrefix.length()); |
84 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(uuid); | 85 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(uuid); |
85 return handle.get() ? handle->data() : NULL; | 86 return handle.get() ? handle->data() : NULL; |
86 } | 87 } |
87 | 88 |
88 } // namespace webkit_blob | 89 } // namespace webkit_blob |
OLD | NEW |