| 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/task_runner.h" | 17 #include "base/task_runner.h" |
| 18 #include "base/task_scheduler/post_task.h" | 18 #include "base/task_scheduler/post_task.h" |
| 19 #include "content/browser/resource_context_impl.h" | 19 #include "content/browser/resource_context_impl.h" |
| 20 #include "content/common/resource_request_body_impl.h" | 20 #include "content/common/resource_request_body_impl.h" |
| 21 #include "content/public/browser/blob_handle.h" | 21 #include "content/public/browser/blob_handle.h" |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "storage/browser/blob/blob_data_builder.h" | 24 #include "storage/browser/blob/blob_data_builder.h" |
| 25 #include "storage/browser/blob/blob_data_handle.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_registry_impl.h" |
| 27 #include "storage/browser/blob/blob_storage_context.h" | 28 #include "storage/browser/blob/blob_storage_context.h" |
| 28 | 29 |
| 29 using base::FilePath; | 30 using base::FilePath; |
| 30 using base::UserDataAdapter; | 31 using base::UserDataAdapter; |
| 31 using storage::BlobStorageContext; | 32 using storage::BlobStorageContext; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 const FilePath::CharType kBlobStorageContextKeyName[] = | 37 const FilePath::CharType kBlobStorageContextKeyName[] = |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 125 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 125 context, kBlobStorageContextKeyName); | 126 context, kBlobStorageContextKeyName); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void ChromeBlobStorageContext::InitializeOnIOThread( | 129 void ChromeBlobStorageContext::InitializeOnIOThread( |
| 129 FilePath blob_storage_dir, | 130 FilePath blob_storage_dir, |
| 130 scoped_refptr<base::TaskRunner> file_task_runner) { | 131 scoped_refptr<base::TaskRunner> file_task_runner) { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 132 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 132 context_.reset(new BlobStorageContext(std::move(blob_storage_dir), | 133 context_.reset(new BlobStorageContext(std::move(blob_storage_dir), |
| 133 std::move(file_task_runner))); | 134 std::move(file_task_runner))); |
| 135 blob_registry_ = base::MakeUnique<storage::BlobRegistryImpl>(context_.get()); |
| 134 // Signal the BlobMemoryController when it's appropriate to calculate its | 136 // Signal the BlobMemoryController when it's appropriate to calculate its |
| 135 // storage limits. | 137 // storage limits. |
| 136 BrowserThread::PostAfterStartupTask( | 138 BrowserThread::PostAfterStartupTask( |
| 137 FROM_HERE, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), | 139 FROM_HERE, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), |
| 138 base::Bind(&storage::BlobMemoryController::CalculateBlobStorageLimits, | 140 base::Bind(&storage::BlobMemoryController::CalculateBlobStorageLimits, |
| 139 context_->mutable_memory_controller()->GetWeakPtr())); | 141 context_->mutable_memory_controller()->GetWeakPtr())); |
| 140 } | 142 } |
| 141 | 143 |
| 142 std::unique_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( | 144 std::unique_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( |
| 143 const char* data, | 145 const char* data, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 172 std::unique_ptr<storage::BlobDataHandle> blob_data_handle = | 174 std::unique_ptr<storage::BlobDataHandle> blob_data_handle = |
| 173 context_->AddFinishedBlob(&blob_data_builder); | 175 context_->AddFinishedBlob(&blob_data_builder); |
| 174 if (!blob_data_handle) | 176 if (!blob_data_handle) |
| 175 return std::unique_ptr<BlobHandle>(); | 177 return std::unique_ptr<BlobHandle>(); |
| 176 | 178 |
| 177 std::unique_ptr<BlobHandle> blob_handle( | 179 std::unique_ptr<BlobHandle> blob_handle( |
| 178 new BlobHandleImpl(std::move(blob_data_handle))); | 180 new BlobHandleImpl(std::move(blob_data_handle))); |
| 179 return blob_handle; | 181 return blob_handle; |
| 180 } | 182 } |
| 181 | 183 |
| 184 void ChromeBlobStorageContext::BindBlobRegistry( |
| 185 const service_manager::BindSourceInfo& source_info, |
| 186 storage::mojom::BlobRegistryRequest request) { |
| 187 blob_registry_->Bind(source_info, std::move(request)); |
| 188 } |
| 189 |
| 182 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} | 190 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} |
| 183 | 191 |
| 184 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 192 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
| 185 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 193 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
| 186 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 194 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 187 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 195 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
| 188 return; | 196 return; |
| 189 } | 197 } |
| 190 delete this; | 198 delete this; |
| 191 } | 199 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 213 if (!handle) | 221 if (!handle) |
| 214 continue; | 222 continue; |
| 215 // Ensure the blob and any attached shareable files survive until | 223 // Ensure the blob and any attached shareable files survive until |
| 216 // upload completion. The |body| takes ownership of |handle|. | 224 // upload completion. The |body| takes ownership of |handle|. |
| 217 const void* key = handle.get(); | 225 const void* key = handle.get(); |
| 218 body->SetUserData(key, std::move(handle)); | 226 body->SetUserData(key, std::move(handle)); |
| 219 } | 227 } |
| 220 } | 228 } |
| 221 | 229 |
| 222 } // namespace content | 230 } // namespace content |
| OLD | NEW |