| OLD | NEW |
| 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 #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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 // A download has started or been deleted. Query our DownloadManager for the | 119 // A download has started or been deleted. Query our DownloadManager for the |
| 120 // current set of downloads. | 120 // current set of downloads. |
| 121 void DownloadsDOMHandler::ModelChanged() { | 121 void DownloadsDOMHandler::ModelChanged() { |
| 122 ClearDownloadItems(); | 122 ClearDownloadItems(); |
| 123 download_manager_->SearchDownloads(WideToUTF16(search_text_), | 123 download_manager_->SearchDownloads(WideToUTF16(search_text_), |
| 124 &download_items_); | 124 &download_items_); |
| 125 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); | 125 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); |
| 126 | 126 |
| 127 // Scan for any in progress downloads and add ourself to them as an observer. | 127 // Add ourself to all download items as an observer. |
| 128 for (OrderedDownloads::iterator it = download_items_.begin(); | 128 for (OrderedDownloads::iterator it = download_items_.begin(); |
| 129 it != download_items_.end(); ++it) { | 129 it != download_items_.end(); ++it) { |
| 130 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) | 130 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) |
| 131 break; | 131 break; |
| 132 | 132 (*it)->AddObserver(this); |
| 133 DownloadItem* download = *it; | |
| 134 if (download->IsInProgress()) { | |
| 135 // We want to know what happens as the download progresses. | |
| 136 download->AddObserver(this); | |
| 137 } else if (download->safety_state() == DownloadItem::DANGEROUS) { | |
| 138 // We need to be notified when the user validates the dangerous download. | |
| 139 download->AddObserver(this); | |
| 140 } | |
| 141 } | 133 } |
| 142 | 134 |
| 143 SendCurrentDownloads(); | 135 SendCurrentDownloads(); |
| 144 } | 136 } |
| 145 | 137 |
| 146 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { | 138 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { |
| 147 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); | 139 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); |
| 148 if (search_text_.compare(new_search) != 0) { | 140 if (search_text_.compare(new_search) != 0) { |
| 149 search_text_ = new_search; | 141 search_text_ = new_search; |
| 150 ModelChanged(); | 142 ModelChanged(); |
| 151 } else { | 143 } else { |
| 152 SendCurrentDownloads(); | 144 SendCurrentDownloads(); |
| 153 } | 145 } |
| 146 |
| 147 download_manager_->CheckForHistoryFilesRemoval(); |
| 154 } | 148 } |
| 155 | 149 |
| 156 void DownloadsDOMHandler::HandleOpenFile(const ListValue* args) { | 150 void DownloadsDOMHandler::HandleOpenFile(const ListValue* args) { |
| 157 DownloadItem* file = GetDownloadByValue(args); | 151 DownloadItem* file = GetDownloadByValue(args); |
| 158 if (file) | 152 if (file) |
| 159 file->OpenDownload(); | 153 file->OpenDownload(); |
| 160 } | 154 } |
| 161 | 155 |
| 162 void DownloadsDOMHandler::HandleDrag(const ListValue* args) { | 156 void DownloadsDOMHandler::HandleDrag(const ListValue* args) { |
| 163 DownloadItem* file = GetDownloadByValue(args); | 157 DownloadItem* file = GetDownloadByValue(args); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 return NULL; | 239 return NULL; |
| 246 } | 240 } |
| 247 | 241 |
| 248 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 242 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
| 249 int id; | 243 int id; |
| 250 if (ExtractIntegerValue(args, &id)) { | 244 if (ExtractIntegerValue(args, &id)) { |
| 251 return GetDownloadById(id); | 245 return GetDownloadById(id); |
| 252 } | 246 } |
| 253 return NULL; | 247 return NULL; |
| 254 } | 248 } |
| OLD | NEW |