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

Side by Side Diff: chrome/browser/extensions/api/file_system/request_file_system_notification.cc

Issue 1032313002: Add a notification about auto-granted access to file systems. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/file_system/request_file_system_notifica tion.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
12 #include "chrome/browser/extensions/app_icon_loader_impl.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "extensions/common/extension.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/message_center/message_center.h"
17 #include "ui/message_center/notification.h"
18 #include "ui/message_center/notification_delegate.h"
19 #include "ui/message_center/notification_types.h"
20 #include "ui/message_center/notifier_settings.h"
21
22 using file_manager::VolumeInfo;
23 using message_center::Notification;
24
25 namespace {
26
27 // Extension icon size for the notification.
28 // TODO(mtomasz): Take into account DPI.
29 const int kIconSize = 48;
30
31 scoped_ptr<Notification> CreateAutoGrantedNotification(
32 const extensions::Extension& extension,
33 const VolumeInfo& volume_info,
34 bool writable,
35 message_center::NotificationDelegate* delegate) {
36 DCHECK(delegate);
37
38 const std::string notification_id =
39 extension.id() + "-" + volume_info.volume_id;
40 message_center::RichNotificationData data;
41 data.clickable = false;
42
43 // TODO(mtomasz): Share this code with RequestFileSystemDialogView.
44 const base::string16 display_name = base::UTF8ToUTF16(
45 !volume_info.volume_label.empty() ? volume_info.volume_label
46 : volume_info.volume_id);
47 const base::string16 message = l10n_util::GetStringFUTF16(
48 writable
49 ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_WRITABLE_MESSAGE
50 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_MESSAGE,
51 display_name);
52
53 scoped_ptr<Notification> notification(new Notification(
54 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
55 base::UTF8ToUTF16(extension.name()), message,
56 gfx::Image(), // Updated asynchronously later.
57 base::string16(), // display_source
58 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
59 notification_id),
60 data, delegate));
61
62 return notification.Pass();
63 }
64
65 } // namespace
66
67 // static
68 void RequestFileSystemNotification::ShowAutoGrantedNotification(
69 Profile* profile,
70 const extensions::Extension& extension,
71 const VolumeInfo& volume_info,
72 bool writable) {
73 DCHECK(profile);
74 scoped_refptr<RequestFileSystemNotification>
75 request_file_system_notification = make_scoped_refptr(
76 new RequestFileSystemNotification(profile, extension));
77 scoped_ptr<message_center::Notification> notification(
78 CreateAutoGrantedNotification(
79 extension, volume_info, writable,
80 request_file_system_notification.get() /* delegate */));
81 request_file_system_notification->Show(notification.Pass());
82 }
83
84 void RequestFileSystemNotification::SetAppImage(const std::string& id,
85 const gfx::ImageSkia& image) {
86 extension_icon_.reset(new gfx::Image(image));
87
88 // If there is a pending notification, then show it now.
89 if (pending_notification_.get()) {
90 pending_notification_->set_icon(*extension_icon_.get());
91 g_browser_process->message_center()->AddNotification(
92 pending_notification_.Pass());
93 }
94 }
95
96 RequestFileSystemNotification::RequestFileSystemNotification(
97 Profile* profile,
98 const extensions::Extension& extension)
99 : icon_loader_(
100 new extensions::AppIconLoaderImpl(profile, kIconSize, this)) {
101 icon_loader_->FetchImage(extension.id());
102 }
103
104 RequestFileSystemNotification::~RequestFileSystemNotification() {
105 }
106
107 void RequestFileSystemNotification::Show(
108 scoped_ptr<Notification> notification) {
109 pending_notification_.reset(notification.release());
110 // If the extension icon is not known yet, then defer showing the notification
111 // until it is (from SetAppImage).
112 if (!extension_icon_.get())
113 return;
114
115 pending_notification_->set_icon(*extension_icon_.get());
116 g_browser_process->message_center()->AddNotification(
117 pending_notification_.Pass());
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698