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

Side by Side Diff: chrome/browser/status_icons/desktop_notification_balloon_impl.cc

Issue 8375027: Implement notifications for the DisplayBalloon method on Linux and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing DisplayBalloon argument order (good). Created 9 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/status_icons/desktop_notification_balloon_impl.h"
6
7 #include "base/string_number_conversions.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/notifications/desktop_notification_service.h"
11 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/notifications/notification_delegate.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/webui/web_ui_util.h"
16 #include "third_party/skia/include/core/SkBitmap.h"
17
18 namespace {
19
20 // Prefix added to the notification ids.
21 const char kNotificationPrefix[] = "desktop_notification_balloon.";
22
23 void CloseBalloon(const std::string id) {
Andrew T Wilson (Slow) 2011/10/26 01:21:18 Is there a reason why this is broken out rather th
Leandro Graciá Gil 2011/10/26 13:52:00 This comes from a previous testing version that im
24 g_browser_process->notification_ui_manager()->CancelById(id);
25 }
26
27 class DummyNotificationDelegate : public NotificationDelegate {
28 public:
29 explicit DummyNotificationDelegate(const std::string& id) : id_(id) {}
30 virtual ~DummyNotificationDelegate() {}
31
32 virtual void Display() OVERRIDE {}
33 virtual void Error() OVERRIDE {}
34 virtual void Close(bool by_user) OVERRIDE {}
35 virtual void Click() OVERRIDE {}
36 virtual std::string id() const OVERRIDE { return kNotificationPrefix + id_; }
37
38 private:
39 std::string id_;
40 };
41
42 } // anonymous namespace
43
44 int DesktopNotificationBalloonImpl::id_count_ = 1;
45
46 DesktopNotificationBalloonImpl::DesktopNotificationBalloonImpl() {
47 }
48
49 DesktopNotificationBalloonImpl::~DesktopNotificationBalloonImpl() {
50 CloseBalloon(notification_->notification_id());
51 }
52
53 void DesktopNotificationBalloonImpl::DisplayBalloon(const SkBitmap& icon,
54 const string16& title,
55 const string16& contents) {
56 GURL icon_url;
57 if (!icon.empty())
58 icon_url = GURL(web_ui_util::GetImageDataUrl(icon));
59
60 GURL content_url(DesktopNotificationService::CreateDataUrl(
61 icon_url, title, contents, WebKit::WebTextDirectionDefault));
62
63 notification_.reset(new Notification(
64 GURL(), content_url, string16(), string16(),
65 new DummyNotificationDelegate(base::IntToString(id_count_++))));
66
67 // Allow IO access here to get the default profile since a profile is
68 // required for the rendering of the notification UI. No specific profile
69 // can be required by this API because of design reasons (e.g. this is also
70 // used by the background manager which doesn't know about profiles).
71 // The FILE thread cannot be used here as it will raise an invalid thread
72 // assertion when trying to add the notification.
73 // The only option left is to allow IO as an exception.
74 base::ThreadRestrictions::ScopedAllowIO allow_io;
75 g_browser_process->notification_ui_manager()->Add(
Andrew T Wilson (Slow) 2011/10/26 01:21:18 This makes me somewhat nervous - can you have mira
Leandro Graciá Gil 2011/10/26 13:52:00 Done.
76 *notification_.get(), ProfileManager::GetDefaultProfile());
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698