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

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

Issue 3245005: GTTF: Clean up DownloadFileManager (Closed)
Patch Set: fixes 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
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"
48 #include "base/ref_counted.h" 47 #include "base/ref_counted.h"
49 #include "base/timer.h" 48 #include "base/timer.h"
50 #include "gfx/native_widget_types.h" 49 #include "gfx/native_widget_types.h"
51 50
52 struct DownloadBuffer; 51 struct DownloadBuffer;
53 struct DownloadCreateInfo; 52 struct DownloadCreateInfo;
54 struct DownloadSaveInfo; 53 struct DownloadSaveInfo;
55 class DownloadFile; 54 class DownloadFile;
56 class DownloadManager; 55 class DownloadManager;
57 class FilePath; 56 class FilePath;
(...skipping 10 matching lines...) Expand all
68 67
69 public: 68 public:
70 explicit DownloadFileManager(ResourceDispatcherHost* rdh); 69 explicit DownloadFileManager(ResourceDispatcherHost* rdh);
71 70
72 // Called on shutdown on the UI thread. 71 // Called on shutdown on the UI thread.
73 void Shutdown(); 72 void Shutdown();
74 73
75 // Called on the IO thread 74 // Called on the IO thread
76 int GetNextId(); 75 int GetNextId();
77 76
77 // Called on UI thread to make DownloadFileManager start the download.
78 void StartDownload(DownloadCreateInfo* info);
79
78 // Handlers for notifications sent from the IO thread and run on the 80 // Handlers for notifications sent from the IO thread and run on the
79 // download thread. 81 // download thread.
80 void StartDownload(DownloadCreateInfo* info);
81 void UpdateDownload(int id, DownloadBuffer* buffer); 82 void UpdateDownload(int id, DownloadBuffer* buffer);
82 void CancelDownload(int id); 83 void CancelDownload(int id);
83 void DownloadFinished(int id, DownloadBuffer* buffer); 84 void DownloadFinished(int id, DownloadBuffer* buffer);
84 85
85 // Called on the UI thread to remove a download item or manager. 86 // Called on FILE thread by DownloadManager at the beginning of its shutdown.
86 void RemoveDownloadManager(DownloadManager* manager); 87 void OnDownloadManagerShutdown(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 // Handlers for notifications sent from the download thread and run on 128 // Creates DownloadFile on FILE thread and continues starting the download
129 // the UI thread. 129 // process.
130 void OnStartDownload(DownloadCreateInfo* info); 130 void CreateDownloadFile(DownloadCreateInfo* info,
131 void OnDownloadFinished(int id, int64 bytes_so_far); 131 DownloadManager* download_manager);
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);
137 132
138 // Called only on the download thread. 133 // Called only on the download thread.
139 DownloadFile* GetDownloadFile(int id); 134 DownloadFile* GetDownloadFile(int id);
140 135
141 // Called on the UI thread to remove a download from the UI progress table.
142 void RemoveDownloadFromUIProgress(int id);
143
144 // Called only from OnFinalDownloadName or OnIntermediateDownloadName 136 // Called only from OnFinalDownloadName or OnIntermediateDownloadName
145 // on the FILE thread. 137 // on the FILE thread.
146 void CancelDownloadOnRename(int id); 138 void CancelDownloadOnRename(int id);
147 139
148 // Unique ID for each DownloadFile. 140 // Unique ID for each DownloadFile.
149 int next_id_; 141 int next_id_;
150 142
151 // A map of all in progress downloads. 143 // A map of all in progress downloads.
152 typedef base::hash_map<int, DownloadFile*> DownloadFileMap; 144 typedef base::hash_map<int, DownloadFile*> DownloadFileMap;
153 DownloadFileMap downloads_; 145 DownloadFileMap downloads_;
154 146
155 // Throttle updates to the UI thread. 147 // Schedule periodic updates of the download progress. This timer
148 // is controlled from the FILE thread, and posts updates to the UI thread.
156 base::RepeatingTimer<DownloadFileManager> update_timer_; 149 base::RepeatingTimer<DownloadFileManager> update_timer_;
157 150
158 ResourceDispatcherHost* resource_dispatcher_host_; 151 ResourceDispatcherHost* resource_dispatcher_host_;
159 152
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
177 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); 153 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager);
178 }; 154 };
179 155
180 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 156 #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