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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 BrowserThread::IO, FROM_HERE, | 53 BrowserThread::IO, FROM_HERE, |
54 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); | 54 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 58 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
59 context, kBlobStorageContextKeyName); | 59 context, kBlobStorageContextKeyName); |
60 } | 60 } |
61 | 61 |
62 void ChromeBlobStorageContext::InitializeOnIOThread() { | 62 void ChromeBlobStorageContext::InitializeOnIOThread() { |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
64 context_.reset(new BlobStorageContext()); | 64 context_.reset(new BlobStorageContext()); |
65 } | 65 } |
66 | 66 |
67 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( | 67 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( |
68 const char* data, size_t length) { | 68 const char* data, size_t length) { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 69 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
70 | 70 |
71 std::string uuid(base::GenerateGUID()); | 71 std::string uuid(base::GenerateGUID()); |
72 storage::BlobDataBuilder blob_data_builder(uuid); | 72 storage::BlobDataBuilder blob_data_builder(uuid); |
73 blob_data_builder.AppendData(data, length); | 73 blob_data_builder.AppendData(data, length); |
74 | 74 |
75 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 75 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
76 context_->AddFinishedBlob(&blob_data_builder); | 76 context_->AddFinishedBlob(&blob_data_builder); |
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 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateFileBackedBlob( | 85 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateFileBackedBlob( |
86 const base::FilePath& path, | 86 const base::FilePath& path, |
87 int64_t offset, | 87 int64_t offset, |
88 int64_t size, | 88 int64_t size, |
89 const base::Time& expected_modification_time) { | 89 const base::Time& expected_modification_time) { |
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
91 | 91 |
92 std::string uuid(base::GenerateGUID()); | 92 std::string uuid(base::GenerateGUID()); |
93 storage::BlobDataBuilder blob_data_builder(uuid); | 93 storage::BlobDataBuilder blob_data_builder(uuid); |
94 blob_data_builder.AppendFile(path, offset, size, expected_modification_time); | 94 blob_data_builder.AppendFile(path, offset, size, expected_modification_time); |
95 | 95 |
96 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 96 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
97 context_->AddFinishedBlob(&blob_data_builder); | 97 context_->AddFinishedBlob(&blob_data_builder); |
98 if (!blob_data_handle) | 98 if (!blob_data_handle) |
99 return scoped_ptr<BlobHandle>(); | 99 return scoped_ptr<BlobHandle>(); |
100 | 100 |
101 scoped_ptr<BlobHandle> blob_handle( | 101 scoped_ptr<BlobHandle> blob_handle( |
102 new BlobHandleImpl(blob_data_handle.Pass())); | 102 new BlobHandleImpl(blob_data_handle.Pass())); |
103 return blob_handle.Pass(); | 103 return blob_handle.Pass(); |
104 } | 104 } |
105 | 105 |
106 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} | 106 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} |
107 | 107 |
108 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 108 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
109 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 109 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
110 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 110 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
111 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 111 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
112 return; | 112 return; |
113 } | 113 } |
114 delete this; | 114 delete this; |
115 } | 115 } |
116 | 116 |
117 } // namespace content | 117 } // namespace content |
OLD | NEW |