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 TemporaryFileStreamFactory { | |
23 public: | |
24 TemporaryFileManager(); | |
25 virtual ~TemporaryFileManager(); | |
26 | |
27 base::WeakPtr<TemporaryFileManager> AsWeakPtr() { | |
28 return weak_factory_.GetWeakPtr(); | |
29 } | |
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. | |
37 void UnregisterFilesForChild(int child_id); | |
38 | |
39 // TemporaryFileStreamFactory implementation: | |
40 virtual void CreateTemporary( | |
41 int child_id, | |
42 int request_id, | |
43 const TemporaryFileStreamFactory::Callback& callback) OVERRIDE; | |
44 | |
45 private: | |
46 struct PendingTemporary; | |
47 | |
48 void DidCreateTemporaryFile(PendingTemporary* pending, | |
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 // Collection of pending requests, to resolve races where | |
68 // UnregisterFilesForChild or UnregisterDownloadedTempFile are called while a | |
69 // 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
| |
70 typedef std::map<GlobalRequestID, PendingTemporary*> PendingTemporaryMap; | |
71 PendingTemporaryMap pending_temporary_map_; | |
72 | |
73 base::WeakPtrFactory<TemporaryFileManager> weak_factory_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(TemporaryFileManager); | |
76 }; | |
77 | |
78 } // namespace content | |
79 | |
80 #endif // CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_ | |
OLD | NEW |