Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/download/download_completion_observer_win.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/string_number_conversions.h" | |
| 11 #include "base/win/metro.h" | |
| 12 #include "googleurl/src/gurl.h" | |
| 13 #include "grit/generated_resources.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 | |
| 16 using content::DownloadItem; | |
| 17 using content::DownloadManager; | |
| 18 | |
| 19 static const char kDownloadNotificationPrefix[] = "DownloadNotification"; | |
| 20 int g_next_notification_id = 0; | |
| 21 | |
| 22 void DownloadCompletionObserver::Initialize(DownloadManager* manager) { | |
| 23 manager->AddObserver(this); | |
| 24 } | |
| 25 | |
| 26 void DownloadCompletionObserver::OnDownloadCreated(DownloadManager* manager, | |
| 27 DownloadItem* item) { | |
| 28 item->AddObserver(this); | |
|
asanka
2012/08/07 17:31:58
Only add an observer if item->IsInProgress() is tr
ananta
2012/08/07 18:08:28
Done.
| |
| 29 } | |
| 30 | |
| 31 void DownloadCompletionObserver::ManagerGoingDown(DownloadManager* manager) { | |
| 32 manager->RemoveObserver(this); | |
| 33 } | |
| 34 | |
| 35 void DownloadCompletionObserver::OnDownloadUpdated(DownloadItem* download) { | |
| 36 if (!base::win::IsMetroProcess()) | |
| 37 return; | |
| 38 | |
|
asanka
2012/08/07 17:31:58
It is possible that the user has already marked th
ananta
2012/08/07 18:08:28
Done.
| |
| 39 if (download->GetState() == DownloadItem::COMPLETE) { | |
| 40 // In Windows 8 metro mode display a metro style notification which informs | |
| 41 // the user that the download is complete. | |
| 42 HMODULE metro = base::win::GetMetroModule(); | |
| 43 base::win::MetroNotification display_notification = | |
| 44 reinterpret_cast< base::win::MetroNotification>( | |
| 45 ::GetProcAddress(metro, "DisplayNotification")); | |
| 46 DCHECK(display_notification); | |
| 47 if (display_notification) { | |
| 48 string16 title = l10n_util::GetStringUTF16( | |
| 49 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION_TITLE); | |
| 50 string16 body = l10n_util::GetStringUTF16( | |
| 51 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION); | |
| 52 | |
| 53 // Dummy notification id. Every metro style notification needs a unique | |
| 54 // notification id. | |
| 55 std::string notification_id = kDownloadNotificationPrefix; | |
| 56 notification_id += base::IntToString(g_next_notification_id++); | |
| 57 | |
| 58 display_notification(download->GetURL().spec().c_str(), | |
| 59 "", | |
| 60 title.c_str(), | |
| 61 body.c_str(), | |
| 62 L"", | |
| 63 notification_id.c_str()); | |
| 64 } | |
|
asanka
2012/08/07 17:31:58
I suggest removing the observer when any of the te
ananta
2012/08/07 18:08:28
Done.
| |
| 65 } else if (download->GetState() == DownloadItem::REMOVING) { | |
| 66 download->RemoveObserver(this); | |
| 67 } | |
| 68 } | |
| OLD | NEW |