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
3 // found in the LICENSE file.
5 #include "content/browser/fileapi/chrome_blob_storage_context.h"
8 #include "content/public/browser/browser_context.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "webkit/browser/blob/blob_storage_context.h"
12 using base::UserDataAdapter
;
13 using webkit_blob::BlobStorageContext
;
17 static const char* kBlobStorageContextKeyName
= "content_blob_storage_context";
19 ChromeBlobStorageContext::ChromeBlobStorageContext() {}
21 ChromeBlobStorageContext
* ChromeBlobStorageContext::GetFor(
22 BrowserContext
* context
) {
23 if (!context
->GetUserData(kBlobStorageContextKeyName
)) {
24 scoped_refptr
<ChromeBlobStorageContext
> blob
=
25 new ChromeBlobStorageContext();
27 kBlobStorageContextKeyName
,
28 new UserDataAdapter
<ChromeBlobStorageContext
>(blob
.get()));
29 // Check first to avoid memory leak in unittests.
30 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
)) {
31 BrowserThread::PostTask(
32 BrowserThread::IO
, FROM_HERE
,
33 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread
, blob
));
37 return UserDataAdapter
<ChromeBlobStorageContext
>::Get(
38 context
, kBlobStorageContextKeyName
);
41 void ChromeBlobStorageContext::InitializeOnIOThread() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
43 context_
.reset(new BlobStorageContext());
46 ChromeBlobStorageContext::~ChromeBlobStorageContext() {}
48 void ChromeBlobStorageContext::DeleteOnCorrectThread() const {
49 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
) &&
50 !BrowserThread::CurrentlyOn(BrowserThread::IO
)) {
51 BrowserThread::DeleteSoon(BrowserThread::IO
, FROM_HERE
, this);
57 } // namespace content