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

Side by Side Diff: chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h

Issue 1428833005: MD Downloads: track downloads in C++, dispatch discrete JS updates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_UI_WEBUI_MD_DOWNLOADS_MD_DOWNLOADS_DOM_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_MD_DOWNLOADS_MD_DOWNLOADS_DOM_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_MD_DOWNLOADS_MD_DOWNLOADS_DOM_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_MD_DOWNLOADS_MD_DOWNLOADS_DOM_HANDLER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h"
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/download/all_download_item_notifier.h"
15 #include "chrome/browser/download/download_danger_prompt.h" 13 #include "chrome/browser/download/download_danger_prompt.h"
16 #include "content/public/browser/download_item.h" 14 #include "chrome/browser/ui/webui/md_downloads/downloads_list_tracker.h"
17 #include "content/public/browser/download_manager.h"
18 #include "content/public/browser/web_ui_message_handler.h" 15 #include "content/public/browser/web_ui_message_handler.h"
19 16
20 namespace base { 17 namespace base {
21 class ListValue; 18 class ListValue;
22 } 19 }
23 20
24 namespace content { 21 namespace content {
22 class DownloadItem;
23 class DownloadManager;
24 class RenderViewHost;
25 class WebContents; 25 class WebContents;
26 class WebUI;
26 } 27 }
27 28
28 // The handler for Javascript messages related to the "downloads" view, 29 // The handler for Javascript messages related to the "downloads" view,
29 // also observes changes to the download manager. 30 // also observes changes to the download manager.
30 class MdDownloadsDOMHandler : public content::WebUIMessageHandler, 31 class MdDownloadsDOMHandler : public content::WebUIMessageHandler {
31 public AllDownloadItemNotifier::Observer {
32 public: 32 public:
33 explicit MdDownloadsDOMHandler(content::DownloadManager* download_manager); 33 MdDownloadsDOMHandler(content::DownloadManager* download_manager,
34 content::WebUI* web_ui);
34 ~MdDownloadsDOMHandler() override; 35 ~MdDownloadsDOMHandler() override;
35 36
36 void Init();
37
38 // WebUIMessageHandler implementation. 37 // WebUIMessageHandler implementation.
39 void RegisterMessages() override; 38 void RegisterMessages() override;
40 39
41 // AllDownloadItemNotifier::Observer interface 40 void RenderViewReused(content::RenderViewHost* render_view_host);
42 void OnDownloadCreated(content::DownloadManager* manager,
43 content::DownloadItem* download_item) override;
44 void OnDownloadUpdated(content::DownloadManager* manager,
45 content::DownloadItem* download_item) override;
46 void OnDownloadRemoved(content::DownloadManager* manager,
47 content::DownloadItem* download_item) override;
48 41
49 // Callback for the "getDownloads" message. 42 // Callback for the "getDownloads" message.
50 void HandleGetDownloads(const base::ListValue* args); 43 void HandleGetDownloads(const base::ListValue* args);
51 44
52 // Callback for the "openFile" message - opens the file in the shell. 45 // Callback for the "openFile" message - opens the file in the shell.
53 void HandleOpenFile(const base::ListValue* args); 46 void HandleOpenFile(const base::ListValue* args);
54 47
55 // Callback for the "drag" message - initiates a file object drag. 48 // Callback for the "drag" message - initiates a file object drag.
56 void HandleDrag(const base::ListValue* args); 49 void HandleDrag(const base::ListValue* args);
57 50
(...skipping 29 matching lines...) Expand all
87 80
88 // Callback for the "openDownloadsFolder" message - opens the downloads 81 // Callback for the "openDownloadsFolder" message - opens the downloads
89 // folder. 82 // folder.
90 void HandleOpenDownloadsFolder(const base::ListValue* args); 83 void HandleOpenDownloadsFolder(const base::ListValue* args);
91 84
92 protected: 85 protected:
93 // These methods are for mocking so that most of this class does not actually 86 // These methods are for mocking so that most of this class does not actually
94 // depend on WebUI. The other methods that depend on WebUI are 87 // depend on WebUI. The other methods that depend on WebUI are
95 // RegisterMessages() and HandleDrag(). 88 // RegisterMessages() and HandleDrag().
96 virtual content::WebContents* GetWebUIWebContents(); 89 virtual content::WebContents* GetWebUIWebContents();
97 virtual void CallUpdateAll(const base::ListValue& list);
98 virtual void CallUpdateItem(const base::DictionaryValue& item);
99
100 // Schedules a call to SendCurrentDownloads() in the next message loop
101 // iteration. Protected rather than private for use in tests.
102 void ScheduleSendCurrentDownloads();
103 90
104 // Actually remove downloads with an ID in |removals_|. This cannot be undone. 91 // Actually remove downloads with an ID in |removals_|. This cannot be undone.
105 void FinalizeRemovals(); 92 void FinalizeRemovals();
106 93
107 private: 94 private:
108 using IdSet = std::set<uint32>; 95 using IdSet = std::set<uint32>;
109 using DownloadVector = std::vector<content::DownloadItem*>; 96 using DownloadVector = std::vector<content::DownloadItem*>;
110 97
111 // Convenience method to call |main_notifier_->GetManager()| while 98 // Convenience method to call |main_notifier_->GetManager()| while
112 // null-checking |main_notifier_|. 99 // null-checking |main_notifier_|.
113 content::DownloadManager* GetMainNotifierManager() const; 100 content::DownloadManager* GetMainNotifierManager() const;
114 101
115 // Convenience method to call |original_notifier_->GetManager()| while 102 // Convenience method to call |original_notifier_->GetManager()| while
116 // null-checking |original_notifier_|. 103 // null-checking |original_notifier_|.
117 content::DownloadManager* GetOriginalNotifierManager() const; 104 content::DownloadManager* GetOriginalNotifierManager() const;
118 105
119 // Sends the current list of downloads to the page.
120 void SendCurrentDownloads();
121
122 // Displays a native prompt asking the user for confirmation after accepting 106 // Displays a native prompt asking the user for confirmation after accepting
123 // the dangerous download specified by |dangerous|. The function returns 107 // the dangerous download specified by |dangerous|. The function returns
124 // immediately, and will invoke DangerPromptAccepted() asynchronously if the 108 // immediately, and will invoke DangerPromptAccepted() asynchronously if the
125 // user accepts the dangerous download. The native prompt will observe 109 // user accepts the dangerous download. The native prompt will observe
126 // |dangerous| until either the dialog is dismissed or |dangerous| is no 110 // |dangerous| until either the dialog is dismissed or |dangerous| is no
127 // longer an in-progress dangerous download. 111 // longer an in-progress dangerous download.
128 void ShowDangerPrompt(content::DownloadItem* dangerous); 112 void ShowDangerPrompt(content::DownloadItem* dangerous);
129 113
130 // Conveys danger acceptance from the DownloadDangerPrompt to the 114 // Conveys danger acceptance from the DownloadDangerPrompt to the
131 // DownloadItem. 115 // DownloadItem.
132 void DangerPromptDone(int download_id, DownloadDangerPrompt::Action action); 116 void DangerPromptDone(int download_id, DownloadDangerPrompt::Action action);
133 117
134 // Returns true if the records of any downloaded items are allowed (and able) 118 // Returns true if the records of any downloaded items are allowed (and able)
135 // to be deleted. 119 // to be deleted.
136 bool IsDeletingHistoryAllowed(); 120 bool IsDeletingHistoryAllowed();
137 121
138 // Returns the download that is referred to in a given value. 122 // Returns the download that is referred to in a given value.
139 content::DownloadItem* GetDownloadByValue(const base::ListValue* args); 123 content::DownloadItem* GetDownloadByValue(const base::ListValue* args);
140 124
141 // Returns the download with |id| or NULL if it doesn't exist. 125 // Returns the download with |id| or NULL if it doesn't exist.
142 content::DownloadItem* GetDownloadById(uint32 id); 126 content::DownloadItem* GetDownloadById(uint32 id);
143 127
144 // Remove all downloads in |to_remove| with the ability to undo removal later. 128 // Remove all downloads in |to_remove| with the ability to undo removal later.
145 void RemoveDownloads(const DownloadVector& to_remove); 129 void RemoveDownloads(const DownloadVector& to_remove);
146 130
147 // Weak reference to the DownloadManager this class was constructed with. You 131 DownloadsListTracker list_tracker_;
148 // should probably be using use Get{Main,Original}NotifierManager() instead.
149 content::DownloadManager* download_manager_;
150
151 // Current search terms.
152 scoped_ptr<base::ListValue> search_terms_;
153
154 // Notifies OnDownload*() and provides safe access to the DownloadManager.
155 scoped_ptr<AllDownloadItemNotifier> main_notifier_;
156
157 // If |main_notifier_| observes an incognito profile, then this observes the
158 // DownloadManager for the original profile; otherwise, this is NULL.
159 scoped_ptr<AllDownloadItemNotifier> original_notifier_;
160 132
161 // IDs of downloads to remove when this handler gets deleted. 133 // IDs of downloads to remove when this handler gets deleted.
162 std::vector<IdSet> removals_; 134 std::vector<IdSet> removals_;
163 135
164 // Whether a call to SendCurrentDownloads() is currently scheduled.
165 bool update_scheduled_;
166
167 // IDs of new downloads that the page doesn't know about yet.
168 IdSet new_downloads_;
169
170 base::WeakPtrFactory<MdDownloadsDOMHandler> weak_ptr_factory_; 136 base::WeakPtrFactory<MdDownloadsDOMHandler> weak_ptr_factory_;
171 137
172 DISALLOW_COPY_AND_ASSIGN(MdDownloadsDOMHandler); 138 DISALLOW_COPY_AND_ASSIGN(MdDownloadsDOMHandler);
173 }; 139 };
174 140
175 #endif // CHROME_BROWSER_UI_WEBUI_MD_DOWNLOADS_MD_DOWNLOADS_DOM_HANDLER_H_ 141 #endif // CHROME_BROWSER_UI_WEBUI_MD_DOWNLOADS_MD_DOWNLOADS_DOM_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698