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++) { |
103 Show(); | 104 if (!(*it)->IsDone() && ++inprogress_download_count >= 2) { |
| 105 Show(); |
| 106 break; |
| 107 } |
| 108 } |
104 } | 109 } |
105 } | 110 } |
106 | 111 |
107 void DownloadGroupNotification::OnDownloadRemoved( | 112 void DownloadGroupNotification::OnDownloadRemoved( |
108 content::DownloadItem* download) { | 113 content::DownloadItem* download) { |
109 // The given |download| may be already free'd. | 114 // The given |download| may be already free'd. |
110 if (items_.find(download) != items_.end()) { | 115 if (items_.find(download) != items_.end()) { |
111 items_.erase(download); | 116 items_.erase(download); |
112 if (items_.size() <= 1) | 117 if (items_.size() <= 1) |
113 Hide(); | 118 Hide(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | 207 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
203 profile_, chrome::GetActiveDesktop()); | 208 profile_, chrome::GetActiveDesktop()); |
204 Browser* browser = browser_displayer.browser(); | 209 Browser* browser = browser_displayer.browser(); |
205 DCHECK(browser); | 210 DCHECK(browser); |
206 | 211 |
207 browser->OpenURL(content::OpenURLParams( | 212 browser->OpenURL(content::OpenURLParams( |
208 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), | 213 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), |
209 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 214 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
210 false /* is_renderer_initiated */)); | 215 false /* is_renderer_initiated */)); |
211 } | 216 } |
OLD | NEW |