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" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "storage/browser/blob/blob_data_handle.h" | 12 #include "storage/browser/blob/blob_data_handle.h" |
13 #include "storage/browser/blob/blob_storage_context.h" | 13 #include "storage/browser/blob/blob_storage_context.h" |
14 | 14 |
15 using base::UserDataAdapter; | 15 using base::UserDataAdapter; |
16 using storage::BlobStorageContext; | 16 using storage::BlobStorageContext; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; | 22 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; |
23 | 23 |
24 class BlobHandleImpl : public BlobHandle { | 24 class BlobHandleImpl : public BlobHandle { |
25 public: | 25 public: |
26 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataHandle> handle) | 26 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataSnapshotHandle> handle) |
27 : handle_(handle.Pass()) { | 27 : handle_(handle.Pass()) {} |
28 } | |
29 | 28 |
30 ~BlobHandleImpl() override {} | 29 ~BlobHandleImpl() override {} |
31 | 30 |
32 std::string GetUUID() override { return handle_->uuid(); } | 31 std::string GetUUID() override { return handle_->uuid(); } |
33 | 32 |
34 private: | 33 private: |
35 scoped_ptr<storage::BlobDataHandle> handle_; | 34 scoped_ptr<storage::BlobDataSnapshotHandle> handle_; |
michaeln
2015/01/16 00:09:09
for this particular class we only want to keep the
dmurph
2015/01/16 23:45:56
Right, we want to keep the handle around though, r
| |
36 }; | 35 }; |
37 | 36 |
38 } // namespace | 37 } // namespace |
39 | 38 |
40 ChromeBlobStorageContext::ChromeBlobStorageContext() {} | 39 ChromeBlobStorageContext::ChromeBlobStorageContext() {} |
41 | 40 |
42 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( | 41 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( |
43 BrowserContext* context) { | 42 BrowserContext* context) { |
44 if (!context->GetUserData(kBlobStorageContextKeyName)) { | 43 if (!context->GetUserData(kBlobStorageContextKeyName)) { |
45 scoped_refptr<ChromeBlobStorageContext> blob = | 44 scoped_refptr<ChromeBlobStorageContext> blob = |
(...skipping 16 matching lines...) Expand all Loading... | |
62 void ChromeBlobStorageContext::InitializeOnIOThread() { | 61 void ChromeBlobStorageContext::InitializeOnIOThread() { |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
64 context_.reset(new BlobStorageContext()); | 63 context_.reset(new BlobStorageContext()); |
65 } | 64 } |
66 | 65 |
67 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( | 66 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( |
68 const char* data, size_t length) { | 67 const char* data, size_t length) { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
70 | 69 |
71 std::string uuid(base::GenerateGUID()); | 70 std::string uuid(base::GenerateGUID()); |
72 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); | 71 scoped_ptr<storage::BlobDataBuilder> blob_data( |
72 new storage::BlobDataBuilder(uuid)); | |
73 blob_data->AppendData(data, length); | 73 blob_data->AppendData(data, length); |
74 | 74 |
75 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 75 scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle = |
76 context_->AddFinishedBlob(blob_data.get()); | 76 context_->AddFinishedBlob(*blob_data.get()); |
77 if (!blob_data_handle) | 77 if (!blob_data_handle) |
78 return scoped_ptr<BlobHandle>(); | 78 return scoped_ptr<BlobHandle>(); |
79 | 79 |
80 scoped_ptr<BlobHandle> blob_handle( | 80 scoped_ptr<BlobHandle> blob_handle( |
81 new BlobHandleImpl(blob_data_handle.Pass())); | 81 new BlobHandleImpl(blob_data_handle.Pass())); |
82 return blob_handle.Pass(); | 82 return blob_handle.Pass(); |
83 } | 83 } |
84 | 84 |
85 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} | 85 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} |
86 | 86 |
87 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 87 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
88 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 88 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
89 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 89 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
90 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 90 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
91 return; | 91 return; |
92 } | 92 } |
93 delete this; | 93 delete this; |
94 } | 94 } |
95 | 95 |
96 } // namespace content | 96 } // namespace content |
OLD | NEW |