Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / notifications / platform_notification_service_impl.h
blob85ef42271ab759003dc352864d8ca4c1be6edd1c
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/singleton.h"
10 #include "base/strings/string16.h"
11 #include "chrome/browser/notifications/notification.h"
12 #include "content/public/browser/platform_notification_service.h"
13 #include "content/public/common/persistent_notification_status.h"
15 class NotificationDelegate;
16 class NotificationUIManager;
17 class Profile;
19 namespace gcm {
20 class PushMessagingBrowserTest;
23 // The platform notification service is the profile-agnostic entry point through
24 // which Web Notifications can be controlled.
25 class PlatformNotificationServiceImpl
26 : public content::PlatformNotificationService {
27 public:
28 // Returns the active instance of the service in the browser process. Safe to
29 // be called from any thread.
30 static PlatformNotificationServiceImpl* GetInstance();
32 // To be called when a persistent notification has been clicked on. The
33 // Service Worker associated with the registration will be started if
34 // needed, on which the event will be fired. Must be called on the UI thread.
35 void OnPersistentNotificationClick(
36 content::BrowserContext* browser_context,
37 int64 service_worker_registration_id,
38 const std::string& notification_id,
39 const GURL& origin,
40 const content::PlatformNotificationData& notification_data,
41 const base::Callback<void(content::PersistentNotificationStatus)>&
42 callback) const;
44 // Returns the Notification UI Manager through which notifications can be
45 // displayed to the user. Can be overridden for testing.
46 NotificationUIManager* GetNotificationUIManager() const;
48 // content::PlatformNotificationService implementation.
49 blink::WebNotificationPermission CheckPermissionOnUIThread(
50 content::BrowserContext* browser_context,
51 const GURL& origin,
52 int render_process_id) override;
53 blink::WebNotificationPermission CheckPermissionOnIOThread(
54 content::ResourceContext* resource_context,
55 const GURL& origin,
56 int render_process_id) override;
57 void DisplayNotification(
58 content::BrowserContext* browser_context,
59 const GURL& origin,
60 const SkBitmap& icon,
61 const content::PlatformNotificationData& notification_data,
62 scoped_ptr<content::DesktopNotificationDelegate> delegate,
63 base::Closure* cancel_callback) override;
64 void DisplayPersistentNotification(
65 content::BrowserContext* browser_context,
66 int64 service_worker_registration_id,
67 const GURL& origin,
68 const SkBitmap& icon,
69 const content::PlatformNotificationData& notification_data) override;
70 void ClosePersistentNotification(
71 content::BrowserContext* browser_context,
72 const std::string& persistent_notification_id) override;
74 private:
75 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>;
76 friend class PlatformNotificationServiceBrowserTest;
77 friend class PlatformNotificationServiceTest;
78 friend class PushMessagingBrowserTest;
79 FRIEND_TEST_ALL_PREFIXES(
80 PlatformNotificationServiceTest, DisplayNameForOrigin);
81 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest,
82 TestWebOriginDisplayName);
84 PlatformNotificationServiceImpl();
85 ~PlatformNotificationServiceImpl() override;
87 // Creates a new Web Notification-based Notification object.
88 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this
89 // through requires changing a whole lot of Notification constructor calls.
90 Notification CreateNotificationFromData(
91 Profile* profile,
92 const GURL& origin,
93 const SkBitmap& icon,
94 const content::PlatformNotificationData& notification_data,
95 NotificationDelegate* delegate) const;
97 // Overrides the Notification UI Manager to use to |manager|. Only to be
98 // used by tests. Tests are responsible for cleaning up after themselves.
99 void SetNotificationUIManagerForTesting(NotificationUIManager* manager);
101 // Returns a display name for an origin, to be used in permission infobar or
102 // on the frame of the notification toast. Different from the origin itself
103 // when dealing with extensions.
104 base::string16 DisplayNameForOrigin(Profile* profile,
105 const GURL& origin) const;
107 // Translates a URL into a slightly more readable version that may omit
108 // the port and scheme for common cases.
109 // TODO(dewittj): Remove this when the proper function is implemented in a
110 // chrome/browser/ui library function. See crbug.com/402698.
111 static base::string16 WebOriginDisplayName(const GURL& origin,
112 const std::string& languages);
114 // Weak reference. Ownership maintains with the test.
115 NotificationUIManager* notification_ui_manager_for_tests_;
117 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl);
120 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_