OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/file_system/request_file_system_notifica
tion.h" | 5 #include "chrome/browser/extensions/api/file_system/request_file_system_notifica
tion.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/message_center/notifier_settings.h" | 22 #include "ui/message_center/notifier_settings.h" |
23 | 23 |
24 using file_manager::Volume; | 24 using file_manager::Volume; |
25 using message_center::Notification; | 25 using message_center::Notification; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Extension icon size for the notification. | 29 // Extension icon size for the notification. |
30 const int kIconSize = 48; | 30 const int kIconSize = 48; |
31 | 31 |
32 scoped_ptr<Notification> CreateAutoGrantedNotification( | 32 std::unique_ptr<Notification> CreateAutoGrantedNotification( |
33 const extensions::Extension& extension, | 33 const extensions::Extension& extension, |
34 const base::WeakPtr<Volume>& volume, | 34 const base::WeakPtr<Volume>& volume, |
35 bool writable, | 35 bool writable, |
36 message_center::NotificationDelegate* delegate) { | 36 message_center::NotificationDelegate* delegate) { |
37 DCHECK(delegate); | 37 DCHECK(delegate); |
38 | 38 |
39 // If the volume is gone, then do not show the notification. | 39 // If the volume is gone, then do not show the notification. |
40 if (!volume.get()) | 40 if (!volume.get()) |
41 return scoped_ptr<Notification>(nullptr); | 41 return std::unique_ptr<Notification>(nullptr); |
42 | 42 |
43 const std::string notification_id = | 43 const std::string notification_id = |
44 extension.id() + "-" + volume->volume_id(); | 44 extension.id() + "-" + volume->volume_id(); |
45 message_center::RichNotificationData data; | 45 message_center::RichNotificationData data; |
46 data.clickable = false; | 46 data.clickable = false; |
47 | 47 |
48 // TODO(mtomasz): Share this code with RequestFileSystemDialogView. | 48 // TODO(mtomasz): Share this code with RequestFileSystemDialogView. |
49 const base::string16 display_name = | 49 const base::string16 display_name = |
50 base::UTF8ToUTF16(!volume->volume_label().empty() ? volume->volume_label() | 50 base::UTF8ToUTF16(!volume->volume_label().empty() ? volume->volume_label() |
51 : volume->volume_id()); | 51 : volume->volume_id()); |
52 const base::string16 message = l10n_util::GetStringFUTF16( | 52 const base::string16 message = l10n_util::GetStringFUTF16( |
53 writable | 53 writable |
54 ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_WRITABLE_MESSAGE | 54 ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_WRITABLE_MESSAGE |
55 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_MESSAGE, | 55 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_MESSAGE, |
56 display_name); | 56 display_name); |
57 | 57 |
58 scoped_ptr<Notification> notification(new Notification( | 58 std::unique_ptr<Notification> notification(new Notification( |
59 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, | 59 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, |
60 base::UTF8ToUTF16(extension.name()), message, | 60 base::UTF8ToUTF16(extension.name()), message, |
61 gfx::Image(), // Updated asynchronously later. | 61 gfx::Image(), // Updated asynchronously later. |
62 base::string16(), // display_source | 62 base::string16(), // display_source |
63 GURL(), | 63 GURL(), |
64 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 64 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
65 notification_id), | 65 notification_id), |
66 data, delegate)); | 66 data, delegate)); |
67 | 67 |
68 return notification; | 68 return notification; |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 // static | 73 // static |
74 void RequestFileSystemNotification::ShowAutoGrantedNotification( | 74 void RequestFileSystemNotification::ShowAutoGrantedNotification( |
75 Profile* profile, | 75 Profile* profile, |
76 const extensions::Extension& extension, | 76 const extensions::Extension& extension, |
77 const base::WeakPtr<Volume>& volume, | 77 const base::WeakPtr<Volume>& volume, |
78 bool writable) { | 78 bool writable) { |
79 DCHECK(profile); | 79 DCHECK(profile); |
80 scoped_refptr<RequestFileSystemNotification> | 80 scoped_refptr<RequestFileSystemNotification> |
81 request_file_system_notification = make_scoped_refptr( | 81 request_file_system_notification = make_scoped_refptr( |
82 new RequestFileSystemNotification(profile, extension)); | 82 new RequestFileSystemNotification(profile, extension)); |
83 scoped_ptr<message_center::Notification> notification( | 83 std::unique_ptr<message_center::Notification> notification( |
84 CreateAutoGrantedNotification( | 84 CreateAutoGrantedNotification( |
85 extension, volume, writable, | 85 extension, volume, writable, |
86 request_file_system_notification.get() /* delegate */)); | 86 request_file_system_notification.get() /* delegate */)); |
87 if (notification.get()) | 87 if (notification.get()) |
88 request_file_system_notification->Show(std::move(notification)); | 88 request_file_system_notification->Show(std::move(notification)); |
89 } | 89 } |
90 | 90 |
91 void RequestFileSystemNotification::OnAppImageUpdated( | 91 void RequestFileSystemNotification::OnAppImageUpdated( |
92 const std::string& id, const gfx::ImageSkia& image) { | 92 const std::string& id, const gfx::ImageSkia& image) { |
93 extension_icon_.reset(new gfx::Image(image)); | 93 extension_icon_.reset(new gfx::Image(image)); |
(...skipping 11 matching lines...) Expand all Loading... |
105 const extensions::Extension& extension) | 105 const extensions::Extension& extension) |
106 : icon_loader_( | 106 : icon_loader_( |
107 new extensions::ExtensionAppIconLoader(profile, kIconSize, this)) { | 107 new extensions::ExtensionAppIconLoader(profile, kIconSize, this)) { |
108 icon_loader_->FetchImage(extension.id()); | 108 icon_loader_->FetchImage(extension.id()); |
109 } | 109 } |
110 | 110 |
111 RequestFileSystemNotification::~RequestFileSystemNotification() { | 111 RequestFileSystemNotification::~RequestFileSystemNotification() { |
112 } | 112 } |
113 | 113 |
114 void RequestFileSystemNotification::Show( | 114 void RequestFileSystemNotification::Show( |
115 scoped_ptr<Notification> notification) { | 115 std::unique_ptr<Notification> notification) { |
116 pending_notification_.reset(notification.release()); | 116 pending_notification_.reset(notification.release()); |
117 // If the extension icon is not known yet, then defer showing the notification | 117 // If the extension icon is not known yet, then defer showing the notification |
118 // until it is (from SetAppImage). | 118 // until it is (from SetAppImage). |
119 if (!extension_icon_.get()) | 119 if (!extension_icon_.get()) |
120 return; | 120 return; |
121 | 121 |
122 pending_notification_->set_icon(*extension_icon_.get()); | 122 pending_notification_->set_icon(*extension_icon_.get()); |
123 g_browser_process->message_center()->AddNotification( | 123 g_browser_process->message_center()->AddNotification( |
124 std::move(pending_notification_)); | 124 std::move(pending_notification_)); |
125 } | 125 } |
OLD | NEW |