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 "webkit/browser/blob/blob_data_handle.h" | 12 #include "storage/browser/blob/blob_data_handle.h" |
13 #include "webkit/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 webkit_blob::BlobStorageContext; | 16 using storage::BlobStorageContext; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class BlobHandleImpl : public BlobHandle { | 22 class BlobHandleImpl : public BlobHandle { |
23 public: | 23 public: |
24 BlobHandleImpl(scoped_ptr<webkit_blob::BlobDataHandle> handle) | 24 BlobHandleImpl(scoped_ptr<storage::BlobDataHandle> handle) |
25 : handle_(handle.Pass()) { | 25 : handle_(handle.Pass()) {} |
26 } | |
27 | 26 |
28 virtual ~BlobHandleImpl() {} | 27 virtual ~BlobHandleImpl() {} |
29 | 28 |
30 virtual std::string GetUUID() OVERRIDE { | 29 virtual std::string GetUUID() OVERRIDE { |
31 return handle_->uuid(); | 30 return handle_->uuid(); |
32 } | 31 } |
33 | 32 |
34 private: | 33 private: |
35 scoped_ptr<webkit_blob::BlobDataHandle> handle_; | 34 scoped_ptr<storage::BlobDataHandle> handle_; |
36 }; | 35 }; |
37 | 36 |
38 } // namespace | 37 } // namespace |
39 | 38 |
40 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; | 39 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; |
41 | 40 |
42 ChromeBlobStorageContext::ChromeBlobStorageContext() {} | 41 ChromeBlobStorageContext::ChromeBlobStorageContext() {} |
43 | 42 |
44 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( | 43 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( |
45 BrowserContext* context) { | 44 BrowserContext* context) { |
(...skipping 18 matching lines...) Expand all Loading... |
64 void ChromeBlobStorageContext::InitializeOnIOThread() { | 63 void ChromeBlobStorageContext::InitializeOnIOThread() { |
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
66 context_.reset(new BlobStorageContext()); | 65 context_.reset(new BlobStorageContext()); |
67 } | 66 } |
68 | 67 |
69 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( | 68 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( |
70 const char* data, size_t length) { | 69 const char* data, size_t length) { |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
72 | 71 |
73 std::string uuid(base::GenerateGUID()); | 72 std::string uuid(base::GenerateGUID()); |
74 scoped_refptr<webkit_blob::BlobData> blob_data = | 73 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); |
75 new webkit_blob::BlobData(uuid); | |
76 blob_data->AppendData(data, length); | 74 blob_data->AppendData(data, length); |
77 | 75 |
78 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle = | 76 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
79 context_->AddFinishedBlob(blob_data.get()); | 77 context_->AddFinishedBlob(blob_data.get()); |
80 if (!blob_data_handle) | 78 if (!blob_data_handle) |
81 return scoped_ptr<BlobHandle>(); | 79 return scoped_ptr<BlobHandle>(); |
82 | 80 |
83 scoped_ptr<BlobHandle> blob_handle( | 81 scoped_ptr<BlobHandle> blob_handle( |
84 new BlobHandleImpl(blob_data_handle.Pass())); | 82 new BlobHandleImpl(blob_data_handle.Pass())); |
85 return blob_handle.Pass(); | 83 return blob_handle.Pass(); |
86 } | 84 } |
87 | 85 |
88 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} | 86 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} |
89 | 87 |
90 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 88 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
91 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 89 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
92 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 90 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
93 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 91 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
94 return; | 92 return; |
95 } | 93 } |
96 delete this; | 94 delete this; |
97 } | 95 } |
98 | 96 |
99 } // namespace content | 97 } // namespace content |
OLD | NEW |