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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 20 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
21 #include "chrome/browser/download/download_history.h" | 21 #include "chrome/browser/download/download_history.h" |
22 #include "chrome/browser/download/download_prefs.h" | 22 #include "chrome/browser/download/download_prefs.h" |
| 23 #include "chrome/browser/download/download_service.h" |
| 24 #include "chrome/browser/download/download_service_factory.h" |
23 #include "chrome/browser/download/download_util.h" | 25 #include "chrome/browser/download/download_util.h" |
24 #include "chrome/browser/platform_util.h" | 26 #include "chrome/browser/platform_util.h" |
25 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 28 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
27 #include "chrome/browser/ui/webui/fileicon_source.h" | 29 #include "chrome/browser/ui/webui/fileicon_source.h" |
28 #include "chrome/browser/ui/webui/fileicon_source_chromeos.h" | 30 #include "chrome/browser/ui/webui/fileicon_source_chromeos.h" |
29 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
30 #include "content/browser/download/download_item.h" | 32 #include "content/browser/download/download_item.h" |
31 #include "content/browser/tab_contents/tab_contents.h" | 33 #include "content/browser/tab_contents/tab_contents.h" |
32 #include "content/browser/user_metrics.h" | 34 #include "content/browser/user_metrics.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 78 |
77 } // namespace | 79 } // namespace |
78 | 80 |
79 class DownloadsDOMHandler::OriginalDownloadManagerObserver | 81 class DownloadsDOMHandler::OriginalDownloadManagerObserver |
80 : public DownloadManager::Observer { | 82 : public DownloadManager::Observer { |
81 public: | 83 public: |
82 explicit OriginalDownloadManagerObserver( | 84 explicit OriginalDownloadManagerObserver( |
83 DownloadManager::Observer* observer, | 85 DownloadManager::Observer* observer, |
84 Profile* original_profile) | 86 Profile* original_profile) |
85 : observer_(observer) { | 87 : observer_(observer) { |
86 original_profile_download_manager_ = original_profile->GetDownloadManager(); | 88 original_profile_download_manager_ = |
| 89 DownloadServiceFactory::GetForProfile( |
| 90 original_profile)->GetDownloadManager(); |
87 original_profile_download_manager_->AddObserver(this); | 91 original_profile_download_manager_->AddObserver(this); |
88 } | 92 } |
89 | 93 |
90 virtual ~OriginalDownloadManagerObserver() { | 94 virtual ~OriginalDownloadManagerObserver() { |
91 if (original_profile_download_manager_) | 95 if (original_profile_download_manager_) |
92 original_profile_download_manager_->RemoveObserver(this); | 96 original_profile_download_manager_->RemoveObserver(this); |
93 } | 97 } |
94 | 98 |
95 // Observer interface. | 99 // Observer interface. |
96 virtual void ModelChanged() { | 100 virtual void ModelChanged() { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // A download has started or been deleted. Query our DownloadManager for the | 214 // A download has started or been deleted. Query our DownloadManager for the |
211 // current set of downloads. | 215 // current set of downloads. |
212 void DownloadsDOMHandler::ModelChanged() { | 216 void DownloadsDOMHandler::ModelChanged() { |
213 ClearDownloadItems(); | 217 ClearDownloadItems(); |
214 download_manager_->SearchDownloads(WideToUTF16(search_text_), | 218 download_manager_->SearchDownloads(WideToUTF16(search_text_), |
215 &download_items_); | 219 &download_items_); |
216 // If we have a parent profile, let it add its downloads to the results. | 220 // If we have a parent profile, let it add its downloads to the results. |
217 Profile* profile = | 221 Profile* profile = |
218 Profile::FromBrowserContext(download_manager_->browser_context()); | 222 Profile::FromBrowserContext(download_manager_->browser_context()); |
219 if (profile->GetOriginalProfile() != profile) { | 223 if (profile->GetOriginalProfile() != profile) { |
220 profile->GetOriginalProfile()->GetDownloadManager()->SearchDownloads( | 224 DownloadServiceFactory::GetForProfile( |
221 WideToUTF16(search_text_), &download_items_); | 225 profile->GetOriginalProfile())->GetDownloadManager()->SearchDownloads( |
| 226 WideToUTF16(search_text_), &download_items_); |
222 } | 227 } |
223 | 228 |
224 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); | 229 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); |
225 | 230 |
226 // Remove any extension downloads. | 231 // Remove any extension downloads. |
227 for (size_t i = 0; i < download_items_.size();) { | 232 for (size_t i = 0; i < download_items_.size();) { |
228 if (ChromeDownloadManagerDelegate::IsExtensionDownload(download_items_[i])) | 233 if (ChromeDownloadManagerDelegate::IsExtensionDownload(download_items_[i])) |
229 download_items_.erase(download_items_.begin() + i); | 234 download_items_.erase(download_items_.begin() + i); |
230 else | 235 else |
231 i++; | 236 i++; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 337 |
333 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { | 338 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { |
334 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); | 339 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); |
335 download_manager_->RemoveAllDownloads(); | 340 download_manager_->RemoveAllDownloads(); |
336 | 341 |
337 Profile* profile = | 342 Profile* profile = |
338 Profile::FromBrowserContext(download_manager_->browser_context()); | 343 Profile::FromBrowserContext(download_manager_->browser_context()); |
339 // If this is an incognito downloader, clear All should clear main download | 344 // If this is an incognito downloader, clear All should clear main download |
340 // manager as well. | 345 // manager as well. |
341 if (profile->GetOriginalProfile() != profile) | 346 if (profile->GetOriginalProfile() != profile) |
342 profile->GetOriginalProfile()->GetDownloadManager()->RemoveAllDownloads(); | 347 DownloadServiceFactory::GetForProfile( |
| 348 profile->GetOriginalProfile())-> |
| 349 GetDownloadManager()->RemoveAllDownloads(); |
343 } | 350 } |
344 | 351 |
345 void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { | 352 void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { |
346 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); | 353 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); |
347 FilePath path = DownloadPrefs::FromDownloadManager(download_manager_)-> | 354 FilePath path = DownloadPrefs::FromDownloadManager(download_manager_)-> |
348 download_path(); | 355 download_path(); |
349 | 356 |
350 #if defined(OS_MACOSX) | 357 #if defined(OS_MACOSX) |
351 // Must be called from the UI thread on Mac. | 358 // Must be called from the UI thread on Mac. |
352 platform_util::OpenItem(path); | 359 platform_util::OpenItem(path); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 return NULL; | 403 return NULL; |
397 } | 404 } |
398 | 405 |
399 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 406 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
400 int id; | 407 int id; |
401 if (ExtractIntegerValue(args, &id)) { | 408 if (ExtractIntegerValue(args, &id)) { |
402 return GetDownloadById(id); | 409 return GetDownloadById(id); |
403 } | 410 } |
404 return NULL; | 411 return NULL; |
405 } | 412 } |
OLD | NEW |