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/downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } else { | 193 } else { |
194 NOTREACHED() << "state undefined"; | 194 NOTREACHED() << "state undefined"; |
195 } | 195 } |
196 | 196 |
197 return file_value; | 197 return file_value; |
198 } | 198 } |
199 | 199 |
200 // Filters out extension downloads and downloads that don't have a filename yet. | 200 // Filters out extension downloads and downloads that don't have a filename yet. |
201 bool IsDownloadDisplayable(const content::DownloadItem& item) { | 201 bool IsDownloadDisplayable(const content::DownloadItem& item) { |
202 return (!download_crx_util::IsExtensionDownload(item) && | 202 return (!download_crx_util::IsExtensionDownload(item) && |
203 item.IsPersisted() && | |
204 !item.IsTemporary() && | 203 !item.IsTemporary() && |
205 !item.GetFileNameToReportUser().empty() && | 204 !item.GetFileNameToReportUser().empty() && |
206 !item.GetTargetFilePath().empty()); | 205 !item.GetTargetFilePath().empty()); |
207 } | 206 } |
208 | 207 |
209 } // namespace | 208 } // namespace |
210 | 209 |
211 DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm) | 210 DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm) |
212 : search_text_(), | 211 : search_text_(), |
213 ALLOW_THIS_IN_INITIALIZER_LIST(main_notifier_(dlm, this)), | 212 ALLOW_THIS_IN_INITIALIZER_LIST(main_notifier_(dlm, this)), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell | 320 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell |
322 // SendCurrentDownloads() that |download_item| was removed. A | 321 // SendCurrentDownloads() that |download_item| was removed. A |
323 // SupportsUserData::Data would be the correct way to do this. | 322 // SupportsUserData::Data would be the correct way to do this. |
324 ScheduleSendCurrentDownloads(); | 323 ScheduleSendCurrentDownloads(); |
325 } | 324 } |
326 | 325 |
327 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { | 326 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { |
328 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); | 327 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); |
329 search_text_ = ExtractStringValue(args); | 328 search_text_ = ExtractStringValue(args); |
330 SendCurrentDownloads(); | 329 SendCurrentDownloads(); |
331 if (main_notifier_.GetManager()) | |
332 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); | |
333 } | 330 } |
334 | 331 |
335 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { | 332 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { |
336 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); | 333 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); |
337 content::DownloadItem* file = GetDownloadByValue(args); | 334 content::DownloadItem* file = GetDownloadByValue(args); |
338 if (file) | 335 if (file) |
339 file->OpenDownload(); | 336 file->OpenDownload(); |
340 } | 337 } |
341 | 338 |
342 void DownloadsDOMHandler::HandleDrag(const base::ListValue* args) { | 339 void DownloadsDOMHandler::HandleDrag(const base::ListValue* args) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 update_scheduled_ = true; | 426 update_scheduled_ = true; |
430 BrowserThread::PostTask( | 427 BrowserThread::PostTask( |
431 BrowserThread::UI, FROM_HERE, | 428 BrowserThread::UI, FROM_HERE, |
432 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, | 429 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, |
433 weak_ptr_factory_.GetWeakPtr())); | 430 weak_ptr_factory_.GetWeakPtr())); |
434 } | 431 } |
435 | 432 |
436 void DownloadsDOMHandler::SendCurrentDownloads() { | 433 void DownloadsDOMHandler::SendCurrentDownloads() { |
437 update_scheduled_ = false; | 434 update_scheduled_ = false; |
438 content::DownloadManager::DownloadVector all_items, filtered_items; | 435 content::DownloadManager::DownloadVector all_items, filtered_items; |
439 if (main_notifier_.GetManager()) | 436 if (main_notifier_.GetManager()) { |
440 main_notifier_.GetManager()->GetAllDownloads(&all_items); | 437 main_notifier_.GetManager()->GetAllDownloads(&all_items); |
441 if (original_notifier_.get() && original_notifier_->GetManager()) | 438 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); |
| 439 } |
| 440 if (original_notifier_.get() && original_notifier_->GetManager()) { |
442 original_notifier_->GetManager()->GetAllDownloads(&all_items); | 441 original_notifier_->GetManager()->GetAllDownloads(&all_items); |
| 442 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); |
| 443 } |
443 DownloadQuery query; | 444 DownloadQuery query; |
444 if (!search_text_.empty()) { | 445 if (!search_text_.empty()) { |
445 scoped_ptr<base::Value> query_text(base::Value::CreateStringValue( | 446 scoped_ptr<base::Value> query_text(base::Value::CreateStringValue( |
446 search_text_)); | 447 search_text_)); |
447 query.AddFilter(DownloadQuery::FILTER_QUERY, *query_text.get()); | 448 query.AddFilter(DownloadQuery::FILTER_QUERY, *query_text.get()); |
448 } | 449 } |
449 query.AddFilter(base::Bind(&IsDownloadDisplayable)); | 450 query.AddFilter(base::Bind(&IsDownloadDisplayable)); |
450 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); | 451 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); |
451 query.Limit(kMaxDownloads); | 452 query.Limit(kMaxDownloads); |
452 query.Search(all_items.begin(), all_items.end(), &filtered_items); | 453 query.Search(all_items.begin(), all_items.end(), &filtered_items); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 506 } |
506 | 507 |
507 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { | 508 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { |
508 web_ui()->CallJavascriptFunction("downloadsList", downloads); | 509 web_ui()->CallJavascriptFunction("downloadsList", downloads); |
509 } | 510 } |
510 | 511 |
511 void DownloadsDOMHandler::CallDownloadUpdated( | 512 void DownloadsDOMHandler::CallDownloadUpdated( |
512 const base::ListValue& download_item) { | 513 const base::ListValue& download_item) { |
513 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); | 514 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); |
514 } | 515 } |
OLD | NEW |