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

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

Issue 230103002: [Downloads] Ask DownloadHistory if a download was from history. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UI_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UI_CONTROLLER_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UI_CONTROLLER_H_ 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UI_CONTROLLER_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/download/all_download_item_notifier.h" 12 #include "chrome/browser/download/all_download_item_notifier.h"
12 13
13 class Profile; 14 class Profile;
15 class DownloadHistory;
14 16
15 namespace content { 17 namespace content {
16 class WebContents; 18 class WebContents;
17 } 19 }
18 20
19 // This class handles the task of observing for download notifications and 21 // This class handles the task of observing a single DownloadManager for
20 // notifying the UI when a new download should be displayed in the UI. 22 // download notifications and notifying the UI when a new download should be
23 // displayed in the UI.
21 // 24 //
22 // This class monitors each IN_PROGRESS download that is created (for which 25 // This class monitors each new download that is created (for which
23 // OnDownloadCreated is called) until: 26 // OnDownloadCreated is called) until it is assigned a target path. "New"
24 // - it is assigned a target path or 27 // downloads are distinguished from old downloads using a DownloadFilter (see
25 // - is interrupted. 28 // comments on constructor below). Once a target path is available, the download
26 // Then the NotifyDownloadStarting() method of the Delegate is invoked. 29 // is sent to the UI via the NotifyDownloadStarting() method of the Delegate.
27 class DownloadUIController : public AllDownloadItemNotifier::Observer { 30 class DownloadUIController : public AllDownloadItemNotifier::Observer {
28 public: 31 public:
29 // The delegate is responsible for figuring out how to notify the UI. 32 // The delegate is responsible for figuring out how to notify the UI.
30 class Delegate { 33 class Delegate {
31 public: 34 public:
32 virtual ~Delegate(); 35 virtual ~Delegate();
36
37 // This method is invoked to notify the UI of the new download |item|. Note
38 // that |item| may be in any state by the time this method is invoked.
33 virtual void NotifyDownloadStarting(content::DownloadItem* item) = 0; 39 virtual void NotifyDownloadStarting(content::DownloadItem* item) = 0;
34 }; 40 };
35 41
42 // Predicate for determining whether a given download should be considered a
43 // new download. Only new downloads are considered for display in the UI.
44 typedef base::Callback<bool(const content::DownloadItem*)> DownloadFilter;
45
46 // Construct a DownloadFilter based on a DownloadHistory instance. The
47 // returned predicate assumes that if a given DownloadItem is persisted in
48 // history, then it is not new. The lifetime of the |download_history| object
49 // should larger than the returned predicate.
50 static DownloadFilter NewDownloadFilterFromDownloadHistory(
51 DownloadHistory* download_history);
Randy Smith (Not in Mondays) 2014/04/10 18:03:23 I dislike cluttering up class interfaces for testi
asanka 2014/04/17 21:16:10 I refactored this. PTAL.
52
36 // |manager| is the download manager to observe for new downloads. If 53 // |manager| is the download manager to observe for new downloads. If
37 // |delegate.get()| is NULL, then the default delegate is constructed. 54 // |delegate.get()| is NULL, then the default delegate is constructed.
38 // 55 //
39 // On Android the default delegate notifies DownloadControllerAndroid. On 56 // On Android the default delegate notifies DownloadControllerAndroid. On
40 // other platforms the target of the notification is a Browser object. 57 // other platforms the target of the notification is a Browser object.
41 // 58 //
42 // Currently explicit delegates are only used for testing. 59 // Currently explicit delegates are only used for testing.
60 //
61 // |new_download_filter| is a DownloadFilter that should return true if a
62 // newly created download should be displayed in the UI.
43 DownloadUIController(content::DownloadManager* manager, 63 DownloadUIController(content::DownloadManager* manager,
64 const DownloadFilter& new_download_filter,
44 scoped_ptr<Delegate> delegate); 65 scoped_ptr<Delegate> delegate);
45 66
46 virtual ~DownloadUIController(); 67 virtual ~DownloadUIController();
47 68
48 private: 69 private:
49 virtual void OnDownloadCreated(content::DownloadManager* manager, 70 virtual void OnDownloadCreated(content::DownloadManager* manager,
50 content::DownloadItem* item) OVERRIDE; 71 content::DownloadItem* item) OVERRIDE;
51 virtual void OnDownloadUpdated(content::DownloadManager* manager, 72 virtual void OnDownloadUpdated(content::DownloadManager* manager,
52 content::DownloadItem* item) OVERRIDE; 73 content::DownloadItem* item) OVERRIDE;
53 74
54 AllDownloadItemNotifier download_notifier_; 75 AllDownloadItemNotifier download_notifier_;
55 76
77 DownloadFilter new_download_filter_;
56 scoped_ptr<Delegate> delegate_; 78 scoped_ptr<Delegate> delegate_;
57 79
58 DISALLOW_COPY_AND_ASSIGN(DownloadUIController); 80 DISALLOW_COPY_AND_ASSIGN(DownloadUIController);
59 }; 81 };
60 82
61 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UI_CONTROLLER_H_ 83 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UI_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698