| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // Get the id for the download. Our downloads are sorted latest to first, | 172 // Get the id for the download. Our downloads are sorted latest to first, |
| 173 // and the id is the index into that list. We should be careful of sync | 173 // and the id is the index into that list. We should be careful of sync |
| 174 // errors between the UI and the download_items_ list (we may wish to use | 174 // errors between the UI and the download_items_ list (we may wish to use |
| 175 // something other than 'id'). | 175 // something other than 'id'). |
| 176 OrderedDownloads::iterator it = std::find(download_items_.begin(), | 176 OrderedDownloads::iterator it = std::find(download_items_.begin(), |
| 177 download_items_.end(), | 177 download_items_.end(), |
| 178 download); | 178 download); |
| 179 if (it == download_items_.end()) | 179 if (it == download_items_.end()) |
| 180 return; | 180 return; |
| 181 | 181 |
| 182 if (download->GetState() == content::DownloadItem::REMOVING) { | |
| 183 (*it)->RemoveObserver(this); | |
| 184 *it = NULL; | |
| 185 // A later ModelChanged() notification will change the WebUI's | |
| 186 // view of the downloads list. | |
| 187 return; | |
| 188 } | |
| 189 | |
| 190 const int id = static_cast<int>(it - download_items_.begin()); | 182 const int id = static_cast<int>(it - download_items_.begin()); |
| 191 | 183 |
| 192 ListValue results_value; | 184 ListValue results_value; |
| 193 results_value.Append(download_util::CreateDownloadItemValue(download, id)); | 185 results_value.Append(download_util::CreateDownloadItemValue(download, id)); |
| 194 web_ui()->CallJavascriptFunction("downloadUpdated", results_value); | 186 web_ui()->CallJavascriptFunction("downloadUpdated", results_value); |
| 195 } | 187 } |
| 196 | 188 |
| 189 void DownloadsDOMHandler::OnDownloadDestructed( |
| 190 content::DownloadItem* download) { |
| 191 download->RemoveObserver(this); |
| 192 OrderedDownloads::iterator it = std::find(download_items_.begin(), |
| 193 download_items_.end(), |
| 194 download); |
| 195 *it = NULL; |
| 196 // A later ModelChanged() notification will change the WebUI's |
| 197 // view of the downloads list. |
| 198 } |
| 199 |
| 197 // A download has started or been deleted. Query our DownloadManager for the | 200 // A download has started or been deleted. Query our DownloadManager for the |
| 198 // current set of downloads. | 201 // current set of downloads. |
| 199 void DownloadsDOMHandler::ModelChanged(content::DownloadManager* manager) { | 202 void DownloadsDOMHandler::ModelChanged(content::DownloadManager* manager) { |
| 200 DCHECK(manager == download_manager_ || | 203 DCHECK(manager == download_manager_ || |
| 201 manager == original_profile_download_manager_); | 204 manager == original_profile_download_manager_); |
| 202 | 205 |
| 203 ClearDownloadItems(); | 206 ClearDownloadItems(); |
| 204 download_manager_->SearchDownloads(WideToUTF16(search_text_), | 207 download_manager_->SearchDownloads(WideToUTF16(search_text_), |
| 205 &download_items_); | 208 &download_items_); |
| 206 // If we have a parent DownloadManager, let it add its downloads to the | 209 // If we have a parent DownloadManager, let it add its downloads to the |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 407 } |
| 405 | 408 |
| 406 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( | 409 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( |
| 407 const ListValue* args) { | 410 const ListValue* args) { |
| 408 int id; | 411 int id; |
| 409 if (ExtractIntegerValue(args, &id)) { | 412 if (ExtractIntegerValue(args, &id)) { |
| 410 return GetDownloadById(id); | 413 return GetDownloadById(id); |
| 411 } | 414 } |
| 412 return NULL; | 415 return NULL; |
| 413 } | 416 } |
| OLD | NEW |