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

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

Issue 6905049: Detect removed files and reflect the state in chrome://downloads and the download shelf (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Correct typo Created 9 years, 7 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) 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 113
114 // A download has started or been deleted. Query our DownloadManager for the 114 // A download has started or been deleted. Query our DownloadManager for the
115 // current set of downloads. 115 // current set of downloads.
116 void DownloadsDOMHandler::ModelChanged() { 116 void DownloadsDOMHandler::ModelChanged() {
117 ClearDownloadItems(); 117 ClearDownloadItems();
118 download_manager_->SearchDownloads(WideToUTF16(search_text_), 118 download_manager_->SearchDownloads(WideToUTF16(search_text_),
119 &download_items_); 119 &download_items_);
120 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); 120 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter());
121 121
122 // Scan for any in progress downloads and add ourself to them as an observer. 122 // Add oneself to all download items as an observer
Paweł Hajdan Jr. 2011/05/13 08:41:10 nit: Dot at the end of the sentence.
haraken1 2011/05/13 14:08:17 Done.
123 for (OrderedDownloads::iterator it = download_items_.begin(); 123 for (OrderedDownloads::iterator it = download_items_.begin();
124 it != download_items_.end(); ++it) { 124 it != download_items_.end(); ++it) {
125 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) 125 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads)
126 break; 126 break;
127 127 (*it)->AddObserver(this);
128 DownloadItem* download = *it;
129 if (download->IsInProgress()) {
130 // We want to know what happens as the download progresses.
131 download->AddObserver(this);
132 } else if (download->safety_state() == DownloadItem::DANGEROUS) {
133 // We need to be notified when the user validates the dangerous download.
134 download->AddObserver(this);
135 }
136 } 128 }
137 129
138 SendCurrentDownloads(); 130 SendCurrentDownloads();
139 } 131 }
140 132
141 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { 133 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) {
142 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); 134 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args));
143 if (search_text_.compare(new_search) != 0) { 135 if (search_text_.compare(new_search) != 0) {
144 search_text_ = new_search; 136 search_text_ = new_search;
145 ModelChanged(); 137 ModelChanged();
146 } else { 138 } else {
147 SendCurrentDownloads(); 139 SendCurrentDownloads();
148 } 140 }
141
142 download_manager_->CheckForFilesRemoval();
149 } 143 }
150 144
151 void DownloadsDOMHandler::HandleOpenFile(const ListValue* args) { 145 void DownloadsDOMHandler::HandleOpenFile(const ListValue* args) {
152 DownloadItem* file = GetDownloadByValue(args); 146 DownloadItem* file = GetDownloadByValue(args);
153 if (file) 147 if (file)
154 file->OpenDownload(); 148 file->OpenDownload();
155 } 149 }
156 150
157 void DownloadsDOMHandler::HandleDrag(const ListValue* args) { 151 void DownloadsDOMHandler::HandleDrag(const ListValue* args) {
158 DownloadItem* file = GetDownloadByValue(args); 152 DownloadItem* file = GetDownloadByValue(args);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return NULL; 234 return NULL;
241 } 235 }
242 236
243 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { 237 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) {
244 int id; 238 int id;
245 if (ExtractIntegerValue(args, &id)) { 239 if (ExtractIntegerValue(args, &id)) {
246 return GetDownloadById(id); 240 return GetDownloadById(id);
247 } 241 }
248 return NULL; 242 return NULL;
249 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698