Chromium Code Reviews| 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 | 90 |
|
robertshield
2012/10/09 21:17:14
nit: blank line
ananta
2012/10/09 21:20:53
Done.
| |
| 77 float progress = 0; | 91 float progress = 0; |
| 78 int download_count = 0; | 92 int download_count = 0; |
| 79 bool progress_known = GetProgress(&progress, &download_count); | 93 bool progress_known = GetProgress(&progress, &download_count); |
| 80 UpdateTaskbarProgressBar(download_count, progress_known, progress); | 94 UpdateTaskbarProgressBar(download_count, progress_known, progress); |
| 81 | 95 |
| 82 // Fire notifications when downloads complete. | 96 // Fire notifications when downloads complete. |
| 83 | 97 |
|
robertshield
2012/10/09 21:17:14
nit: blank line
ananta
2012/10/09 21:20:53
Done.
| |
| 84 if (!base::win::IsMetroProcess()) | 98 if (!base::win::IsMetroProcess()) |
| 85 return; | 99 return; |
| 86 | 100 |
| 87 if (download->GetState() != content::DownloadItem::COMPLETE) | 101 if (download->GetState() != content::DownloadItem::COMPLETE) |
| 88 return; | 102 return; |
| 89 | 103 |
| 90 if (download->GetOpenWhenComplete() || | 104 if (download->GetOpenWhenComplete() || |
| 91 download->ShouldOpenFileBasedOnExtension() || | 105 download->ShouldOpenFileBasedOnExtension() || |
| 92 download->IsTemporary() || | 106 download->IsTemporary() || |
| 93 download->GetAutoOpened()) | 107 download->GetAutoOpened()) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 109 // Dummy notification id. Every metro style notification needs a | 123 // Dummy notification id. Every metro style notification needs a |
| 110 // unique notification id. | 124 // unique notification id. |
| 111 std::string notification_id = kDownloadNotificationPrefix; | 125 std::string notification_id = kDownloadNotificationPrefix; |
| 112 notification_id += base::IntToString(g_next_notification_id++); | 126 notification_id += base::IntToString(g_next_notification_id++); |
| 113 | 127 |
| 114 display_notification(download->GetURL().spec().c_str(), | 128 display_notification(download->GetURL().spec().c_str(), |
| 115 "", | 129 "", |
| 116 title.c_str(), | 130 title.c_str(), |
| 117 body.c_str(), | 131 body.c_str(), |
| 118 L"", | 132 L"", |
| 119 notification_id.c_str()); | 133 notification_id.c_str(), |
| 134 MetroDownloadNotificationClickedHandler, | |
| 135 download->GetFullPath().value().c_str()); | |
| 120 } | 136 } |
| 121 } | 137 } |
| 122 | 138 |
| 123 #endif // !USE_AURA | 139 #endif // !USE_AURA |
| OLD | NEW |