Chromium Code Reviews| Index: content/browser/loader/temporary_file_manager.h |
| diff --git a/content/browser/loader/temporary_file_manager.h b/content/browser/loader/temporary_file_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cdb8a12dc267caafb216e518ffe0b30b6be5d521 |
| --- /dev/null |
| +++ b/content/browser/loader/temporary_file_manager.h |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_ |
| +#define CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "content/browser/loader/redirect_to_file_resource_handler.h" |
| +#include "content/public/browser/global_request_id.h" |
| + |
| +namespace content { |
| + |
| +// This class manages temporary files for RedirectToFileResourceHandler and the |
| +// ResourceDispatcherHost. It vends temporary files for resource requests and |
| +// arranges them to be readable by child processes. The TemporaryFileManager |
| +// retains references to each temporary on the child process's behalf. When both |
| +// the child process and the RedirectToFileResourceHandler have released the |
| +// file, it is deleted. |
| +class TemporaryFileManager : public TemporaryFileStreamFactory { |
| + public: |
| + TemporaryFileManager(); |
| + virtual ~TemporaryFileManager(); |
| + |
| + base::WeakPtr<TemporaryFileManager> AsWeakPtr() { |
| + return weak_factory_.GetWeakPtr(); |
| + } |
| + |
| + // Called when child process |child_id| has released the temporary attached to |
| + // |request_id|. |
| + void UnregisterDownloadedTempFile(int child_id, int request_id); |
| + |
| + // Called when child process |child_id| dies. Releases all temporaries managed |
| + // by the child. |
| + void UnregisterFilesForChild(int child_id); |
| + |
| + // TemporaryFileStreamFactory implementation: |
| + virtual void CreateTemporary( |
| + int child_id, |
| + int request_id, |
| + const TemporaryFileStreamFactory::Callback& callback) OVERRIDE; |
| + |
| + private: |
| + struct PendingTemporary; |
| + |
| + void DidCreateTemporaryFile(PendingTemporary* pending, |
| + base::PlatformFileError error_code, |
| + base::PassPlatformFile file_handle, |
| + const base::FilePath& file_path); |
| + |
| + void RegisterDownloadedTempFile( |
| + int child_id, |
| + int request_id, |
| + webkit_blob::ShareableFileReference* reference); |
| + |
| + // Collection of temp files downloaded for child processes via |
| + // the download_to_file mechanism. We avoid deleting them until |
| + // the client no longer needs them. |
| + typedef std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> > |
| + DeletableFilesMap; // key is request id |
| + typedef std::map<int, DeletableFilesMap> |
| + RegisteredTempFiles; // key is child process id |
| + RegisteredTempFiles registered_temp_files_; |
| + |
| + // Collection of pending requests, to resolve races where |
| + // UnregisterFilesForChild or UnregisterDownloadedTempFile are called while a |
| + // CreateTemporary is in flight. |
|
mmenke
2013/12/04 20:55:48
optional: May be worth noting that if we have yet
davidben
2013/12/04 22:44:04
Done. Also reordered DetachableResourceHandler and
mmenke
2013/12/05 21:34:03
I was actually thinking about the destroyed before
|
| + typedef std::map<GlobalRequestID, PendingTemporary*> PendingTemporaryMap; |
| + PendingTemporaryMap pending_temporary_map_; |
| + |
| + base::WeakPtrFactory<TemporaryFileManager> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TemporaryFileManager); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_ |