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