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 "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 #include "webkit/browser/blob/blob_storage_context.h" | 11 #include "webkit/browser/blob/blob_storage_context.h" |
11 | 12 |
12 using base::UserDataAdapter; | 13 using base::UserDataAdapter; |
13 using webkit_blob::BlobStorageContext; | 14 using webkit_blob::BlobStorageContext; |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; | 18 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; |
(...skipping 18 matching lines...) Expand all Loading... |
36 | 37 |
37 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 38 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
38 context, kBlobStorageContextKeyName); | 39 context, kBlobStorageContextKeyName); |
39 } | 40 } |
40 | 41 |
41 void ChromeBlobStorageContext::InitializeOnIOThread() { | 42 void ChromeBlobStorageContext::InitializeOnIOThread() { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
43 context_.reset(new BlobStorageContext()); | 44 context_.reset(new BlobStorageContext()); |
44 } | 45 } |
45 | 46 |
| 47 void ChromeBlobStorageContext::CreateMemoryBackedBlob( |
| 48 const char* data, size_t length, const BlobCallback& callback) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 50 BrowserThread::PostTaskAndReplyWithResult( |
| 51 BrowserThread::IO, FROM_HERE, |
| 52 base::Bind(&ChromeBlobStorageContext::CreateMemoryBackedBlobOnIOThread, |
| 53 this, data, length, callback), |
| 54 callback); |
| 55 } |
| 56 |
46 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} | 57 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} |
47 | 58 |
| 59 scoped_ptr<webkit_blob::BlobDataHandle> |
| 60 ChromeBlobStorageContext::CreateMemoryBackedBlobOnIOThread( |
| 61 const char* data, size_t length, const BlobCallback& callback) { |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 63 |
| 64 std::string uuid(base::GenerateGUID()); |
| 65 scoped_refptr<webkit_blob::BlobData> blob_data = |
| 66 new webkit_blob::BlobData(uuid); |
| 67 blob_data->AppendData(data, length); |
| 68 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle( |
| 69 context_->AddFinishedBlob(blob_data.get())); |
| 70 return blob_data_handle.Pass(); |
| 71 } |
| 72 |
48 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 73 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
49 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 74 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
50 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 75 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
51 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 76 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
52 return; | 77 return; |
53 } | 78 } |
54 delete this; | 79 delete this; |
55 } | 80 } |
56 | 81 |
57 } // namespace content | 82 } // namespace content |
OLD | NEW |