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

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

Issue 7640021: Move some Chrome-specific code paths out of DownloadManager and into the delegate. Getting rid of... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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
« no previous file with comments | « chrome/browser/download/download_item.cc ('k') | chrome/browser/download/download_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 DownloadManager object manages the process of downloading, including 5 // The DownloadManager object manages the process of downloading, including
6 // updates to the history system and providing the information for displaying 6 // updates to the history system and providing the information for displaying
7 // the downloads view in the Destinations tab. There is one DownloadManager per 7 // the downloads view in the Destinations tab. There is one DownloadManager per
8 // active profile in Chrome. 8 // active profile in Chrome.
9 // 9 //
10 // Download observers: 10 // Download observers:
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Display a new download in the appropriate browser UI. 191 // Display a new download in the appropriate browser UI.
192 void ShowDownloadInBrowser(DownloadItem* download); 192 void ShowDownloadInBrowser(DownloadItem* download);
193 193
194 // The number of in progress (including paused) downloads. 194 // The number of in progress (including paused) downloads.
195 int in_progress_count() const { 195 int in_progress_count() const {
196 return static_cast<int>(in_progress_.size()); 196 return static_cast<int>(in_progress_.size());
197 } 197 }
198 198
199 Profile* profile() { return profile_; } 199 Profile* profile() { return profile_; }
200 200
201 DownloadHistory* download_history() { return download_history_.get(); }
202
201 DownloadPrefs* download_prefs() { return download_prefs_.get(); } 203 DownloadPrefs* download_prefs() { return download_prefs_.get(); }
202 204
203 #if defined(UNIT_TEST) 205 FilePath last_download_path() { return last_download_path_; }
204 DownloadHistory* download_history() { return download_history_.get(); }
205 #endif
206 206
207 // Creates the download item. Must be called on the UI thread. 207 // Creates the download item. Must be called on the UI thread.
208 void CreateDownloadItem(DownloadCreateInfo* info); 208 void CreateDownloadItem(DownloadCreateInfo* info);
209 209
210 // Clears the last download path, used to initialize "save as" dialogs. 210 // Clears the last download path, used to initialize "save as" dialogs.
211 void ClearLastDownloadPath(); 211 void ClearLastDownloadPath();
212 212
213 // Tests if a file type should be opened automatically.
214 bool ShouldOpenFileBasedOnExtension(const FilePath& path) const;
215
216 // Overridden from DownloadStatusUpdaterDelegate: 213 // Overridden from DownloadStatusUpdaterDelegate:
217 virtual bool IsDownloadProgressKnown(); 214 virtual bool IsDownloadProgressKnown();
218 virtual int64 GetInProgressDownloadCount(); 215 virtual int64 GetInProgressDownloadCount();
219 virtual int64 GetReceivedDownloadBytes(); 216 virtual int64 GetReceivedDownloadBytes();
220 virtual int64 GetTotalDownloadBytes(); 217 virtual int64 GetTotalDownloadBytes();
221 218
222 // Called by the embedder after the save as dialog is closed. 219 // Called by the delegate after the save as dialog is closed.
223 void FileSelected(const FilePath& path, void* params); 220 void FileSelected(const FilePath& path, void* params);
224 void FileSelectionCanceled(void* params); 221 void FileSelectionCanceled(void* params);
225 222
226 // Returns true if this download should show the "dangerous file" warning. 223 // Called by the delegate if it delayed the download in
227 // Various factors are considered, such as the type of the file, whether a 224 // DownloadManagerDelegate::ShouldStartDownload and now is ready.
228 // user action initiated the download, and whether the user has explicitly 225 void RestartDownload(int32 download_id);
229 // marked the file type as "auto open".
230 bool IsDangerousFile(const DownloadItem& download,
231 const DownloadStateInfo& state,
232 bool visited_referrer_before);
233 226
234 // Checks whether downloaded files still exist. Updates state of downloads 227 // Checks whether downloaded files still exist. Updates state of downloads
235 // that refer to removed files. The check runs in the background and may 228 // that refer to removed files. The check runs in the background and may
236 // finish asynchronously after this method returns. 229 // finish asynchronously after this method returns.
237 void CheckForHistoryFilesRemoval(); 230 void CheckForHistoryFilesRemoval();
238 231
239 // Checks whether a downloaded file still exists and updates the file's state 232 // Checks whether a downloaded file still exists and updates the file's state
240 // if the file is already removed. The check runs in the background and may 233 // if the file is already removed. The check runs in the background and may
241 // finish asynchronously after this method returns. 234 // finish asynchronously after this method returns.
242 void CheckForFileRemoval(DownloadItem* download_item); 235 void CheckForFileRemoval(DownloadItem* download_item);
243 236
244 // Callback function after url is checked with safebrowsing service.
245 void CheckDownloadUrlDone(int32 download_id, bool is_dangerous_url);
246
247 // Callback function after we check whether the referrer URL has been visited
248 // before today.
249 void CheckVisitedReferrerBeforeDone(int32 download_id,
250 bool visited_referrer_before);
251
252 // Callback function after download file hash is checked with safebrowsing
253 // service.
254 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash);
255
256 // Assert the named download item is on the correct queues 237 // Assert the named download item is on the correct queues
257 // in the DownloadManager. For debugging. 238 // in the DownloadManager. For debugging.
258 void AssertQueueStateConsistent(DownloadItem* download); 239 void AssertQueueStateConsistent(DownloadItem* download);
259 240
260 // Get the download item from the history map. Useful after the item has 241 // Get the download item from the history map. Useful after the item has
261 // been removed from the active map, or was retrieved from the history DB. 242 // been removed from the active map, or was retrieved from the history DB.
262 DownloadItem* GetDownloadItem(int id); 243 DownloadItem* GetDownloadItem(int id);
263 244
264 // Called when Save Page download starts. Transfers ownership of |download| 245 // Called when Save Page download starts. Transfers ownership of |download|
265 // to the DownloadManager. 246 // to the DownloadManager.
266 void SavePageDownloadStarted(DownloadItem* download); 247 void SavePageDownloadStarted(DownloadItem* download);
267 248
268 // Callback when Save Page As entry is commited to the history system. 249 // Callback when Save Page As entry is commited to the history system.
269 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle); 250 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle);
270 251
271 // Called when Save Page download is done. 252 // Called when Save Page download is done.
272 void SavePageDownloadFinished(DownloadItem* download); 253 void SavePageDownloadFinished(DownloadItem* download);
273 254
274 // Download Id for next Save Page. 255 // Download Id for next Save Page.
275 int32 GetNextSavePageId(); 256 int32 GetNextSavePageId();
276 257
258 // Get the download item from the active map. Useful when the item is not
259 // yet in the history map.
260 DownloadItem* GetActiveDownloadItem(int id);
261
277 DownloadManagerDelegate* delegate() const { return delegate_; } 262 DownloadManagerDelegate* delegate() const { return delegate_; }
278 263
279 private: 264 private:
280 typedef std::set<DownloadItem*> DownloadSet; 265 typedef std::set<DownloadItem*> DownloadSet;
281 typedef base::hash_map<int64, DownloadItem*> DownloadMap; 266 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
282 267
283 // For testing. 268 // For testing.
284 friend class DownloadManagerTest; 269 friend class DownloadManagerTest;
285 friend class MockDownloadManager; 270 friend class MockDownloadManager;
286 271
(...skipping 25 matching lines...) Expand all
312 virtual ~DownloadManager(); 297 virtual ~DownloadManager();
313 298
314 // Called on the FILE thread to check the existence of a downloaded file. 299 // Called on the FILE thread to check the existence of a downloaded file.
315 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); 300 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path);
316 301
317 // Called on the UI thread if the FILE thread detects the removal of 302 // Called on the UI thread if the FILE thread detects the removal of
318 // the downloaded file. The UI thread updates the state of the file 303 // the downloaded file. The UI thread updates the state of the file
319 // and then notifies this update to the file's observer. 304 // and then notifies this update to the file's observer.
320 void OnFileRemovalDetected(int64 db_handle); 305 void OnFileRemovalDetected(int64 db_handle);
321 306
322 // Called on the download thread to check whether the suggested file path
323 // exists. We don't check if the file exists on the UI thread to avoid UI
324 // stalls from interacting with the file system.
325 void CheckIfSuggestedPathExists(int32 download_id,
326 DownloadStateInfo state,
327 const FilePath& default_path);
328
329 // Called on the UI thread once the DownloadManager has determined whether the
330 // suggested file path exists.
331 void OnPathExistenceAvailable(int32 download_id,
332 const DownloadStateInfo& new_state);
333
334 // Called back after a target path for the file to be downloaded to has been 307 // Called back after a target path for the file to be downloaded to has been
335 // determined, either automatically based on the suggested file name, or by 308 // determined, either automatically based on the suggested file name, or by
336 // the user in a Save As dialog box. 309 // the user in a Save As dialog box.
337 void ContinueDownloadWithPath(DownloadItem* download, 310 void ContinueDownloadWithPath(DownloadItem* download,
338 const FilePath& chosen_file); 311 const FilePath& chosen_file);
339 312
340 // Download cancel helper function. 313 // Download cancel helper function.
341 void DownloadCancelledInternal(int download_id, 314 void DownloadCancelledInternal(int download_id,
342 const DownloadRequestHandle& request_handle); 315 const DownloadRequestHandle& request_handle);
343 316
344 // All data has been downloaded. 317 // All data has been downloaded.
345 // |hash| is sha256 hash for the downloaded file. It is empty when the hash 318 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
346 // is not available. 319 // is not available.
347 void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash); 320 void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash);
348 321
349 // An error occurred in the download. 322 // An error occurred in the download.
350 void OnDownloadError(int32 download_id, int64 size, int os_error); 323 void OnDownloadError(int32 download_id, int64 size, int os_error);
351 324
352 // Updates the app icon about the overall download progress. 325 // Updates the app icon about the overall download progress.
353 void UpdateAppIcon(); 326 void UpdateAppIcon();
354 327
355 // Inform observers that the model has changed. 328 // Inform observers that the model has changed.
356 void NotifyModelChanged(); 329 void NotifyModelChanged();
357 330
358 // Get the download item from the active map. Useful when the item is not
359 // yet in the history map.
360 DownloadItem* GetActiveDownloadItem(int id);
361
362 // Debugging routine to confirm relationship between below 331 // Debugging routine to confirm relationship between below
363 // containers; no-op if NDEBUG. 332 // containers; no-op if NDEBUG.
364 void AssertContainersConsistent() const; 333 void AssertContainersConsistent() const;
365 334
366 // Add a DownloadItem to history_downloads_. 335 // Add a DownloadItem to history_downloads_.
367 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); 336 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle);
368 337
369 // Remove from internal maps. 338 // Remove from internal maps.
370 int RemoveDownloadItems(const DownloadVector& pending_deletes); 339 int RemoveDownloadItems(const DownloadVector& pending_deletes);
371 340
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 409
441 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; 410 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_;
442 411
443 // Allows an embedder to control behavior. Guaranteed to outlive this object. 412 // Allows an embedder to control behavior. Guaranteed to outlive this object.
444 DownloadManagerDelegate* delegate_; 413 DownloadManagerDelegate* delegate_;
445 414
446 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 415 DISALLOW_COPY_AND_ASSIGN(DownloadManager);
447 }; 416 };
448 417
449 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 418 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item.cc ('k') | chrome/browser/download/download_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698