| 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 "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 9 #include "webkit/blob/blob_storage_controller.h" | 9 #include "webkit/blob/blob_storage_controller.h" |
| 10 | 10 |
| 11 using base::UserDataAdapter; | 11 using base::UserDataAdapter; |
| 12 using content::BrowserContext; | 12 using content::BrowserContext; |
| 13 using content::BrowserThread; | 13 using content::BrowserThread; |
| 14 using webkit_blob::BlobStorageController; | 14 using webkit_blob::BlobStorageController; |
| 15 | 15 |
| 16 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; | 16 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; |
| 17 | 17 |
| 18 ChromeBlobStorageContext::ChromeBlobStorageContext() {} |
| 19 |
| 18 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( | 20 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( |
| 19 BrowserContext* context) { | 21 BrowserContext* context) { |
| 20 if (!context->GetUserData(kBlobStorageContextKeyName)) { | 22 if (!context->GetUserData(kBlobStorageContextKeyName)) { |
| 21 scoped_refptr<ChromeBlobStorageContext> blob = | 23 scoped_refptr<ChromeBlobStorageContext> blob = |
| 22 new ChromeBlobStorageContext(); | 24 new ChromeBlobStorageContext(); |
| 23 context->SetUserData(kBlobStorageContextKeyName, | 25 context->SetUserData(kBlobStorageContextKeyName, |
| 24 new UserDataAdapter<ChromeBlobStorageContext>(blob)); | 26 new UserDataAdapter<ChromeBlobStorageContext>(blob)); |
| 25 // Check first to avoid memory leak in unittests. | 27 // Check first to avoid memory leak in unittests. |
| 26 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 28 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 27 BrowserThread::PostTask( | 29 BrowserThread::PostTask( |
| 28 BrowserThread::IO, FROM_HERE, | 30 BrowserThread::IO, FROM_HERE, |
| 29 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); | 31 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); |
| 30 } | 32 } |
| 31 } | 33 } |
| 32 | 34 |
| 33 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 35 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 34 context, kBlobStorageContextKeyName); | 36 context, kBlobStorageContextKeyName); |
| 35 } | 37 } |
| 36 | 38 |
| 37 ChromeBlobStorageContext::ChromeBlobStorageContext() { | |
| 38 } | |
| 39 | |
| 40 void ChromeBlobStorageContext::InitializeOnIOThread() { | 39 void ChromeBlobStorageContext::InitializeOnIOThread() { |
| 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 42 controller_.reset(new BlobStorageController()); | 41 controller_.reset(new BlobStorageController()); |
| 43 } | 42 } |
| 44 | 43 |
| 45 ChromeBlobStorageContext::~ChromeBlobStorageContext() { | 44 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} |
| 46 } | |
| 47 | 45 |
| 48 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 46 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
| 49 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 47 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
| 50 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 48 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 51 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 49 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
| 52 return; | 50 return; |
| 53 } | 51 } |
| 54 delete this; | 52 delete this; |
| 55 } | 53 } |
| OLD | NEW |