OLD | NEW |
---|---|
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 #include "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 web_ui()->RegisterMessageCallback("clearAll", | 128 web_ui()->RegisterMessageCallback("clearAll", |
129 base::Bind(&MdDownloadsDOMHandler::HandleClearAll, | 129 base::Bind(&MdDownloadsDOMHandler::HandleClearAll, |
130 weak_ptr_factory_.GetWeakPtr())); | 130 weak_ptr_factory_.GetWeakPtr())); |
131 web_ui()->RegisterMessageCallback("openDownloadsFolder", | 131 web_ui()->RegisterMessageCallback("openDownloadsFolder", |
132 base::Bind(&MdDownloadsDOMHandler::HandleOpenDownloadsFolder, | 132 base::Bind(&MdDownloadsDOMHandler::HandleOpenDownloadsFolder, |
133 weak_ptr_factory_.GetWeakPtr())); | 133 weak_ptr_factory_.GetWeakPtr())); |
134 } | 134 } |
135 | 135 |
136 void MdDownloadsDOMHandler::RenderViewReused( | 136 void MdDownloadsDOMHandler::RenderViewReused( |
137 content::RenderViewHost* render_view_host) { | 137 content::RenderViewHost* render_view_host) { |
138 list_tracker_.Stop(); | 138 list_tracker_.Reset(); |
139 } | 139 } |
140 | 140 |
141 void MdDownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { | 141 void MdDownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { |
142 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); | 142 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); |
143 | 143 |
144 bool terms_changed = list_tracker_.SetSearchTerms(*args); | 144 bool terms_changed = list_tracker_.SetSearchTerms(*args); |
145 if (terms_changed) | 145 if (terms_changed) |
146 list_tracker_.CallClearAll(); | 146 list_tracker_.Reset(); |
147 | 147 |
148 list_tracker_.Start(); | 148 list_tracker_.StartAndSendChunk(); |
149 } | 149 } |
150 | 150 |
151 void MdDownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { | 151 void MdDownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { |
152 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); | 152 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); |
153 content::DownloadItem* file = GetDownloadByValue(args); | 153 content::DownloadItem* file = GetDownloadByValue(args); |
154 if (file) | 154 if (file) |
155 file->OpenDownload(); | 155 file->OpenDownload(); |
156 } | 156 } |
157 | 157 |
158 void MdDownloadsDOMHandler::HandleDrag(const base::ListValue* args) { | 158 void MdDownloadsDOMHandler::HandleDrag(const base::ListValue* args) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 } | 231 } |
232 | 232 |
233 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) { | 233 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) { |
234 // TODO(dbeam): handle more than removed downloads someday? | 234 // TODO(dbeam): handle more than removed downloads someday? |
235 if (removals_.empty()) | 235 if (removals_.empty()) |
236 return; | 236 return; |
237 | 237 |
238 const IdSet last_removed_ids = removals_.back(); | 238 const IdSet last_removed_ids = removals_.back(); |
239 removals_.pop_back(); | 239 removals_.pop_back(); |
240 | 240 |
241 const bool undoing_clear_all = last_removed_ids.size() > 1; | |
242 if (undoing_clear_all) | |
Dan Beam
2015/12/05 00:31:43
^ this is how
| |
243 list_tracker_.Reset(); | |
244 | |
241 for (auto id : last_removed_ids) { | 245 for (auto id : last_removed_ids) { |
242 content::DownloadItem* download = GetDownloadById(id); | 246 content::DownloadItem* download = GetDownloadById(id); |
243 if (!download) | 247 if (!download) |
244 continue; | 248 continue; |
245 | 249 |
246 DownloadItemModel model(download); | 250 DownloadItemModel model(download); |
247 model.SetShouldShowInShelf(true); | 251 model.SetShouldShowInShelf(true); |
248 model.SetIsBeingRevived(true); | 252 model.SetIsBeingRevived(true); |
249 | 253 |
250 download->UpdateObservers(); | 254 download->UpdateObservers(); |
251 | 255 |
252 model.SetIsBeingRevived(false); | 256 model.SetIsBeingRevived(false); |
253 } | 257 } |
258 | |
259 if (undoing_clear_all) | |
260 list_tracker_.StartAndSendChunk(); | |
254 } | 261 } |
255 | 262 |
256 void MdDownloadsDOMHandler::HandleCancel(const base::ListValue* args) { | 263 void MdDownloadsDOMHandler::HandleCancel(const base::ListValue* args) { |
257 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); | 264 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); |
258 content::DownloadItem* file = GetDownloadByValue(args); | 265 content::DownloadItem* file = GetDownloadByValue(args); |
259 if (file) | 266 if (file) |
260 file->Cancel(true); | 267 file->Cancel(true); |
261 } | 268 } |
262 | 269 |
263 void MdDownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { | 270 void MdDownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { |
264 if (!IsDeletingHistoryAllowed()) { | 271 if (!IsDeletingHistoryAllowed()) { |
265 // This should only be reached during tests. | 272 // This should only be reached during tests. |
266 return; | 273 return; |
267 } | 274 } |
268 | 275 |
269 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); | 276 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); |
270 | 277 |
271 list_tracker_.CallClearAll(); | 278 list_tracker_.Reset(); |
272 list_tracker_.Stop(); | |
273 | 279 |
274 DownloadVector downloads; | 280 DownloadVector downloads; |
275 if (GetMainNotifierManager()) | 281 if (GetMainNotifierManager()) |
276 GetMainNotifierManager()->GetAllDownloads(&downloads); | 282 GetMainNotifierManager()->GetAllDownloads(&downloads); |
277 if (GetOriginalNotifierManager()) | 283 if (GetOriginalNotifierManager()) |
278 GetOriginalNotifierManager()->GetAllDownloads(&downloads); | 284 GetOriginalNotifierManager()->GetAllDownloads(&downloads); |
279 RemoveDownloads(downloads); | 285 RemoveDownloads(downloads); |
280 | 286 |
281 list_tracker_.Start(); | 287 list_tracker_.StartAndSendChunk(); |
282 } | 288 } |
283 | 289 |
284 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) { | 290 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) { |
285 IdSet ids; | 291 IdSet ids; |
286 | 292 |
287 for (auto* download : to_remove) { | 293 for (auto* download : to_remove) { |
288 DownloadItemModel item_model(download); | 294 DownloadItemModel item_model(download); |
289 if (!item_model.ShouldShowInShelf() || | 295 if (!item_model.ShouldShowInShelf() || |
290 download->GetState() == content::DownloadItem::IN_PROGRESS) { | 296 download->GetState() == content::DownloadItem::IN_PROGRESS) { |
291 continue; | 297 continue; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 if (GetMainNotifierManager()) | 399 if (GetMainNotifierManager()) |
394 item = GetMainNotifierManager()->GetDownload(id); | 400 item = GetMainNotifierManager()->GetDownload(id); |
395 if (!item && GetOriginalNotifierManager()) | 401 if (!item && GetOriginalNotifierManager()) |
396 item = GetOriginalNotifierManager()->GetDownload(id); | 402 item = GetOriginalNotifierManager()->GetDownload(id); |
397 return item; | 403 return item; |
398 } | 404 } |
399 | 405 |
400 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() { | 406 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() { |
401 return web_ui()->GetWebContents(); | 407 return web_ui()->GetWebContents(); |
402 } | 408 } |
OLD | NEW |