OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chrome_blob_storage_context.h" | 5 #include "content/browser/chrome_blob_storage_context.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/public/browser/browser_context.h" |
7 #include "webkit/blob/blob_storage_controller.h" | 9 #include "webkit/blob/blob_storage_controller.h" |
8 | 10 |
| 11 using base::UserDataAdapter; |
| 12 using content::BrowserContext; |
9 using content::BrowserThread; | 13 using content::BrowserThread; |
10 using webkit_blob::BlobStorageController; | 14 using webkit_blob::BlobStorageController; |
11 | 15 |
| 16 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; |
| 17 |
| 18 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( |
| 19 BrowserContext* context) { |
| 20 if (!context->GetUserData(kBlobStorageContextKeyName)) { |
| 21 scoped_refptr<ChromeBlobStorageContext> blob = |
| 22 new ChromeBlobStorageContext(); |
| 23 BrowserThread::PostTask( |
| 24 BrowserThread::IO, FROM_HERE, |
| 25 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); |
| 26 context->SetUserData(kBlobStorageContextKeyName, |
| 27 new UserDataAdapter<ChromeBlobStorageContext>(blob)); |
| 28 } |
| 29 |
| 30 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 31 context, kBlobStorageContextKeyName); |
| 32 } |
| 33 |
12 ChromeBlobStorageContext::ChromeBlobStorageContext() { | 34 ChromeBlobStorageContext::ChromeBlobStorageContext() { |
13 } | 35 } |
14 | 36 |
15 void ChromeBlobStorageContext::InitializeOnIOThread() { | 37 void ChromeBlobStorageContext::InitializeOnIOThread() { |
16 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
17 controller_.reset(new BlobStorageController()); | 39 controller_.reset(new BlobStorageController()); |
18 } | 40 } |
19 | 41 |
20 ChromeBlobStorageContext::~ChromeBlobStorageContext() { | 42 ChromeBlobStorageContext::~ChromeBlobStorageContext() { |
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
22 } | 44 } |
OLD | NEW |