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/gtk/download/download_shelf_gtk.h" | 5 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/download/download_item_model.h" | 9 #include "chrome/browser/download/download_item_model.h" |
10 #include "chrome/browser/download/download_util.h" | 10 #include "chrome/browser/download/download_util.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 12 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
13 #include "chrome/browser/ui/gtk/custom_button.h" | 13 #include "chrome/browser/ui/gtk/custom_button.h" |
14 #include "chrome/browser/ui/gtk/download/download_item_gtk.h" | 14 #include "chrome/browser/ui/gtk/download/download_item_gtk.h" |
15 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 15 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
16 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h" | 16 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h" |
17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
18 #include "chrome/browser/ui/gtk/gtk_util.h" | 18 #include "chrome/browser/ui/gtk/gtk_util.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "content/browser/download/download_item.h" | 20 #include "content/browser/download/download_item.h" |
| 21 #include "content/browser/download/download_stats.h" |
21 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
24 #include "grit/theme_resources_standard.h" | 25 #include "grit/theme_resources_standard.h" |
25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
27 #include "ui/gfx/gtk_util.h" | 28 #include "ui/gfx/gtk_util.h" |
28 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
29 #include "ui/gfx/insets.h" | 30 #include "ui/gfx/insets.h" |
30 #include "ui/gfx/point.h" | 31 #include "ui/gfx/point.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 browser_->UpdateDownloadShelfVisibility(true); | 188 browser_->UpdateDownloadShelfVisibility(true); |
188 CancelAutoClose(); | 189 CancelAutoClose(); |
189 } | 190 } |
190 | 191 |
191 void DownloadShelfGtk::Close() { | 192 void DownloadShelfGtk::Close() { |
192 // When we are closing, we can vertically overlap the render view. Make sure | 193 // When we are closing, we can vertically overlap the render view. Make sure |
193 // we are on top. | 194 // we are on top. |
194 gdk_window_raise(shelf_.get()->window); | 195 gdk_window_raise(shelf_.get()->window); |
195 slide_widget_->Close(); | 196 slide_widget_->Close(); |
196 browser_->UpdateDownloadShelfVisibility(false); | 197 browser_->UpdateDownloadShelfVisibility(false); |
| 198 download_stats::RecordShelfSize(download_items_.size()); |
| 199 int num_pending = 0; |
| 200 size_t i = 0; |
| 201 while (i < download_items_.size()) { |
| 202 DownloadItem* download = download_items_[i]->get_download(); |
| 203 bool is_transfer_done = download->IsComplete() || |
| 204 download->IsCancelled() || |
| 205 download->IsInterrupted(); |
| 206 if (!is_transfer_done) |
| 207 ++num_pending; |
| 208 } |
| 209 download_stats::RecordShelfPendingSize(num_pending); |
197 SetCloseOnMouseOut(false); | 210 SetCloseOnMouseOut(false); |
198 } | 211 } |
199 | 212 |
200 Browser* DownloadShelfGtk::browser() const { | 213 Browser* DownloadShelfGtk::browser() const { |
201 return browser_; | 214 return browser_; |
202 } | 215 } |
203 | 216 |
204 void DownloadShelfGtk::Closed() { | 217 void DownloadShelfGtk::Closed() { |
205 // When the close animation is complete, remove all completed downloads. | 218 // When the close animation is complete, remove all completed downloads. |
206 size_t i = 0; | 219 size_t i = 0; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 382 |
370 MessageLoop::current()->PostDelayedTask( | 383 MessageLoop::current()->PostDelayedTask( |
371 FROM_HERE, | 384 FROM_HERE, |
372 auto_close_factory_.NewRunnableMethod(&DownloadShelfGtk::Close), | 385 auto_close_factory_.NewRunnableMethod(&DownloadShelfGtk::Close), |
373 kAutoCloseDelayMs); | 386 kAutoCloseDelayMs); |
374 } | 387 } |
375 | 388 |
376 void DownloadShelfGtk::MouseEnteredShelf() { | 389 void DownloadShelfGtk::MouseEnteredShelf() { |
377 auto_close_factory_.RevokeAll(); | 390 auto_close_factory_.RevokeAll(); |
378 } | 391 } |
OLD | NEW |