| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Add ourself to all download items as an observer. | 136 // Add ourself to all download items as an observer. |
| 137 for (OrderedDownloads::iterator it = download_items_.begin(); | 137 for (OrderedDownloads::iterator it = download_items_.begin(); |
| 138 it != download_items_.end(); ++it) { | 138 it != download_items_.end(); ++it) { |
| 139 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) | 139 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) |
| 140 break; | 140 break; |
| 141 | 141 |
| 142 // TODO(rdsmith): Convert to DCHECK()s when http://crbug.com/84508 is | 142 // TODO(rdsmith): Convert to DCHECK()s when http://crbug.com/84508 is |
| 143 // fixed. | 143 // fixed. |
| 144 // We should never see anything that isn't already in the history. | 144 // We should never see anything that isn't already in the history. |
| 145 CHECK(*it); | 145 CHECK(*it); |
| 146 CHECK_NE(DownloadHistory::kUninitializedHandle, (*it)->db_handle()); | 146 CHECK_NE(DownloadHistory::kUninitializedHandle, (*it)->id()); |
| 147 | 147 |
| 148 (*it)->AddObserver(this); | 148 (*it)->AddObserver(this); |
| 149 } | 149 } |
| 150 | 150 |
| 151 SendCurrentDownloads(); | 151 SendCurrentDownloads(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { | 154 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { |
| 155 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); | 155 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); |
| 156 if (search_text_.compare(new_search) != 0) { | 156 if (search_text_.compare(new_search) != 0) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 void DownloadsDOMHandler::HandlePause(const ListValue* args) { | 205 void DownloadsDOMHandler::HandlePause(const ListValue* args) { |
| 206 DownloadItem* file = GetDownloadByValue(args); | 206 DownloadItem* file = GetDownloadByValue(args); |
| 207 if (file) | 207 if (file) |
| 208 file->TogglePause(); | 208 file->TogglePause(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { | 211 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { |
| 212 DownloadItem* file = GetDownloadByValue(args); | 212 DownloadItem* file = GetDownloadByValue(args); |
| 213 // TODO(rdsmith): Change to DCHECK when http://crbug.com/84508 is fixed. | 213 // TODO(rdsmith): Change to DCHECK when http://crbug.com/84508 is fixed. |
| 214 CHECK_NE(DownloadHistory::kUninitializedHandle, file->db_handle()); | 214 CHECK_NE(DownloadHistory::kUninitializedHandle, file->id()); |
| 215 if (file) | 215 if (file) |
| 216 file->Remove(); | 216 file->Remove(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { | 219 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { |
| 220 DownloadItem* file = GetDownloadByValue(args); | 220 DownloadItem* file = GetDownloadByValue(args); |
| 221 if (file) | 221 if (file) |
| 222 file->Cancel(true); | 222 file->Cancel(true); |
| 223 } | 223 } |
| 224 | 224 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 return NULL; | 265 return NULL; |
| 266 } | 266 } |
| 267 | 267 |
| 268 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 268 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
| 269 int id; | 269 int id; |
| 270 if (ExtractIntegerValue(args, &id)) { | 270 if (ExtractIntegerValue(args, &id)) { |
| 271 return GetDownloadById(id); | 271 return GetDownloadById(id); |
| 272 } | 272 } |
| 273 return NULL; | 273 return NULL; |
| 274 } | 274 } |
| OLD | NEW |