OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/blob_storage/chrome_blob_storage_context.h" | 5 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/guid.h" | 13 #include "base/guid.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/supports_user_data.h" |
17 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
18 #include "base/task_scheduler/post_task.h" | 19 #include "base/task_scheduler/post_task.h" |
19 #include "content/browser/resource_context_impl.h" | 20 #include "content/browser/resource_context_impl.h" |
20 #include "content/common/resource_request_body_impl.h" | 21 #include "content/common/resource_request_body_impl.h" |
21 #include "content/public/browser/blob_handle.h" | 22 #include "content/public/browser/blob_handle.h" |
22 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
24 #include "storage/browser/blob/blob_data_builder.h" | 25 #include "storage/browser/blob/blob_data_builder.h" |
25 #include "storage/browser/blob/blob_data_handle.h" | |
26 #include "storage/browser/blob/blob_memory_controller.h" | 26 #include "storage/browser/blob/blob_memory_controller.h" |
27 #include "storage/browser/blob/blob_storage_context.h" | 27 #include "storage/browser/blob/blob_storage_context.h" |
28 | 28 |
29 using base::FilePath; | 29 using base::FilePath; |
30 using base::UserDataAdapter; | 30 using base::UserDataAdapter; |
31 using storage::BlobStorageContext; | 31 using storage::BlobStorageContext; |
32 | 32 |
33 namespace content { | 33 namespace content { |
34 | 34 |
35 namespace { | 35 namespace { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 delete this; | 190 delete this; |
191 } | 191 } |
192 | 192 |
193 storage::BlobStorageContext* GetBlobStorageContext( | 193 storage::BlobStorageContext* GetBlobStorageContext( |
194 ChromeBlobStorageContext* blob_storage_context) { | 194 ChromeBlobStorageContext* blob_storage_context) { |
195 if (!blob_storage_context) | 195 if (!blob_storage_context) |
196 return NULL; | 196 return NULL; |
197 return blob_storage_context->context(); | 197 return blob_storage_context->context(); |
198 } | 198 } |
199 | 199 |
200 bool AttachRequestBodyBlobDataHandles(ResourceRequestBodyImpl* body, | 200 std::unique_ptr<BlobHandles> GetBodyBlobDataHandles( |
201 ResourceContext* resource_context) { | 201 ResourceRequestBodyImpl* body, |
| 202 ResourceContext* resource_context) { |
202 storage::BlobStorageContext* blob_context = GetBlobStorageContext( | 203 storage::BlobStorageContext* blob_context = GetBlobStorageContext( |
203 GetChromeBlobStorageContextForResourceContext(resource_context)); | 204 GetChromeBlobStorageContextForResourceContext(resource_context)); |
204 | 205 |
| 206 std::unique_ptr<BlobHandles> blob_handles(new BlobHandles()); |
| 207 |
205 DCHECK(blob_context); | 208 DCHECK(blob_context); |
206 for (size_t i = 0; i < body->elements()->size(); ++i) { | 209 for (size_t i = 0; i < body->elements()->size(); ++i) { |
207 const ResourceRequestBodyImpl::Element& element = (*body->elements())[i]; | 210 const ResourceRequestBodyImpl::Element& element = (*body->elements())[i]; |
208 if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB) | 211 if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB) |
209 continue; | 212 continue; |
210 std::unique_ptr<storage::BlobDataHandle> handle = | 213 std::unique_ptr<storage::BlobDataHandle> handle = |
211 blob_context->GetBlobDataFromUUID(element.blob_uuid()); | 214 blob_context->GetBlobDataFromUUID(element.blob_uuid()); |
212 if (!handle) | 215 if (!handle) |
213 return false; | 216 return nullptr; |
214 // Ensure the blob and any attached shareable files survive until | 217 blob_handles->push_back(std::move(handle)); |
215 // upload completion. The |body| takes ownership of |handle|. | |
216 const void* key = handle.get(); | |
217 body->SetUserData(key, std::move(handle)); | |
218 } | 218 } |
219 return true; | 219 return blob_handles; |
220 } | 220 } |
221 | 221 |
222 } // namespace content | 222 } // namespace content |
OLD | NEW |