Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: content/browser/loader/temporary_file_manager.h

Issue 82273002: Fix various issues in RedirectToFileResourceHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: UUUUNIT TESTS Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 child processes.
17 class TemporaryFileManager : public TemporaryFileStreamFactory {
18 public:
19 TemporaryFileManager();
20 virtual ~TemporaryFileManager();
21
22 base::WeakPtr<TemporaryFileManager> AsWeakPtr() {
23 return weak_factory_.GetWeakPtr();
24 }
25
26 void UnregisterDownloadedTempFile(int child_id, int request_id);
27 void UnregisterFilesForChild(int child_id);
28
29 // TemporaryFileStreamFactory implementation:
30 virtual void CreateTemporary(
31 int child_id,
32 int request_id,
33 const TemporaryFileStreamFactory::Callback& callback) OVERRIDE;
34
35 private:
36 struct PendingTemporary;
37
38 void DidCreateTemporaryFile(PendingTemporary* pending,
39 base::PlatformFileError error_code,
40 base::PassPlatformFile file_handle,
41 const base::FilePath& file_path);
42
43 void RegisterDownloadedTempFile(
44 int child_id,
45 int request_id,
46 webkit_blob::ShareableFileReference* reference);
47
48 // Collection of temp files downloaded for child processes via
49 // the download_to_file mechanism. We avoid deleting them until
50 // the client no longer needs them.
51 typedef std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> >
52 DeletableFilesMap; // key is request id
53 typedef std::map<int, DeletableFilesMap>
54 RegisteredTempFiles; // key is child process id
55 RegisteredTempFiles registered_temp_files_;
56
57 // Collection of pending requests, to resolve races where
58 // UnregisterFilesForChild or UnregisterDownloadedTempFile are called while a
59 // CreateTemporary is in flight.
60 typedef std::map<GlobalRequestID, PendingTemporary*> PendingTemporaryMap;
61 PendingTemporaryMap pending_temporary_map_;
62
63 base::WeakPtrFactory<TemporaryFileManager> weak_factory_;
64
65 DISALLOW_COPY_AND_ASSIGN(TemporaryFileManager);
66 };
67
68 } // namespace content
69
70 #endif // CONTENT_BROWSER_LOADER_TEMPORARY_FILE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698