Chromium Code Reviews| 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/download/notification/download_group_notification.h" | 5 #include "chrome/browser/download/notification/download_group_notification.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 content::DownloadItem* download) { | 90 content::DownloadItem* download) { |
| 91 if (items_.find(download) != items_.end()) { | 91 if (items_.find(download) != items_.end()) { |
| 92 Update(); | 92 Update(); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 void DownloadGroupNotification::OnDownloadAdded( | 96 void DownloadGroupNotification::OnDownloadAdded( |
| 97 content::DownloadItem* download) { | 97 content::DownloadItem* download) { |
| 98 if (items_.find(download) == items_.end()) { | 98 if (items_.find(download) == items_.end()) { |
| 99 items_.insert(download); | 99 items_.insert(download); |
| 100 int inprogress_download_count = 0; | |
| 100 // If new download is started and there are more than 2 downloads in total, | 101 // If new download is started and there are more than 2 downloads in total, |
| 101 // show the group notification. | 102 // show the group notification. |
| 102 if (items_.size() >= 2) | 103 for (auto it = items_.begin(); it != items_.end(); it++) { |
|
asanka
2015/08/04 21:55:09
for (const auto& item : items_) {
if (!item->IsD
yoshiki
2015/08/05 09:09:31
Done.
| |
| 103 Show(); | 104 if (!(*it)->IsDone()) { |
| 105 if (++inprogress_download_count >= 2) { | |
| 106 Show(); | |
| 107 break; | |
| 108 } | |
| 109 } | |
| 110 } | |
| 104 } | 111 } |
| 105 } | 112 } |
| 106 | 113 |
| 107 void DownloadGroupNotification::OnDownloadRemoved( | 114 void DownloadGroupNotification::OnDownloadRemoved( |
| 108 content::DownloadItem* download) { | 115 content::DownloadItem* download) { |
| 109 // The given |download| may be already free'd. | 116 // The given |download| may be already free'd. |
| 110 if (items_.find(download) != items_.end()) { | 117 if (items_.find(download) != items_.end()) { |
| 111 items_.erase(download); | 118 items_.erase(download); |
| 112 if (items_.size() <= 1) | 119 if (items_.size() <= 1) |
| 113 Hide(); | 120 Hide(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | 209 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
| 203 profile_, chrome::GetActiveDesktop()); | 210 profile_, chrome::GetActiveDesktop()); |
| 204 Browser* browser = browser_displayer.browser(); | 211 Browser* browser = browser_displayer.browser(); |
| 205 DCHECK(browser); | 212 DCHECK(browser); |
| 206 | 213 |
| 207 browser->OpenURL(content::OpenURLParams( | 214 browser->OpenURL(content::OpenURLParams( |
| 208 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), | 215 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), |
| 209 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 216 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
| 210 false /* is_renderer_initiated */)); | 217 false /* is_renderer_initiated */)); |
| 211 } | 218 } |
| OLD | NEW |