OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
| 13 #include "content/public/browser/global_request_id.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // This class manages temporary files for RedirectToFileResourceHandler and the |
| 18 // ResourceDispatcherHost. It vends temporary files for resource requests and |
| 19 // arranges them to be readable by child processes. The TemporaryFileManager |
| 20 // retains references to each temporary on the child process's behalf. When both |
| 21 // the child process and the RedirectToFileResourceHandler have released the |
| 22 // file, it is deleted. |
| 23 class TemporaryFileManager : public RedirectToFileResourceHandler::Delegate { |
| 24 public: |
| 25 TemporaryFileManager(); |
| 26 virtual ~TemporaryFileManager(); |
| 27 |
| 28 // Called when child process |child_id| has released the temporary attached to |
| 29 // |request_id|. |
| 30 void UnregisterDownloadedTempFile(int child_id, int request_id); |
| 31 |
| 32 // Called when child process |child_id| dies. Releases all temporaries managed |
| 33 // by the child. Note: to resolve races where the child dies while a |
| 34 // CreateTemporary is pending, all RedirectToFileResourceHandlers for |
| 35 // |child_id| must be destroyed before calling this function. |
| 36 void UnregisterFilesForChild(int child_id); |
| 37 |
| 38 // RedirectToFileResourceHandler::Delegate implementation: |
| 39 virtual void CreateTemporary( |
| 40 int child_id, |
| 41 int request_id, |
| 42 base::WeakPtr<RedirectToFileResourceHandler> handler) OVERRIDE; |
| 43 |
| 44 private: |
| 45 void DidCreateTemporaryFile( |
| 46 int child_id, |
| 47 int request_id, |
| 48 base::WeakPtr<RedirectToFileResourceHandler> handler, |
| 49 base::PlatformFileError error_code, |
| 50 base::PassPlatformFile file_handle, |
| 51 const base::FilePath& file_path); |
| 52 |
| 53 void RegisterDownloadedTempFile( |
| 54 int child_id, |
| 55 int request_id, |
| 56 webkit_blob::ShareableFileReference* reference); |
| 57 |
| 58 // Collection of temp files downloaded for child processes via |
| 59 // the download_to_file mechanism. We avoid deleting them until |
| 60 // the client no longer needs them. |
| 61 typedef std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> > |
| 62 DeletableFilesMap; // key is request id |
| 63 typedef std::map<int, DeletableFilesMap> |
| 64 RegisteredTempFiles; // key is child process id |
| 65 RegisteredTempFiles registered_temp_files_; |
| 66 |
| 67 base::WeakPtrFactory<TemporaryFileManager> weak_factory_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(TemporaryFileManager); |
| 70 }; |
| 71 |
| 72 } // namespace content |
| 73 |
| 74 #endif // CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_ |
OLD | NEW |