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