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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 // The original profile's download manager. | 112 // The original profile's download manager. |
113 DownloadManager* original_profile_download_manager_; | 113 DownloadManager* original_profile_download_manager_; |
114 }; | 114 }; |
115 | 115 |
116 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) | 116 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) |
117 : search_text_(), | 117 : search_text_(), |
118 download_manager_(dlm), | 118 download_manager_(dlm), |
119 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 119 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
120 // Create our fileicon data source. | 120 // Create our fileicon data source. |
121 Profile::FromBrowserContext(dlm->browser_context())-> | 121 Profile::FromBrowserContext(dlm->BrowserContext())-> |
122 GetChromeURLDataManager()->AddDataSource( | 122 GetChromeURLDataManager()->AddDataSource( |
123 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
124 new FileIconSourceCros()); | 124 new FileIconSourceCros()); |
125 #else | 125 #else |
126 new FileIconSource()); | 126 new FileIconSource()); |
127 #endif // OS_CHROMEOS | 127 #endif // OS_CHROMEOS |
128 } | 128 } |
129 | 129 |
130 DownloadsDOMHandler::~DownloadsDOMHandler() { | 130 DownloadsDOMHandler::~DownloadsDOMHandler() { |
131 ClearDownloadItems(); | 131 ClearDownloadItems(); |
132 download_manager_->RemoveObserver(this); | 132 download_manager_->RemoveObserver(this); |
133 } | 133 } |
134 | 134 |
135 // DownloadsDOMHandler, public: ----------------------------------------------- | 135 // DownloadsDOMHandler, public: ----------------------------------------------- |
136 | 136 |
137 void DownloadsDOMHandler::Init() { | 137 void DownloadsDOMHandler::Init() { |
138 download_manager_->AddObserver(this); | 138 download_manager_->AddObserver(this); |
139 | 139 |
140 Profile* profile = | 140 Profile* profile = |
141 Profile::FromBrowserContext(download_manager_->browser_context()); | 141 Profile::FromBrowserContext(download_manager_->BrowserContext()); |
142 Profile* original_profile = profile->GetOriginalProfile(); | 142 Profile* original_profile = profile->GetOriginalProfile(); |
143 if (original_profile != profile) { | 143 if (original_profile != profile) { |
144 original_download_manager_observer_.reset( | 144 original_download_manager_observer_.reset( |
145 new OriginalDownloadManagerObserver(this, original_profile)); | 145 new OriginalDownloadManagerObserver(this, original_profile)); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 void DownloadsDOMHandler::RegisterMessages() { | 149 void DownloadsDOMHandler::RegisterMessages() { |
150 web_ui_->RegisterMessageCallback("getDownloads", | 150 web_ui_->RegisterMessageCallback("getDownloads", |
151 base::Bind(&DownloadsDOMHandler::HandleGetDownloads, | 151 base::Bind(&DownloadsDOMHandler::HandleGetDownloads, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 212 } |
213 | 213 |
214 // 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 |
215 // current set of downloads. | 215 // current set of downloads. |
216 void DownloadsDOMHandler::ModelChanged() { | 216 void DownloadsDOMHandler::ModelChanged() { |
217 ClearDownloadItems(); | 217 ClearDownloadItems(); |
218 download_manager_->SearchDownloads(WideToUTF16(search_text_), | 218 download_manager_->SearchDownloads(WideToUTF16(search_text_), |
219 &download_items_); | 219 &download_items_); |
220 // 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. |
221 Profile* profile = | 221 Profile* profile = |
222 Profile::FromBrowserContext(download_manager_->browser_context()); | 222 Profile::FromBrowserContext(download_manager_->BrowserContext()); |
223 if (profile->GetOriginalProfile() != profile) { | 223 if (profile->GetOriginalProfile() != profile) { |
224 DownloadServiceFactory::GetForProfile( | 224 DownloadServiceFactory::GetForProfile( |
225 profile->GetOriginalProfile())->GetDownloadManager()->SearchDownloads( | 225 profile->GetOriginalProfile())->GetDownloadManager()->SearchDownloads( |
226 WideToUTF16(search_text_), &download_items_); | 226 WideToUTF16(search_text_), &download_items_); |
227 } | 227 } |
228 | 228 |
229 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); | 229 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); |
230 | 230 |
231 // Remove any extension downloads. | 231 // Remove any extension downloads. |
232 for (size_t i = 0; i < download_items_.size();) { | 232 for (size_t i = 0; i < download_items_.size();) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 DownloadItem* file = GetDownloadByValue(args); | 333 DownloadItem* file = GetDownloadByValue(args); |
334 if (file) | 334 if (file) |
335 file->Cancel(true); | 335 file->Cancel(true); |
336 } | 336 } |
337 | 337 |
338 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { | 338 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { |
339 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); | 339 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); |
340 download_manager_->RemoveAllDownloads(); | 340 download_manager_->RemoveAllDownloads(); |
341 | 341 |
342 Profile* profile = | 342 Profile* profile = |
343 Profile::FromBrowserContext(download_manager_->browser_context()); | 343 Profile::FromBrowserContext(download_manager_->BrowserContext()); |
344 // 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 |
345 // manager as well. | 345 // manager as well. |
346 if (profile->GetOriginalProfile() != profile) | 346 if (profile->GetOriginalProfile() != profile) |
347 DownloadServiceFactory::GetForProfile( | 347 DownloadServiceFactory::GetForProfile( |
348 profile->GetOriginalProfile())-> | 348 profile->GetOriginalProfile())-> |
349 GetDownloadManager()->RemoveAllDownloads(); | 349 GetDownloadManager()->RemoveAllDownloads(); |
350 } | 350 } |
351 | 351 |
352 void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { | 352 void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { |
353 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); | 353 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 return NULL; | 403 return NULL; |
404 } | 404 } |
405 | 405 |
406 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 406 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
407 int id; | 407 int id; |
408 if (ExtractIntegerValue(args, &id)) { | 408 if (ExtractIntegerValue(args, &id)) { |
409 return GetDownloadById(id); | 409 return GetDownloadById(id); |
410 } | 410 } |
411 return NULL; | 411 return NULL; |
412 } | 412 } |
OLD | NEW |