OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/chrome_blob_storage_context.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "content/public/browser/browser_context.h" | |
9 #include "webkit/blob/blob_storage_controller.h" | |
10 | |
11 using base::UserDataAdapter; | |
12 using content::BrowserContext; | |
13 using content::BrowserThread; | |
14 using webkit_blob::BlobStorageController; | |
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 context->SetUserData(kBlobStorageContextKeyName, | |
24 new UserDataAdapter<ChromeBlobStorageContext>(blob)); | |
25 // Check first to avoid memory leak in unittests. | |
26 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | |
27 BrowserThread::PostTask( | |
28 BrowserThread::IO, FROM_HERE, | |
29 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); | |
30 } | |
31 } | |
32 | |
33 return UserDataAdapter<ChromeBlobStorageContext>::Get( | |
34 context, kBlobStorageContextKeyName); | |
35 } | |
36 | |
37 ChromeBlobStorageContext::ChromeBlobStorageContext() { | |
38 } | |
39 | |
40 void ChromeBlobStorageContext::InitializeOnIOThread() { | |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
42 controller_.reset(new BlobStorageController()); | |
43 } | |
44 | |
45 ChromeBlobStorageContext::~ChromeBlobStorageContext() { | |
46 } | |
47 | |
48 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | |
49 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | |
50 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
51 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | |
52 return; | |
53 } | |
54 delete this; | |
55 } | |
OLD | NEW |