| 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..0be796d2de18c2a136ce782092aa6eeeb2365b97
|
| --- /dev/null
|
| +++ b/content/browser/loader/temporary_file_manager.h
|
| @@ -0,0 +1,70 @@
|
| +// 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 child processes.
|
| +class TemporaryFileManager : public TemporaryFileStreamFactory {
|
| + public:
|
| + TemporaryFileManager();
|
| + virtual ~TemporaryFileManager();
|
| +
|
| + base::WeakPtr<TemporaryFileManager> AsWeakPtr() {
|
| + return weak_factory_.GetWeakPtr();
|
| + }
|
| +
|
| + void UnregisterDownloadedTempFile(int child_id, int request_id);
|
| + 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.
|
| + 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_
|
|
|