BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / download / download_status_updater_win.cc
blob47ed35b9c4fbeff61d41b64fc38a36fb4b589f7b
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
3 // found in the LICENSE file.
5 #include "chrome/browser/download/download_status_updater.h"
7 #include <shobjidl.h>
8 #include <string>
10 #include "base/logging.h"
11 #include "base/win/scoped_comptr.h"
12 #include "base/win/windows_version.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_iterator.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "ui/views/win/hwnd_util.h"
18 namespace {
20 void UpdateTaskbarProgressBar(int download_count,
21 bool progress_known,
22 float progress) {
23 // Taskbar progress bar is only supported on Win7.
24 if (base::win::GetVersion() < base::win::VERSION_WIN7)
25 return;
27 base::win::ScopedComPtr<ITaskbarList3> taskbar;
28 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL,
29 CLSCTX_INPROC_SERVER);
30 if (FAILED(result)) {
31 DVLOG(1) << "Failed creating a TaskbarList object: " << result;
32 return;
35 result = taskbar->HrInit();
36 if (FAILED(result)) {
37 LOG(ERROR) << "Failed initializing an ITaskbarList3 interface.";
38 return;
41 // Iterate through all the browser windows, and draw the progress bar.
42 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
43 Browser* browser = *it;
44 BrowserWindow* window = browser->window();
45 if (!window)
46 continue;
47 HWND frame = views::HWNDForNativeWindow(window->GetNativeWindow());
48 if (download_count == 0 || progress == 1.0f)
49 taskbar->SetProgressState(frame, TBPF_NOPROGRESS);
50 else if (!progress_known)
51 taskbar->SetProgressState(frame, TBPF_INDETERMINATE);
52 else
53 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100);
57 } // namespace
59 void DownloadStatusUpdater::UpdateAppIconDownloadProgress(
60 content::DownloadItem* download) {
62 // Always update overall progress.
63 float progress = 0;
64 int download_count = 0;
65 bool progress_known = GetProgress(&progress, &download_count);
66 UpdateTaskbarProgressBar(download_count, progress_known, progress);