| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "content/public/browser/blob_handle.h" | 9 #include "content/public/browser/blob_handle.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 ~BlobHandleImpl() override {} | 30 ~BlobHandleImpl() override {} |
| 31 | 31 |
| 32 std::string GetUUID() override { return handle_->uuid(); } | 32 std::string GetUUID() override { return handle_->uuid(); } |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 scoped_ptr<storage::BlobDataHandle> handle_; | 35 scoped_ptr<storage::BlobDataHandle> handle_; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 ChromeBlobStorageContext::ChromeBlobStorageContext() {} | 40 ChromeBlobStorageContext::ChromeBlobStorageContext(bool disk_enabled) |
| 41 : disk_enabled_(disk_enabled) {} |
| 41 | 42 |
| 42 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( | 43 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( |
| 43 BrowserContext* context) { | 44 BrowserContext* context) { |
| 44 if (!context->GetUserData(kBlobStorageContextKeyName)) { | 45 if (!context->GetUserData(kBlobStorageContextKeyName)) { |
| 45 scoped_refptr<ChromeBlobStorageContext> blob = | 46 scoped_refptr<ChromeBlobStorageContext> blob = |
| 46 new ChromeBlobStorageContext(); | 47 new ChromeBlobStorageContext(!context->IsOffTheRecord()); |
| 47 context->SetUserData( | 48 context->SetUserData( |
| 48 kBlobStorageContextKeyName, | 49 kBlobStorageContextKeyName, |
| 49 new UserDataAdapter<ChromeBlobStorageContext>(blob.get())); | 50 new UserDataAdapter<ChromeBlobStorageContext>(blob.get())); |
| 50 // Check first to avoid memory leak in unittests. | 51 // Check first to avoid memory leak in unittests. |
| 51 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 52 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 52 BrowserThread::PostTask( | 53 BrowserThread::PostTask( |
| 53 BrowserThread::IO, FROM_HERE, | 54 BrowserThread::IO, FROM_HERE, |
| 54 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); | 55 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 | 58 |
| 58 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 59 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 59 context, kBlobStorageContextKeyName); | 60 context, kBlobStorageContextKeyName); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void ChromeBlobStorageContext::InitializeOnIOThread() { | 63 void ChromeBlobStorageContext::InitializeOnIOThread() { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 64 context_.reset(new BlobStorageContext()); | 65 context_.reset(new BlobStorageContext(disk_enabled_)); |
| 65 } | 66 } |
| 66 | 67 |
| 67 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( | 68 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( |
| 68 const char* data, size_t length) { | 69 const char* data, size_t length) { |
| 69 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 70 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 70 | 71 |
| 71 std::string uuid(base::GenerateGUID()); | 72 std::string uuid(base::GenerateGUID()); |
| 72 storage::BlobDataBuilder blob_data_builder(uuid); | 73 storage::BlobDataBuilder blob_data_builder(uuid); |
| 73 blob_data_builder.AppendData(data, length); | 74 blob_data_builder.AppendData(data, length); |
| 74 | 75 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 109 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
| 109 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 110 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
| 110 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 111 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 111 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 112 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 delete this; | 115 delete this; |
| 115 } | 116 } |
| 116 | 117 |
| 117 } // namespace content | 118 } // namespace content |
| OLD | NEW |