| 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/fileapi/chrome_blob_storage_context.h" | 5 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/guid.h" | 10 #include "base/guid.h" |
| 9 #include "content/public/browser/blob_handle.h" | 11 #include "content/public/browser/blob_handle.h" |
| 10 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 12 #include "storage/browser/blob/blob_data_builder.h" | 14 #include "storage/browser/blob/blob_data_builder.h" |
| 13 #include "storage/browser/blob/blob_data_handle.h" | 15 #include "storage/browser/blob/blob_data_handle.h" |
| 14 #include "storage/browser/blob/blob_storage_context.h" | 16 #include "storage/browser/blob/blob_storage_context.h" |
| 15 | 17 |
| 16 using base::UserDataAdapter; | 18 using base::UserDataAdapter; |
| 17 using storage::BlobStorageContext; | 19 using storage::BlobStorageContext; |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; | 25 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; |
| 24 | 26 |
| 25 class BlobHandleImpl : public BlobHandle { | 27 class BlobHandleImpl : public BlobHandle { |
| 26 public: | 28 public: |
| 27 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataHandle> handle) | 29 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataHandle> handle) |
| 28 : handle_(handle.Pass()) {} | 30 : handle_(std::move(handle)) {} |
| 29 | 31 |
| 30 ~BlobHandleImpl() override {} | 32 ~BlobHandleImpl() override {} |
| 31 | 33 |
| 32 std::string GetUUID() override { return handle_->uuid(); } | 34 std::string GetUUID() override { return handle_->uuid(); } |
| 33 | 35 |
| 34 private: | 36 private: |
| 35 scoped_ptr<storage::BlobDataHandle> handle_; | 37 scoped_ptr<storage::BlobDataHandle> handle_; |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 } // namespace | 40 } // namespace |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 std::string uuid(base::GenerateGUID()); | 73 std::string uuid(base::GenerateGUID()); |
| 72 storage::BlobDataBuilder blob_data_builder(uuid); | 74 storage::BlobDataBuilder blob_data_builder(uuid); |
| 73 blob_data_builder.AppendData(data, length); | 75 blob_data_builder.AppendData(data, length); |
| 74 | 76 |
| 75 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 77 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
| 76 context_->AddFinishedBlob(&blob_data_builder); | 78 context_->AddFinishedBlob(&blob_data_builder); |
| 77 if (!blob_data_handle) | 79 if (!blob_data_handle) |
| 78 return scoped_ptr<BlobHandle>(); | 80 return scoped_ptr<BlobHandle>(); |
| 79 | 81 |
| 80 scoped_ptr<BlobHandle> blob_handle( | 82 scoped_ptr<BlobHandle> blob_handle( |
| 81 new BlobHandleImpl(blob_data_handle.Pass())); | 83 new BlobHandleImpl(std::move(blob_data_handle))); |
| 82 return blob_handle.Pass(); | 84 return blob_handle; |
| 83 } | 85 } |
| 84 | 86 |
| 85 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateFileBackedBlob( | 87 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateFileBackedBlob( |
| 86 const base::FilePath& path, | 88 const base::FilePath& path, |
| 87 int64_t offset, | 89 int64_t offset, |
| 88 int64_t size, | 90 int64_t size, |
| 89 const base::Time& expected_modification_time) { | 91 const base::Time& expected_modification_time) { |
| 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 91 | 93 |
| 92 std::string uuid(base::GenerateGUID()); | 94 std::string uuid(base::GenerateGUID()); |
| 93 storage::BlobDataBuilder blob_data_builder(uuid); | 95 storage::BlobDataBuilder blob_data_builder(uuid); |
| 94 blob_data_builder.AppendFile(path, offset, size, expected_modification_time); | 96 blob_data_builder.AppendFile(path, offset, size, expected_modification_time); |
| 95 | 97 |
| 96 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 98 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
| 97 context_->AddFinishedBlob(&blob_data_builder); | 99 context_->AddFinishedBlob(&blob_data_builder); |
| 98 if (!blob_data_handle) | 100 if (!blob_data_handle) |
| 99 return scoped_ptr<BlobHandle>(); | 101 return scoped_ptr<BlobHandle>(); |
| 100 | 102 |
| 101 scoped_ptr<BlobHandle> blob_handle( | 103 scoped_ptr<BlobHandle> blob_handle( |
| 102 new BlobHandleImpl(blob_data_handle.Pass())); | 104 new BlobHandleImpl(std::move(blob_data_handle))); |
| 103 return blob_handle.Pass(); | 105 return blob_handle; |
| 104 } | 106 } |
| 105 | 107 |
| 106 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} | 108 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} |
| 107 | 109 |
| 108 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 110 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
| 109 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 111 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
| 110 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 112 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 111 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 113 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
| 112 return; | 114 return; |
| 113 } | 115 } |
| 114 delete this; | 116 delete this; |
| 115 } | 117 } |
| 116 | 118 |
| 117 } // namespace content | 119 } // namespace content |
| OLD | NEW |