| 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/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "storage/browser/blob/blob_memory_controller.h" | 28 #include "storage/browser/blob/blob_memory_controller.h" |
| 29 #include "storage/browser/blob/blob_storage_context.h" | 29 #include "storage/browser/blob/blob_storage_context.h" |
| 30 | 30 |
| 31 using base::FilePath; | 31 using base::FilePath; |
| 32 using base::UserDataAdapter; | 32 using base::UserDataAdapter; |
| 33 using storage::BlobStorageContext; | 33 using storage::BlobStorageContext; |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 const FilePath::CharType kBlobStorageContextKeyName[] = | 38 // FIXME: Identical to the constant in resource_context_impl.cc |
| 39 const FilePath::CharType kBlobStorageContextKeyNameFoo[] = |
| 39 FILE_PATH_LITERAL("content_blob_storage_context"); | 40 FILE_PATH_LITERAL("content_blob_storage_context"); |
| 40 const FilePath::CharType kBlobStorageParentDirectory[] = | 41 const FilePath::CharType kBlobStorageParentDirectory[] = |
| 41 FILE_PATH_LITERAL("blob_storage"); | 42 FILE_PATH_LITERAL("blob_storage"); |
| 42 | 43 |
| 43 // Removes all folders in the parent directory except for the | 44 // Removes all folders in the parent directory except for the |
| 44 // |current_run_dir| folder. If this path is empty, then we delete all folders. | 45 // |current_run_dir| folder. If this path is empty, then we delete all folders. |
| 45 void RemoveOldBlobStorageDirectories(FilePath blob_storage_parent, | 46 void RemoveOldBlobStorageDirectories(FilePath blob_storage_parent, |
| 46 const FilePath& current_run_dir) { | 47 const FilePath& current_run_dir) { |
| 47 if (!base::DirectoryExists(blob_storage_parent)) { | 48 if (!base::DirectoryExists(blob_storage_parent)) { |
| 48 return; | 49 return; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 } // namespace | 78 } // namespace |
| 78 | 79 |
| 79 ChromeBlobStorageContext::ChromeBlobStorageContext() {} | 80 ChromeBlobStorageContext::ChromeBlobStorageContext() {} |
| 80 | 81 |
| 81 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( | 82 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( |
| 82 BrowserContext* context) { | 83 BrowserContext* context) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 84 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 84 | 85 |
| 85 if (!context->GetUserData(kBlobStorageContextKeyName)) { | 86 if (!context->GetUserData(kBlobStorageContextKeyNameFoo)) { |
| 86 scoped_refptr<ChromeBlobStorageContext> blob = | 87 scoped_refptr<ChromeBlobStorageContext> blob = |
| 87 new ChromeBlobStorageContext(); | 88 new ChromeBlobStorageContext(); |
| 88 context->SetUserData( | 89 context->SetUserData( |
| 89 kBlobStorageContextKeyName, | 90 kBlobStorageContextKeyNameFoo, |
| 90 base::MakeUnique<UserDataAdapter<ChromeBlobStorageContext>>( | 91 base::MakeUnique<UserDataAdapter<ChromeBlobStorageContext>>( |
| 91 blob.get())); | 92 blob.get())); |
| 92 | 93 |
| 93 // Check first to avoid memory leak in unittests. | 94 // Check first to avoid memory leak in unittests. |
| 94 bool io_thread_valid = BrowserThread::IsMessageLoopValid(BrowserThread::IO); | 95 bool io_thread_valid = BrowserThread::IsMessageLoopValid(BrowserThread::IO); |
| 95 | 96 |
| 96 // Resolve our storage directories. | 97 // Resolve our storage directories. |
| 97 FilePath blob_storage_parent = | 98 FilePath blob_storage_parent = |
| 98 context->GetPath().Append(kBlobStorageParentDirectory); | 99 context->GetPath().Append(kBlobStorageParentDirectory); |
| 99 FilePath blob_storage_dir = blob_storage_parent.Append( | 100 FilePath blob_storage_dir = blob_storage_parent.Append( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 119 if (io_thread_valid) { | 120 if (io_thread_valid) { |
| 120 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 121 BrowserThread::IO, FROM_HERE, | 122 BrowserThread::IO, FROM_HERE, |
| 122 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob, | 123 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob, |
| 123 base::Passed(&blob_storage_dir), | 124 base::Passed(&blob_storage_dir), |
| 124 base::Passed(&file_task_runner))); | 125 base::Passed(&file_task_runner))); |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 129 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 129 context, kBlobStorageContextKeyName); | 130 context, kBlobStorageContextKeyNameFoo); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void ChromeBlobStorageContext::InitializeOnIOThread( | 133 void ChromeBlobStorageContext::InitializeOnIOThread( |
| 133 FilePath blob_storage_dir, | 134 FilePath blob_storage_dir, |
| 134 scoped_refptr<base::TaskRunner> file_task_runner) { | 135 scoped_refptr<base::TaskRunner> file_task_runner) { |
| 135 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 136 context_.reset(new BlobStorageContext(std::move(blob_storage_dir), | 137 context_.reset(new BlobStorageContext(std::move(blob_storage_dir), |
| 137 std::move(file_task_runner))); | 138 std::move(file_task_runner))); |
| 138 // Signal the BlobMemoryController when it's appropriate to calculate its | 139 // Signal the BlobMemoryController when it's appropriate to calculate its |
| 139 // storage limits. | 140 // storage limits. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 std::unique_ptr<storage::BlobDataHandle> handle = | 218 std::unique_ptr<storage::BlobDataHandle> handle = |
| 218 blob_context->GetBlobDataFromUUID(element.blob_uuid()); | 219 blob_context->GetBlobDataFromUUID(element.blob_uuid()); |
| 219 if (!handle) | 220 if (!handle) |
| 220 return false; | 221 return false; |
| 221 blob_handles->push_back(std::move(handle)); | 222 blob_handles->push_back(std::move(handle)); |
| 222 } | 223 } |
| 223 return true; | 224 return true; |
| 224 } | 225 } |
| 225 | 226 |
| 226 } // namespace content | 227 } // namespace content |
| OLD | NEW |