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

Side by Side Diff: chrome/browser/ui/webui/downloads_dom_handler.cc

Issue 10837125: Revert 149794 - DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1228/src/
Patch Set: Created 8 years, 4 months 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 | Annotate | Revision Log
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 #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
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
182 const int id = static_cast<int>(it - download_items_.begin()); 190 const int id = static_cast<int>(it - download_items_.begin());
183 191
184 ListValue results_value; 192 ListValue results_value;
185 results_value.Append(download_util::CreateDownloadItemValue(download, id)); 193 results_value.Append(download_util::CreateDownloadItemValue(download, id));
186 web_ui()->CallJavascriptFunction("downloadUpdated", results_value); 194 web_ui()->CallJavascriptFunction("downloadUpdated", results_value);
187 } 195 }
188 196
189 void DownloadsDOMHandler::OnDownloadDestroyed(
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
200 // A download has started or been deleted. Query our DownloadManager for the 197 // A download has started or been deleted. Query our DownloadManager for the
201 // current set of downloads. 198 // current set of downloads.
202 void DownloadsDOMHandler::ModelChanged(content::DownloadManager* manager) { 199 void DownloadsDOMHandler::ModelChanged(content::DownloadManager* manager) {
203 DCHECK(manager == download_manager_ || 200 DCHECK(manager == download_manager_ ||
204 manager == original_profile_download_manager_); 201 manager == original_profile_download_manager_);
205 202
206 ClearDownloadItems(); 203 ClearDownloadItems();
207 download_manager_->SearchDownloads(WideToUTF16(search_text_), 204 download_manager_->SearchDownloads(WideToUTF16(search_text_),
208 &download_items_); 205 &download_items_);
209 // If we have a parent DownloadManager, let it add its downloads to the 206 // 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
407 } 404 }
408 405
409 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( 406 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue(
410 const ListValue* args) { 407 const ListValue* args) {
411 int id; 408 int id;
412 if (ExtractIntegerValue(args, &id)) { 409 if (ExtractIntegerValue(args, &id)) {
413 return GetDownloadById(id); 410 return GetDownloadById(id);
414 } 411 }
415 return NULL; 412 return NULL;
416 } 413 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/downloads_dom_handler.h ('k') | content/browser/download/download_item_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698