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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // Maximum number of downloads to show. TODO(glen): Remove this and instead | 50 // Maximum number of downloads to show. TODO(glen): Remove this and instead |
51 // stuff the downloads down the pipe slowly. | 51 // stuff the downloads down the pipe slowly. |
52 static const int kMaxDownloads = 150; | 52 static const int kMaxDownloads = 150; |
53 | 53 |
54 // Sort DownloadItems into descending order by their start time. | 54 // Sort DownloadItems into descending order by their start time. |
55 class DownloadItemSorter : public std::binary_function<DownloadItem*, | 55 class DownloadItemSorter : public std::binary_function<DownloadItem*, |
56 DownloadItem*, | 56 DownloadItem*, |
57 bool> { | 57 bool> { |
58 public: | 58 public: |
59 bool operator()(const DownloadItem* lhs, const DownloadItem* rhs) { | 59 bool operator()(const DownloadItem* lhs, const DownloadItem* rhs) { |
60 return lhs->start_time() > rhs->start_time(); | 60 return lhs->GetStartTime() > rhs->GetStartTime(); |
61 } | 61 } |
62 }; | 62 }; |
63 | 63 |
64 enum DownloadsDOMEvent { | 64 enum DownloadsDOMEvent { |
65 DOWNLOADS_DOM_EVENT_GET_DOWNLOADS = 0, | 65 DOWNLOADS_DOM_EVENT_GET_DOWNLOADS = 0, |
66 DOWNLOADS_DOM_EVENT_OPEN_FILE = 1, | 66 DOWNLOADS_DOM_EVENT_OPEN_FILE = 1, |
67 DOWNLOADS_DOM_EVENT_DRAG = 2, | 67 DOWNLOADS_DOM_EVENT_DRAG = 2, |
68 DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS = 3, | 68 DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS = 3, |
69 DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS = 4, | 69 DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS = 4, |
70 DOWNLOADS_DOM_EVENT_SHOW = 5, | 70 DOWNLOADS_DOM_EVENT_SHOW = 5, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // Get the id for the download. Our downloads are sorted latest to first, | 195 // Get the id for the download. Our downloads are sorted latest to first, |
196 // and the id is the index into that list. We should be careful of sync | 196 // and the id is the index into that list. We should be careful of sync |
197 // errors between the UI and the download_items_ list (we may wish to use | 197 // errors between the UI and the download_items_ list (we may wish to use |
198 // something other than 'id'). | 198 // something other than 'id'). |
199 OrderedDownloads::iterator it = find(download_items_.begin(), | 199 OrderedDownloads::iterator it = find(download_items_.begin(), |
200 download_items_.end(), | 200 download_items_.end(), |
201 download); | 201 download); |
202 if (it == download_items_.end()) | 202 if (it == download_items_.end()) |
203 return; | 203 return; |
204 | 204 |
205 if (download->state() == DownloadItem::REMOVING) { | 205 if (download->GetState() == DownloadItem::REMOVING) { |
206 (*it)->RemoveObserver(this); | 206 (*it)->RemoveObserver(this); |
207 *it = NULL; | 207 *it = NULL; |
208 // A later ModelChanged() notification will change the WebUI's | 208 // A later ModelChanged() notification will change the WebUI's |
209 // view of the downloads list. | 209 // view of the downloads list. |
210 return; | 210 return; |
211 } | 211 } |
212 | 212 |
213 const int id = static_cast<int>(it - download_items_.begin()); | 213 const int id = static_cast<int>(it - download_items_.begin()); |
214 | 214 |
215 ListValue results_value; | 215 ListValue results_value; |
(...skipping 29 matching lines...) Expand all Loading... |
245 // Add ourself to all download items as an observer. | 245 // Add ourself to all download items as an observer. |
246 for (OrderedDownloads::iterator it = download_items_.begin(); | 246 for (OrderedDownloads::iterator it = download_items_.begin(); |
247 it != download_items_.end(); ++it) { | 247 it != download_items_.end(); ++it) { |
248 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) | 248 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) |
249 break; | 249 break; |
250 | 250 |
251 // TODO(rdsmith): Convert to DCHECK()s when http://crbug.com/85408 is | 251 // TODO(rdsmith): Convert to DCHECK()s when http://crbug.com/85408 is |
252 // fixed. | 252 // fixed. |
253 // We should never see anything that isn't already in the history. | 253 // We should never see anything that isn't already in the history. |
254 CHECK(*it); | 254 CHECK(*it); |
255 CHECK_NE(DownloadItem::kUninitializedHandle, (*it)->db_handle()); | 255 CHECK_NE(DownloadItem::kUninitializedHandle, (*it)->GetDbHandle()); |
256 | 256 |
257 (*it)->AddObserver(this); | 257 (*it)->AddObserver(this); |
258 } | 258 } |
259 | 259 |
260 SendCurrentDownloads(); | 260 SendCurrentDownloads(); |
261 } | 261 } |
262 | 262 |
263 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { | 263 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { |
264 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); | 264 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); |
265 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); | 265 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 DownloadItem* file = GetDownloadByValue(args); | 322 DownloadItem* file = GetDownloadByValue(args); |
323 if (file) | 323 if (file) |
324 file->TogglePause(); | 324 file->TogglePause(); |
325 } | 325 } |
326 | 326 |
327 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { | 327 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { |
328 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); | 328 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); |
329 DownloadItem* file = GetDownloadByValue(args); | 329 DownloadItem* file = GetDownloadByValue(args); |
330 if (file) { | 330 if (file) { |
331 // TODO(rdsmith): Change to DCHECK when http://crbug.com/85408 is fixed. | 331 // TODO(rdsmith): Change to DCHECK when http://crbug.com/85408 is fixed. |
332 CHECK_NE(DownloadItem::kUninitializedHandle, file->db_handle()); | 332 CHECK_NE(DownloadItem::kUninitializedHandle, file->GetDbHandle()); |
333 file->Remove(); | 333 file->Remove(); |
334 } | 334 } |
335 } | 335 } |
336 | 336 |
337 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { | 337 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { |
338 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); | 338 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); |
339 DownloadItem* file = GetDownloadByValue(args); | 339 DownloadItem* file = GetDownloadByValue(args); |
340 if (file) | 340 if (file) |
341 file->Cancel(true); | 341 file->Cancel(true); |
342 } | 342 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 return NULL; | 400 return NULL; |
401 } | 401 } |
402 | 402 |
403 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 403 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
404 int id; | 404 int id; |
405 if (ExtractIntegerValue(args, &id)) { | 405 if (ExtractIntegerValue(args, &id)) { |
406 return GetDownloadById(id); | 406 return GetDownloadById(id); |
407 } | 407 } |
408 return NULL; | 408 return NULL; |
409 } | 409 } |
OLD | NEW |