| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/public/test/mock_blob_url_request_context.h" | 5 #include "storage/browser/test/mock_blob_url_request_context.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "storage/browser/blob/blob_data_builder.h" | 9 #include "storage/browser/blob/blob_data_builder.h" |
| 10 #include "storage/browser/blob/blob_storage_context.h" | 10 #include "storage/browser/blob/blob_storage_context.h" |
| 11 #include "storage/browser/blob/blob_url_request_job.h" | 11 #include "storage/browser/blob/blob_url_request_job.h" |
| 12 #include "storage/browser/blob/blob_url_request_job_factory.h" | 12 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 MockBlobURLRequestContext::MockBlobURLRequestContext( | 16 MockBlobURLRequestContext::MockBlobURLRequestContext( |
| 17 storage::FileSystemContext* file_system_context) | 17 storage::FileSystemContext* file_system_context) |
| 18 : blob_storage_context_(new storage::BlobStorageContext) { | 18 : blob_storage_context_(new storage::BlobStorageContext) { |
| 19 // Job factory owns the protocol handler. | 19 // Job factory owns the protocol handler. |
| 20 job_factory_.SetProtocolHandler( | 20 job_factory_.SetProtocolHandler( |
| 21 "blob", base::MakeUnique<storage::BlobProtocolHandler>( | 21 "blob", base::MakeUnique<storage::BlobProtocolHandler>( |
| 22 blob_storage_context_.get(), file_system_context, | 22 blob_storage_context_.get(), file_system_context, |
| 23 base::ThreadTaskRunnerHandle::Get())); | 23 base::ThreadTaskRunnerHandle::Get())); |
| 24 set_job_factory(&job_factory_); | 24 set_job_factory(&job_factory_); |
| 25 } | 25 } |
| 26 | 26 |
| 27 MockBlobURLRequestContext::~MockBlobURLRequestContext() { | 27 MockBlobURLRequestContext::~MockBlobURLRequestContext() { |
| 28 AssertNoURLRequests(); | 28 AssertNoURLRequests(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 ScopedTextBlob::ScopedTextBlob( | 31 ScopedTextBlob::ScopedTextBlob(const MockBlobURLRequestContext& request_context, |
| 32 const MockBlobURLRequestContext& request_context, | 32 const std::string& blob_id, |
| 33 const std::string& blob_id, | 33 const std::string& data) |
| 34 const std::string& data) | 34 : blob_id_(blob_id), context_(request_context.blob_storage_context()) { |
| 35 : blob_id_(blob_id), | |
| 36 context_(request_context.blob_storage_context()) { | |
| 37 DCHECK(context_); | 35 DCHECK(context_); |
| 38 storage::BlobDataBuilder blob_builder(blob_id_); | 36 storage::BlobDataBuilder blob_builder(blob_id_); |
| 39 if (!data.empty()) | 37 if (!data.empty()) |
| 40 blob_builder.AppendData(data); | 38 blob_builder.AppendData(data); |
| 41 handle_ = context_->AddFinishedBlob(&blob_builder); | 39 handle_ = context_->AddFinishedBlob(&blob_builder); |
| 42 } | 40 } |
| 43 | 41 |
| 44 ScopedTextBlob::~ScopedTextBlob() { | 42 ScopedTextBlob::~ScopedTextBlob() {} |
| 45 } | |
| 46 | 43 |
| 47 std::unique_ptr<storage::BlobDataHandle> ScopedTextBlob::GetBlobDataHandle() { | 44 std::unique_ptr<storage::BlobDataHandle> ScopedTextBlob::GetBlobDataHandle() { |
| 48 return context_->GetBlobDataFromUUID(blob_id_); | 45 return context_->GetBlobDataFromUUID(blob_id_); |
| 49 } | 46 } |
| 50 | 47 |
| 51 } // namespace content | 48 } // namespace content |
| OLD | NEW |