Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/download/download_completion_observer_win.cc

Issue 10832174: Fire a notification in Windows 8 metro chrome which informs the user about a completed download. Th… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 if (item->IsInProgress())
29 item->AddObserver(this);
30 }
31
32 void DownloadCompletionObserver::ManagerGoingDown(DownloadManager* manager) {
33 manager->RemoveObserver(this);
asanka 2012/08/07 19:05:15 There are some lifetime issues here. Notably, it w
ananta 2012/08/07 21:40:31 Done. Maintained the list of items in a set.
34 }
35
36 void DownloadCompletionObserver::OnDownloadUpdated(DownloadItem* download) {
37 if (!base::win::IsMetroProcess())
38 return;
39
40 switch (download->GetState()) {
41 case DownloadItem::COMPLETE: {
42 if (!download->GetOpenWhenComplete() &&
43 !download->ShouldOpenFileBasedOnExtension() &&
44 !download->IsTemporary() &&
45 !download->GetAutoOpened()) {
46 // In Windows 8 metro mode display a metro style notification which
47 // informs the user that the download is complete.
48 HMODULE metro = base::win::GetMetroModule();
49 base::win::MetroNotification display_notification =
50 reinterpret_cast< base::win::MetroNotification>(
51 ::GetProcAddress(metro, "DisplayNotification"));
52 DCHECK(display_notification);
53 if (display_notification) {
54 string16 title = l10n_util::GetStringUTF16(
55 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION_TITLE);
56 string16 body = l10n_util::GetStringUTF16(
57 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION);
58
59 // Dummy notification id. Every metro style notification needs a
60 // unique notification id.
61 std::string notification_id = kDownloadNotificationPrefix;
62 notification_id += base::IntToString(g_next_notification_id++);
63
64 display_notification(download->GetURL().spec().c_str(),
65 "",
asanka 2012/08/07 19:05:15 Nit: Indent
ananta 2012/08/07 21:40:31 Done.
66 title.c_str(),
67 body.c_str(),
68 L"",
69 notification_id.c_str());
70 }
71 }
72 download->RemoveObserver(this);
73 break;
74 }
75
76 case DownloadItem::REMOVING:
77 case DownloadItem::INTERRUPTED:
78 case DownloadItem::CANCELLED: {
79 download->RemoveObserver(this);
80 break;
81 }
82
83 default:
84 break;
85 }
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698