| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 // The original profile's download manager. | 118 // The original profile's download manager. |
| 119 DownloadManager* original_profile_download_manager_; | 119 DownloadManager* original_profile_download_manager_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) | 122 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) |
| 123 : search_text_(), | 123 : search_text_(), |
| 124 download_manager_(dlm), | 124 download_manager_(dlm), |
| 125 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 125 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 126 // Create our fileicon data source. | 126 // Create our fileicon data source. |
| 127 Profile::FromBrowserContext(dlm->browser_context())-> | 127 Profile::FromBrowserContext(dlm->BrowserContext())-> |
| 128 GetChromeURLDataManager()->AddDataSource( | 128 GetChromeURLDataManager()->AddDataSource( |
| 129 #if defined(OS_CHROMEOS) | 129 #if defined(OS_CHROMEOS) |
| 130 new FileIconSourceCros()); | 130 new FileIconSourceCros()); |
| 131 #else | 131 #else |
| 132 new FileIconSource()); | 132 new FileIconSource()); |
| 133 #endif // OS_CHROMEOS | 133 #endif // OS_CHROMEOS |
| 134 } | 134 } |
| 135 | 135 |
| 136 DownloadsDOMHandler::~DownloadsDOMHandler() { | 136 DownloadsDOMHandler::~DownloadsDOMHandler() { |
| 137 ClearDownloadItems(); | 137 ClearDownloadItems(); |
| 138 download_manager_->RemoveObserver(this); | 138 download_manager_->RemoveObserver(this); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // DownloadsDOMHandler, public: ----------------------------------------------- | 141 // DownloadsDOMHandler, public: ----------------------------------------------- |
| 142 | 142 |
| 143 void DownloadsDOMHandler::Init() { | 143 void DownloadsDOMHandler::Init() { |
| 144 download_manager_->AddObserver(this); | 144 download_manager_->AddObserver(this); |
| 145 | 145 |
| 146 Profile* profile = | 146 Profile* profile = |
| 147 Profile::FromBrowserContext(download_manager_->browser_context()); | 147 Profile::FromBrowserContext(download_manager_->BrowserContext()); |
| 148 Profile* original_profile = profile->GetOriginalProfile(); | 148 Profile* original_profile = profile->GetOriginalProfile(); |
| 149 if (original_profile != profile) { | 149 if (original_profile != profile) { |
| 150 original_download_manager_observer_.reset( | 150 original_download_manager_observer_.reset( |
| 151 new OriginalDownloadManagerObserver(this, original_profile)); | 151 new OriginalDownloadManagerObserver(this, original_profile)); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 void DownloadsDOMHandler::RegisterMessages() { | 155 void DownloadsDOMHandler::RegisterMessages() { |
| 156 web_ui_->RegisterMessageCallback("getDownloads", | 156 web_ui_->RegisterMessageCallback("getDownloads", |
| 157 base::Bind(&DownloadsDOMHandler::HandleGetDownloads, | 157 base::Bind(&DownloadsDOMHandler::HandleGetDownloads, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 218 } |
| 219 | 219 |
| 220 // A download has started or been deleted. Query our DownloadManager for the | 220 // A download has started or been deleted. Query our DownloadManager for the |
| 221 // current set of downloads. | 221 // current set of downloads. |
| 222 void DownloadsDOMHandler::ModelChanged() { | 222 void DownloadsDOMHandler::ModelChanged() { |
| 223 ClearDownloadItems(); | 223 ClearDownloadItems(); |
| 224 download_manager_->SearchDownloads(WideToUTF16(search_text_), | 224 download_manager_->SearchDownloads(WideToUTF16(search_text_), |
| 225 &download_items_); | 225 &download_items_); |
| 226 // If we have a parent profile, let it add its downloads to the results. | 226 // If we have a parent profile, let it add its downloads to the results. |
| 227 Profile* profile = | 227 Profile* profile = |
| 228 Profile::FromBrowserContext(download_manager_->browser_context()); | 228 Profile::FromBrowserContext(download_manager_->BrowserContext()); |
| 229 if (profile->GetOriginalProfile() != profile) { | 229 if (profile->GetOriginalProfile() != profile) { |
| 230 DownloadServiceFactory::GetForProfile( | 230 DownloadServiceFactory::GetForProfile( |
| 231 profile->GetOriginalProfile())->GetDownloadManager()->SearchDownloads( | 231 profile->GetOriginalProfile())->GetDownloadManager()->SearchDownloads( |
| 232 WideToUTF16(search_text_), &download_items_); | 232 WideToUTF16(search_text_), &download_items_); |
| 233 } | 233 } |
| 234 | 234 |
| 235 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); | 235 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); |
| 236 | 236 |
| 237 // Remove any extension downloads. | 237 // Remove any extension downloads. |
| 238 for (size_t i = 0; i < download_items_.size();) { | 238 for (size_t i = 0; i < download_items_.size();) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| 343 | 343 |
| 344 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { | 344 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { |
| 345 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); | 345 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); |
| 346 download_manager_->RemoveAllDownloads(); | 346 download_manager_->RemoveAllDownloads(); |
| 347 | 347 |
| 348 Profile* profile = | 348 Profile* profile = |
| 349 Profile::FromBrowserContext(download_manager_->browser_context()); | 349 Profile::FromBrowserContext(download_manager_->BrowserContext()); |
| 350 // If this is an incognito downloader, clear All should clear main download | 350 // If this is an incognito downloader, clear All should clear main download |
| 351 // manager as well. | 351 // manager as well. |
| 352 if (profile->GetOriginalProfile() != profile) | 352 if (profile->GetOriginalProfile() != profile) |
| 353 DownloadServiceFactory::GetForProfile( | 353 DownloadServiceFactory::GetForProfile( |
| 354 profile->GetOriginalProfile())-> | 354 profile->GetOriginalProfile())-> |
| 355 GetDownloadManager()->RemoveAllDownloads(); | 355 GetDownloadManager()->RemoveAllDownloads(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { | 358 void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { |
| 359 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); | 359 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 return NULL; | 413 return NULL; |
| 414 } | 414 } |
| 415 | 415 |
| 416 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 416 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
| 417 int id; | 417 int id; |
| 418 if (ExtractIntegerValue(args, &id)) { | 418 if (ExtractIntegerValue(args, &id)) { |
| 419 return GetDownloadById(id); | 419 return GetDownloadById(id); |
| 420 } | 420 } |
| 421 return NULL; | 421 return NULL; |
| 422 } | 422 } |
| OLD | NEW |