OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/md_downloads/downloads_list_tracker.h" | 5 #include "chrome/browser/ui/webui/md_downloads/downloads_list_tracker.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 base::string16 file_name = | 228 base::string16 file_name = |
229 download_item->GetFileNameToReportUser().LossyDisplayName(); | 229 download_item->GetFileNameToReportUser().LossyDisplayName(); |
230 file_name = base::i18n::GetDisplayStringInLTRDirectionality(file_name); | 230 file_name = base::i18n::GetDisplayStringInLTRDirectionality(file_name); |
231 file_value->SetString("file_name", file_name); | 231 file_value->SetString("file_name", file_name); |
232 file_value->SetString("url", download_item->GetURL().spec()); | 232 file_value->SetString("url", download_item->GetURL().spec()); |
233 file_value->SetInteger("total", static_cast<int>( | 233 file_value->SetInteger("total", static_cast<int>( |
234 download_item->GetTotalBytes())); | 234 download_item->GetTotalBytes())); |
235 file_value->SetBoolean("file_externally_removed", | 235 file_value->SetBoolean("file_externally_removed", |
236 download_item->GetFileExternallyRemoved()); | 236 download_item->GetFileExternallyRemoved()); |
237 file_value->SetBoolean("resume", download_item->CanResume()); | 237 file_value->SetBoolean("resume", download_item->CanResume()); |
238 | 238 file_value->SetBoolean("otr", IsIncognito(*download_item)); |
239 bool incognito = false; | |
240 auto* original_manager = GetOriginalNotifierManager(); | |
241 if (original_manager) { | |
242 incognito = | |
243 original_manager->GetDownload(download_item->GetId()) == download_item; | |
244 } | |
245 file_value->SetBoolean("otr", incognito); | |
246 | 239 |
247 const char* danger_type = ""; | 240 const char* danger_type = ""; |
248 base::string16 last_reason_text; | 241 base::string16 last_reason_text; |
249 // -2 is invalid, -1 means indeterminate, and 0-100 are in-progress. | 242 // -2 is invalid, -1 means indeterminate, and 0-100 are in-progress. |
250 int percent = -2; | 243 int percent = -2; |
251 base::string16 progress_status_text; | 244 base::string16 progress_status_text; |
252 bool retry = false; | 245 bool retry = false; |
253 const char* state = nullptr; | 246 const char* state = nullptr; |
254 | 247 |
255 switch (download_item->GetState()) { | 248 switch (download_item->GetState()) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 file_value->SetString("danger_type", danger_type); | 293 file_value->SetString("danger_type", danger_type); |
301 file_value->SetString("last_reason_text", last_reason_text); | 294 file_value->SetString("last_reason_text", last_reason_text); |
302 file_value->SetInteger("percent", percent); | 295 file_value->SetInteger("percent", percent); |
303 file_value->SetString("progress_status_text", progress_status_text); | 296 file_value->SetString("progress_status_text", progress_status_text); |
304 file_value->SetBoolean("retry", retry); | 297 file_value->SetBoolean("retry", retry); |
305 file_value->SetString("state", state); | 298 file_value->SetString("state", state); |
306 | 299 |
307 return file_value.Pass(); | 300 return file_value.Pass(); |
308 } | 301 } |
309 | 302 |
| 303 bool DownloadsListTracker::IsIncognito(const DownloadItem& item) const { |
| 304 return GetOriginalNotifierManager() && GetMainNotifierManager() && |
| 305 GetMainNotifierManager()->GetDownload(item.GetId()) == &item; |
| 306 } |
| 307 |
310 const DownloadItem* DownloadsListTracker::GetItemForTesting(size_t index) | 308 const DownloadItem* DownloadsListTracker::GetItemForTesting(size_t index) |
311 const { | 309 const { |
312 if (index >= sorted_visible_items_.size()) | 310 if (index >= sorted_visible_items_.size()) |
313 return nullptr; | 311 return nullptr; |
314 | 312 |
315 SortedSet::iterator it = sorted_visible_items_.begin(); | 313 SortedSet::iterator it = sorted_visible_items_.begin(); |
316 std::advance(it, index); | 314 std::advance(it, index); |
317 return *it; | 315 return *it; |
318 } | 316 } |
319 | 317 |
320 bool DownloadsListTracker::ShouldShow(const DownloadItem& item) const { | 318 bool DownloadsListTracker::ShouldShow(const DownloadItem& item) const { |
321 return !download_crx_util::IsExtensionDownload(item) && | 319 return !download_crx_util::IsExtensionDownload(item) && |
322 !item.IsTemporary() && | 320 !item.IsTemporary() && |
323 !item.GetFileNameToReportUser().empty() && | 321 !item.GetFileNameToReportUser().empty() && |
324 !item.GetTargetFilePath().empty() && | 322 !item.GetTargetFilePath().empty() && |
325 DownloadItemModel(const_cast<DownloadItem*>(&item)).ShouldShowInShelf() && | 323 DownloadItemModel(const_cast<DownloadItem*>(&item)).ShouldShowInShelf() && |
326 DownloadQuery::MatchesQuery(search_terms_, item); | 324 DownloadQuery::MatchesQuery(search_terms_, item); |
327 } | 325 } |
328 | 326 |
329 bool DownloadsListTracker::StartTimeComparator::operator() ( | 327 bool DownloadsListTracker::StartTimeComparator::operator() ( |
330 const content::DownloadItem* a, const content::DownloadItem* b) const { | 328 const content::DownloadItem* a, const content::DownloadItem* b) const { |
331 return a->GetStartTime() > b->GetStartTime(); | 329 return a->GetStartTime() > b->GetStartTime(); |
332 } | 330 } |
333 | 331 |
334 void DownloadsListTracker::Init() { | 332 void DownloadsListTracker::Init() { |
335 Profile* profile = Profile::FromBrowserContext( | 333 Profile* profile = Profile::FromBrowserContext( |
336 GetMainNotifierManager()->GetBrowserContext()); | 334 GetMainNotifierManager()->GetBrowserContext()); |
337 if (profile->IsOffTheRecord()) { | 335 if (profile->IsOffTheRecord()) { |
| 336 Profile* original_profile = profile->GetOriginalProfile(); |
338 original_notifier_.reset(new AllDownloadItemNotifier( | 337 original_notifier_.reset(new AllDownloadItemNotifier( |
339 BrowserContext::GetDownloadManager(profile->GetOriginalProfile()), | 338 BrowserContext::GetDownloadManager(original_profile), this)); |
340 this)); | |
341 } | 339 } |
342 | 340 |
343 RebuildSortedSet(); | 341 RebuildSortedSet(); |
344 } | 342 } |
345 | 343 |
346 void DownloadsListTracker::RebuildSortedSet() { | 344 void DownloadsListTracker::RebuildSortedSet() { |
347 DownloadVector all_items, visible_items; | 345 DownloadVector all_items, visible_items; |
348 | 346 |
349 GetMainNotifierManager()->GetAllDownloads(&all_items); | 347 GetMainNotifierManager()->GetAllDownloads(&all_items); |
350 | 348 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return std::distance(sorted_visible_items_.begin(), position); | 383 return std::distance(sorted_visible_items_.begin(), position); |
386 } | 384 } |
387 | 385 |
388 void DownloadsListTracker::RemoveItem(const SortedSet::iterator& remove) { | 386 void DownloadsListTracker::RemoveItem(const SortedSet::iterator& remove) { |
389 if (sending_updates_) { | 387 if (sending_updates_) { |
390 web_ui_->CallJavascriptFunction("downloads.Manager.removeItem", | 388 web_ui_->CallJavascriptFunction("downloads.Manager.removeItem", |
391 base::FundamentalValue(GetIndex(remove))); | 389 base::FundamentalValue(GetIndex(remove))); |
392 } | 390 } |
393 sorted_visible_items_.erase(remove); | 391 sorted_visible_items_.erase(remove); |
394 } | 392 } |
OLD | NEW |