| 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/blob_storage/chrome_blob_storage_context.h" | 5 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "content/public/browser/blob_handle.h" | 19 #include "content/public/browser/blob_handle.h" |
| 19 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "storage/browser/blob/blob_data_builder.h" | 22 #include "storage/browser/blob/blob_data_builder.h" |
| 22 #include "storage/browser/blob/blob_data_handle.h" | 23 #include "storage/browser/blob/blob_data_handle.h" |
| 23 #include "storage/browser/blob/blob_memory_controller.h" | 24 #include "storage/browser/blob/blob_memory_controller.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 74 |
| 74 ChromeBlobStorageContext::ChromeBlobStorageContext() {} | 75 ChromeBlobStorageContext::ChromeBlobStorageContext() {} |
| 75 | 76 |
| 76 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( | 77 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( |
| 77 BrowserContext* context) { | 78 BrowserContext* context) { |
| 78 if (!context->GetUserData(kBlobStorageContextKeyName)) { | 79 if (!context->GetUserData(kBlobStorageContextKeyName)) { |
| 79 scoped_refptr<ChromeBlobStorageContext> blob = | 80 scoped_refptr<ChromeBlobStorageContext> blob = |
| 80 new ChromeBlobStorageContext(); | 81 new ChromeBlobStorageContext(); |
| 81 context->SetUserData( | 82 context->SetUserData( |
| 82 kBlobStorageContextKeyName, | 83 kBlobStorageContextKeyName, |
| 83 new UserDataAdapter<ChromeBlobStorageContext>(blob.get())); | 84 base::MakeUnique<UserDataAdapter<ChromeBlobStorageContext>>( |
| 85 blob.get())); |
| 84 | 86 |
| 85 // Check first to avoid memory leak in unittests. | 87 // Check first to avoid memory leak in unittests. |
| 86 bool io_thread_valid = BrowserThread::IsMessageLoopValid(BrowserThread::IO); | 88 bool io_thread_valid = BrowserThread::IsMessageLoopValid(BrowserThread::IO); |
| 87 | 89 |
| 88 // Resolve our storage directories. | 90 // Resolve our storage directories. |
| 89 FilePath blob_storage_parent = | 91 FilePath blob_storage_parent = |
| 90 context->GetPath().Append(kBlobStorageParentDirectory); | 92 context->GetPath().Append(kBlobStorageParentDirectory); |
| 91 FilePath blob_storage_dir = blob_storage_parent.Append( | 93 FilePath blob_storage_dir = blob_storage_parent.Append( |
| 92 FilePath::FromUTF8Unsafe(base::GenerateGUID())); | 94 FilePath::FromUTF8Unsafe(base::GenerateGUID())); |
| 93 | 95 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { | 182 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { |
| 181 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 183 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
| 182 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 184 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 183 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 185 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
| 184 return; | 186 return; |
| 185 } | 187 } |
| 186 delete this; | 188 delete this; |
| 187 } | 189 } |
| 188 | 190 |
| 189 } // namespace content | 191 } // namespace content |
| OLD | NEW |