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

Side by Side Diff: chrome/browser/download/download_file_manager.h

Issue 3348010: Revert 58196 - GTTF: Clean up DownloadFileManager... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 3 months 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // The DownloadFileManager owns a set of DownloadFile objects, each of which 5 // The DownloadFileManager owns a set of DownloadFile objects, each of which
6 // represent one in progress download and performs the disk IO for that 6 // represent one in progress download and performs the disk IO for that
7 // download. The DownloadFileManager itself is a singleton object owned by the 7 // download. The DownloadFileManager itself is a singleton object owned by the
8 // ResourceDispatcherHost. 8 // ResourceDispatcherHost.
9 // 9 //
10 // The DownloadFileManager uses the file_thread for performing file write 10 // The DownloadFileManager uses the file_thread for performing file write
(...skipping 26 matching lines...) Expand all
37 // DownloadManager that exits (such as when closing a profile). 37 // DownloadManager that exits (such as when closing a profile).
38 38
39 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 39 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_
40 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 40 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_
41 #pragma once 41 #pragma once
42 42
43 #include <map> 43 #include <map>
44 44
45 #include "base/basictypes.h" 45 #include "base/basictypes.h"
46 #include "base/hash_tables.h" 46 #include "base/hash_tables.h"
47 #include "base/lock.h"
47 #include "base/ref_counted.h" 48 #include "base/ref_counted.h"
48 #include "base/timer.h" 49 #include "base/timer.h"
49 #include "gfx/native_widget_types.h" 50 #include "gfx/native_widget_types.h"
50 51
51 struct DownloadBuffer; 52 struct DownloadBuffer;
52 struct DownloadCreateInfo; 53 struct DownloadCreateInfo;
53 struct DownloadSaveInfo; 54 struct DownloadSaveInfo;
54 class DownloadFile; 55 class DownloadFile;
55 class DownloadManager; 56 class DownloadManager;
56 class FilePath; 57 class FilePath;
(...skipping 10 matching lines...) Expand all
67 68
68 public: 69 public:
69 explicit DownloadFileManager(ResourceDispatcherHost* rdh); 70 explicit DownloadFileManager(ResourceDispatcherHost* rdh);
70 71
71 // Called on shutdown on the UI thread. 72 // Called on shutdown on the UI thread.
72 void Shutdown(); 73 void Shutdown();
73 74
74 // Called on the IO thread 75 // Called on the IO thread
75 int GetNextId(); 76 int GetNextId();
76 77
77 // Called on UI thread to make DownloadFileManager start the download.
78 void StartDownload(DownloadCreateInfo* info);
79
80 // Handlers for notifications sent from the IO thread and run on the 78 // Handlers for notifications sent from the IO thread and run on the
81 // download thread. 79 // download thread.
80 void StartDownload(DownloadCreateInfo* info);
82 void UpdateDownload(int id, DownloadBuffer* buffer); 81 void UpdateDownload(int id, DownloadBuffer* buffer);
83 void CancelDownload(int id); 82 void CancelDownload(int id);
84 void DownloadFinished(int id, DownloadBuffer* buffer); 83 void DownloadFinished(int id, DownloadBuffer* buffer);
85 84
86 // Called on FILE thread by DownloadManager at the beginning of its shutdown. 85 // Called on the UI thread to remove a download item or manager.
87 void OnDownloadManagerShutdown(DownloadManager* manager); 86 void RemoveDownloadManager(DownloadManager* manager);
87 void RemoveDownload(int id, DownloadManager* manager);
88 88
89 #if !defined(OS_MACOSX) 89 #if !defined(OS_MACOSX)
90 // The open and show methods run on the file thread, which does not work on 90 // The open and show methods run on the file thread, which does not work on
91 // Mac OS X (which uses the UI thread for opens). 91 // Mac OS X (which uses the UI thread for opens).
92 92
93 // Handler for shell operations sent from the UI to the download thread. 93 // Handler for shell operations sent from the UI to the download thread.
94 void OnShowDownloadInShell(const FilePath& full_path); 94 void OnShowDownloadInShell(const FilePath& full_path);
95 95
96 // Handler to open or execute a downloaded file. 96 // Handler to open or execute a downloaded file.
97 void OnOpenDownloadInShell(const FilePath& full_path, 97 void OnOpenDownloadInShell(const FilePath& full_path,
(...skipping 20 matching lines...) Expand all
118 ~DownloadFileManager(); 118 ~DownloadFileManager();
119 119
120 // Timer helpers for updating the UI about the current progress of a download. 120 // Timer helpers for updating the UI about the current progress of a download.
121 void StartUpdateTimer(); 121 void StartUpdateTimer();
122 void StopUpdateTimer(); 122 void StopUpdateTimer();
123 void UpdateInProgressDownloads(); 123 void UpdateInProgressDownloads();
124 124
125 // Clean up helper that runs on the download thread. 125 // Clean up helper that runs on the download thread.
126 void OnShutdown(); 126 void OnShutdown();
127 127
128 // Creates DownloadFile on FILE thread and continues starting the download 128 // Handlers for notifications sent from the download thread and run on
129 // process. 129 // the UI thread.
130 void CreateDownloadFile(DownloadCreateInfo* info, 130 void OnStartDownload(DownloadCreateInfo* info);
131 DownloadManager* download_manager); 131 void OnDownloadFinished(int id, int64 bytes_so_far);
132
133 // Called only on UI thread to get the DownloadManager for a tab's profile.
134 static DownloadManager* DownloadManagerFromRenderIds(int render_process_id,
135 int review_view_id);
136 DownloadManager* GetDownloadManager(int download_id);
132 137
133 // Called only on the download thread. 138 // Called only on the download thread.
134 DownloadFile* GetDownloadFile(int id); 139 DownloadFile* GetDownloadFile(int id);
135 140
141 // Called on the UI thread to remove a download from the UI progress table.
142 void RemoveDownloadFromUIProgress(int id);
143
136 // Called only from OnFinalDownloadName or OnIntermediateDownloadName 144 // Called only from OnFinalDownloadName or OnIntermediateDownloadName
137 // on the FILE thread. 145 // on the FILE thread.
138 void CancelDownloadOnRename(int id); 146 void CancelDownloadOnRename(int id);
139 147
140 // Unique ID for each DownloadFile. 148 // Unique ID for each DownloadFile.
141 int next_id_; 149 int next_id_;
142 150
143 // A map of all in progress downloads. 151 // A map of all in progress downloads.
144 typedef base::hash_map<int, DownloadFile*> DownloadFileMap; 152 typedef base::hash_map<int, DownloadFile*> DownloadFileMap;
145 DownloadFileMap downloads_; 153 DownloadFileMap downloads_;
146 154
147 // Schedule periodic updates of the download progress. This timer 155 // Throttle updates to the UI thread.
148 // is controlled from the FILE thread, and posts updates to the UI thread.
149 base::RepeatingTimer<DownloadFileManager> update_timer_; 156 base::RepeatingTimer<DownloadFileManager> update_timer_;
150 157
151 ResourceDispatcherHost* resource_dispatcher_host_; 158 ResourceDispatcherHost* resource_dispatcher_host_;
152 159
160 // Tracking which DownloadManager to send data to, called only on UI thread.
161 // DownloadManagerMap maps download IDs to their DownloadManager.
162 typedef base::hash_map<int, DownloadManager*> DownloadManagerMap;
163 DownloadManagerMap managers_;
164
165 // RequestMap maps a DownloadManager to all in-progress download IDs.
166 // Called only on the UI thread.
167 typedef base::hash_set<int> DownloadRequests;
168 typedef std::map<DownloadManager*, DownloadRequests> RequestMap;
169 RequestMap requests_;
170
171 // Used for progress updates on the UI thread, mapping download->id() to bytes
172 // received so far. Written to by the file thread and read by the UI thread.
173 typedef base::hash_map<int, int64> ProgressMap;
174 ProgressMap ui_progress_;
175 Lock progress_lock_;
176
153 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); 177 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager);
154 }; 178 };
155 179
156 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 180 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/download_file.cc ('k') | chrome/browser/download/download_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698