| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 return lhs->start_time() > rhs->start_time(); | 45 return lhs->start_time() > rhs->start_time(); |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) | 51 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) |
| 52 : search_text_(), | 52 : search_text_(), |
| 53 download_manager_(dlm), | 53 download_manager_(dlm), |
| 54 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 54 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 55 DVLOG(1) << __PRETTY_FUNCTION__ << " " << dlm; |
| 55 // Create our fileicon data source. | 56 // Create our fileicon data source. |
| 56 dlm->profile()->GetChromeURLDataManager()->AddDataSource( | 57 dlm->profile()->GetChromeURLDataManager()->AddDataSource( |
| 57 #if defined(OS_CHROMEOS) | 58 #if defined(OS_CHROMEOS) |
| 58 new FileIconSourceCros()); | 59 new FileIconSourceCros()); |
| 59 #else | 60 #else |
| 60 new FileIconSource()); | 61 new FileIconSource()); |
| 61 #endif // OS_CHROMEOS | 62 #endif // OS_CHROMEOS |
| 62 } | 63 } |
| 63 | 64 |
| 64 DownloadsDOMHandler::~DownloadsDOMHandler() { | 65 DownloadsDOMHandler::~DownloadsDOMHandler() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Add ourself to all download items as an observer. | 137 // Add ourself to all download items as an observer. |
| 137 for (OrderedDownloads::iterator it = download_items_.begin(); | 138 for (OrderedDownloads::iterator it = download_items_.begin(); |
| 138 it != download_items_.end(); ++it) { | 139 it != download_items_.end(); ++it) { |
| 139 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) | 140 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) |
| 140 break; | 141 break; |
| 141 | 142 |
| 142 // TODO(rdsmith): Convert to DCHECK()s when http://crbug.com/84508 is | 143 // TODO(rdsmith): Convert to DCHECK()s when http://crbug.com/84508 is |
| 143 // fixed. | 144 // fixed. |
| 144 // We should never see anything that isn't already in the history. | 145 // We should never see anything that isn't already in the history. |
| 145 CHECK(*it); | 146 CHECK(*it); |
| 146 CHECK_NE(DownloadHistory::kUninitializedHandle, (*it)->db_handle()); | 147 CHECK((*it)->IsInHistory()); |
| 147 | 148 |
| 148 (*it)->AddObserver(this); | 149 (*it)->AddObserver(this); |
| 149 } | 150 } |
| 150 | 151 |
| 151 SendCurrentDownloads(); | 152 SendCurrentDownloads(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { | 155 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { |
| 155 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); | 156 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); |
| 156 if (search_text_.compare(new_search) != 0) { | 157 if (search_text_.compare(new_search) != 0) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 179 { | 180 { |
| 180 // Enable nested tasks during DnD, while |DragDownload()| blocks. | 181 // Enable nested tasks during DnD, while |DragDownload()| blocks. |
| 181 MessageLoop::ScopedNestableTaskAllower allower(MessageLoop::current()); | 182 MessageLoop::ScopedNestableTaskAllower allower(MessageLoop::current()); |
| 182 download_util::DragDownload(file, icon, view); | 183 download_util::DragDownload(file, icon, view); |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 void DownloadsDOMHandler::HandleSaveDangerous(const ListValue* args) { | 188 void DownloadsDOMHandler::HandleSaveDangerous(const ListValue* args) { |
| 188 DownloadItem* file = GetDownloadByValue(args); | 189 DownloadItem* file = GetDownloadByValue(args); |
| 190 DVLOG(1) << __PRETTY_FUNCTION__ << " " << file; |
| 189 if (file) | 191 if (file) |
| 190 download_manager_->DangerousDownloadValidated(file); | 192 download_manager_->DangerousDownloadValidated(file); |
| 191 } | 193 } |
| 192 | 194 |
| 193 void DownloadsDOMHandler::HandleDiscardDangerous(const ListValue* args) { | 195 void DownloadsDOMHandler::HandleDiscardDangerous(const ListValue* args) { |
| 194 DownloadItem* file = GetDownloadByValue(args); | 196 DownloadItem* file = GetDownloadByValue(args); |
| 195 if (file) | 197 if (file) |
| 196 file->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 198 file->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 197 } | 199 } |
| 198 | 200 |
| 199 void DownloadsDOMHandler::HandleShow(const ListValue* args) { | 201 void DownloadsDOMHandler::HandleShow(const ListValue* args) { |
| 200 DownloadItem* file = GetDownloadByValue(args); | 202 DownloadItem* file = GetDownloadByValue(args); |
| 201 if (file) | 203 if (file) |
| 202 file->ShowDownloadInShell(); | 204 file->ShowDownloadInShell(); |
| 203 } | 205 } |
| 204 | 206 |
| 205 void DownloadsDOMHandler::HandlePause(const ListValue* args) { | 207 void DownloadsDOMHandler::HandlePause(const ListValue* args) { |
| 206 DownloadItem* file = GetDownloadByValue(args); | 208 DownloadItem* file = GetDownloadByValue(args); |
| 207 if (file) | 209 if (file) |
| 208 file->TogglePause(); | 210 file->TogglePause(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { | 213 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { |
| 212 DownloadItem* file = GetDownloadByValue(args); | 214 DownloadItem* file = GetDownloadByValue(args); |
| 213 if (file) { | 215 if (file) { |
| 214 // TODO(rdsmith): Change to DCHECK when http://crbug.com/84508 is fixed. | |
| 215 CHECK_NE(DownloadHistory::kUninitializedHandle, file->db_handle()); | |
| 216 file->Remove(); | 216 file->Remove(); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { | 220 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { |
| 221 DownloadItem* file = GetDownloadByValue(args); | 221 DownloadItem* file = GetDownloadByValue(args); |
| 222 if (file) | 222 if (file) |
| 223 file->Cancel(true); | 223 file->Cancel(true); |
| 224 } | 224 } |
| 225 | 225 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 252 continue; | 252 continue; |
| 253 (*it)->RemoveObserver(this); | 253 (*it)->RemoveObserver(this); |
| 254 } | 254 } |
| 255 download_items_.clear(); | 255 download_items_.clear(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 DownloadItem* DownloadsDOMHandler::GetDownloadById(int id) { | 258 DownloadItem* DownloadsDOMHandler::GetDownloadById(int id) { |
| 259 for (OrderedDownloads::iterator it = download_items_.begin(); | 259 for (OrderedDownloads::iterator it = download_items_.begin(); |
| 260 it != download_items_.end(); ++it) { | 260 it != download_items_.end(); ++it) { |
| 261 if (static_cast<int>(it - download_items_.begin() == id)) { | 261 if (static_cast<int>(it - download_items_.begin() == id)) { |
| 262 DVLOG(1) << " " << id << " " << *it; |
| 262 return (*it); | 263 return (*it); |
| 263 } | 264 } |
| 264 } | 265 } |
| 265 | 266 |
| 266 return NULL; | 267 return NULL; |
| 267 } | 268 } |
| 268 | 269 |
| 269 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 270 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
| 270 int id; | 271 int id; |
| 271 if (ExtractIntegerValue(args, &id)) { | 272 if (ExtractIntegerValue(args, &id)) { |
| 273 DVLOG(1) << id; |
| 272 return GetDownloadById(id); | 274 return GetDownloadById(id); |
| 273 } | 275 } |
| 274 return NULL; | 276 return NULL; |
| 275 } | 277 } |
| OLD | NEW |