| 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..efafb09ca41d9313b5fba0d4b5efe0134b91745b
|
| --- /dev/null
|
| +++ b/content/browser/loader/temporary_file_manager.h
|
| @@ -0,0 +1,74 @@
|
| +// 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/compiler_specific.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 RedirectToFileResourceHandler::Delegate {
|
| + public:
|
| + TemporaryFileManager();
|
| + virtual ~TemporaryFileManager();
|
| +
|
| + // 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. Note: to resolve races where the child dies while a
|
| + // CreateTemporary is pending, all RedirectToFileResourceHandlers for
|
| + // |child_id| must be destroyed before calling this function.
|
| + void UnregisterFilesForChild(int child_id);
|
| +
|
| + // RedirectToFileResourceHandler::Delegate implementation:
|
| + virtual void CreateTemporary(
|
| + int child_id,
|
| + int request_id,
|
| + base::WeakPtr<RedirectToFileResourceHandler> handler) OVERRIDE;
|
| +
|
| + private:
|
| + void DidCreateTemporaryFile(
|
| + int child_id,
|
| + int request_id,
|
| + base::WeakPtr<RedirectToFileResourceHandler> handler,
|
| + 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_;
|
| +
|
| + base::WeakPtrFactory<TemporaryFileManager> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TemporaryFileManager);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_
|
|
|