| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download_status_updater.h" | 5 #include "chrome/browser/download/download_status_updater.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <shobjidl.h> | 8 #include <shobjidl.h> |
| 9 | 9 |
| 10 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 13 #include "base/win/metro.h" | 14 #include "base/win/metro.h" |
| 14 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
| 15 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
| 17 #include "chrome/browser/platform_util.h" |
| 16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "content/public/browser/browser_thread.h" |
| 19 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 20 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 22 | 25 |
| 23 // This code doesn't compile with Aura on. TODO(avi): hook it up so that | 26 // This code doesn't compile with Aura on. TODO(avi): hook it up so that |
| 24 // win_aura can do platform integration. | 27 // win_aura can do platform integration. |
| 25 #if !defined(USE_AURA) | 28 #if !defined(USE_AURA) |
| 26 | 29 |
| 27 namespace { | 30 namespace { |
| 28 | 31 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 HWND frame = window->GetNativeWindow(); | 63 HWND frame = window->GetNativeWindow(); |
| 61 if (download_count == 0 || progress == 1.0f) | 64 if (download_count == 0 || progress == 1.0f) |
| 62 taskbar->SetProgressState(frame, TBPF_NOPROGRESS); | 65 taskbar->SetProgressState(frame, TBPF_NOPROGRESS); |
| 63 else if (!progress_known) | 66 else if (!progress_known) |
| 64 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); | 67 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); |
| 65 else | 68 else |
| 66 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100); | 69 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100); |
| 67 } | 70 } |
| 68 } | 71 } |
| 69 | 72 |
| 73 void MetroDownloadNotificationClickedHandler(const wchar_t* download_path) { |
| 74 // Metro chrome will invoke these handlers on the metro thread. |
| 75 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 76 |
| 77 // Ensure that we invoke the function to display the downloaded item on the |
| 78 // UI thread. |
| 79 content::BrowserThread::PostTask( |
| 80 content::BrowserThread::UI, FROM_HERE, |
| 81 base::Bind(platform_util::ShowItemInFolder, FilePath(download_path))); |
| 82 } |
| 83 |
| 70 } // namespace | 84 } // namespace |
| 71 | 85 |
| 72 void DownloadStatusUpdater::UpdateAppIconDownloadProgress( | 86 void DownloadStatusUpdater::UpdateAppIconDownloadProgress( |
| 73 content::DownloadItem* download) { | 87 content::DownloadItem* download) { |
| 74 | 88 |
| 75 // Always update overall progress. | 89 // Always update overall progress. |
| 76 | |
| 77 float progress = 0; | 90 float progress = 0; |
| 78 int download_count = 0; | 91 int download_count = 0; |
| 79 bool progress_known = GetProgress(&progress, &download_count); | 92 bool progress_known = GetProgress(&progress, &download_count); |
| 80 UpdateTaskbarProgressBar(download_count, progress_known, progress); | 93 UpdateTaskbarProgressBar(download_count, progress_known, progress); |
| 81 | 94 |
| 82 // Fire notifications when downloads complete. | 95 // Fire notifications when downloads complete. |
| 83 | |
| 84 if (!base::win::IsMetroProcess()) | 96 if (!base::win::IsMetroProcess()) |
| 85 return; | 97 return; |
| 86 | 98 |
| 87 if (download->GetState() != content::DownloadItem::COMPLETE) | 99 if (download->GetState() != content::DownloadItem::COMPLETE) |
| 88 return; | 100 return; |
| 89 | 101 |
| 90 if (download->GetOpenWhenComplete() || | 102 if (download->GetOpenWhenComplete() || |
| 91 download->ShouldOpenFileBasedOnExtension() || | 103 download->ShouldOpenFileBasedOnExtension() || |
| 92 download->IsTemporary() || | 104 download->IsTemporary() || |
| 93 download->GetAutoOpened()) | 105 download->GetAutoOpened()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 // Dummy notification id. Every metro style notification needs a | 121 // Dummy notification id. Every metro style notification needs a |
| 110 // unique notification id. | 122 // unique notification id. |
| 111 std::string notification_id = kDownloadNotificationPrefix; | 123 std::string notification_id = kDownloadNotificationPrefix; |
| 112 notification_id += base::IntToString(g_next_notification_id++); | 124 notification_id += base::IntToString(g_next_notification_id++); |
| 113 | 125 |
| 114 display_notification(download->GetURL().spec().c_str(), | 126 display_notification(download->GetURL().spec().c_str(), |
| 115 "", | 127 "", |
| 116 title.c_str(), | 128 title.c_str(), |
| 117 body.c_str(), | 129 body.c_str(), |
| 118 L"", | 130 L"", |
| 119 notification_id.c_str()); | 131 notification_id.c_str(), |
| 132 MetroDownloadNotificationClickedHandler, |
| 133 download->GetTargetFilePath().value().c_str()); |
| 120 } | 134 } |
| 121 } | 135 } |
| 122 | 136 |
| 123 #endif // !USE_AURA | 137 #endif // !USE_AURA |
| OLD | NEW |