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

Side by Side Diff: content/shell/browser/layout_test/layout_test_notification_manager.h

Issue 2300093002: Make //content responsible for generating notification Ids (Closed)
Patch Set: comments Created 4 years, 3 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ 5 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ 6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <map>
10 #include <string> 9 #include <string>
10 #include <unordered_map>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "content/public/browser/platform_notification_service.h" 15 #include "content/public/browser/platform_notification_service.h"
16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace content { 19 namespace content {
20 20
(...skipping 21 matching lines...) Expand all
42 blink::mojom::PermissionStatus CheckPermissionOnUIThread( 42 blink::mojom::PermissionStatus CheckPermissionOnUIThread(
43 BrowserContext* browser_context, 43 BrowserContext* browser_context,
44 const GURL& origin, 44 const GURL& origin,
45 int render_process_id) override; 45 int render_process_id) override;
46 blink::mojom::PermissionStatus CheckPermissionOnIOThread( 46 blink::mojom::PermissionStatus CheckPermissionOnIOThread(
47 ResourceContext* resource_context, 47 ResourceContext* resource_context,
48 const GURL& origin, 48 const GURL& origin,
49 int render_process_id) override; 49 int render_process_id) override;
50 void DisplayNotification( 50 void DisplayNotification(
51 BrowserContext* browser_context, 51 BrowserContext* browser_context,
52 const std::string& notification_id,
52 const GURL& origin, 53 const GURL& origin,
53 const PlatformNotificationData& notification_data, 54 const PlatformNotificationData& notification_data,
54 const NotificationResources& notification_resources, 55 const NotificationResources& notification_resources,
55 std::unique_ptr<DesktopNotificationDelegate> delegate, 56 std::unique_ptr<DesktopNotificationDelegate> delegate,
56 base::Closure* cancel_callback) override; 57 base::Closure* cancel_callback) override;
57 void DisplayPersistentNotification( 58 void DisplayPersistentNotification(
58 BrowserContext* browser_context, 59 BrowserContext* browser_context,
59 int64_t persistent_notification_id, 60 const std::string& notification_id,
60 const GURL& service_worker_scope, 61 const GURL& service_worker_scope,
61 const GURL& origin, 62 const GURL& origin,
62 const PlatformNotificationData& notification_data, 63 const PlatformNotificationData& notification_data,
63 const NotificationResources& notification_resources) override; 64 const NotificationResources& notification_resources) override;
64 void ClosePersistentNotification( 65 void ClosePersistentNotification(BrowserContext* browser_context,
65 BrowserContext* browser_context, 66 const std::string& notification_id) override;
66 int64_t persistent_notification_id) override;
67 bool GetDisplayedPersistentNotifications( 67 bool GetDisplayedPersistentNotifications(
68 BrowserContext* browser_context, 68 BrowserContext* browser_context,
69 std::set<std::string>* displayed_notifications) override; 69 std::set<std::string>* displayed_notifications) override;
70 70
71 private: 71 private:
72 // Structure to represent the information of a persistent notification. 72 // Structure to represent the information of a persistent notification.
73 struct PersistentNotification { 73 struct PersistentNotification {
74 BrowserContext* browser_context = nullptr; 74 BrowserContext* browser_context = nullptr;
75 GURL origin; 75 GURL origin;
76 int64_t persistent_id = 0;
77 }; 76 };
78 77
79 // Closes the notification titled |title|. Must be called on the UI thread. 78 // Closes the notification titled |title|. Must be called on the UI thread.
80 void Close(const std::string& title); 79 void Close(const std::string& title);
81 80
82 // Fakes replacing the notification identified by |params| when it has a tag 81 // Fakes replacing the notification identified by |notification_id|. Both
83 // and a previous notification has been displayed using the same tag. All 82 // persistent and non-persistent notifications will be considered for this.
84 // notifications, both page and persistent ones, will be considered for this. 83 void ReplaceNotificationIfNeeded(const std::string& notification_id);
85 void ReplaceNotificationIfNeeded(
86 const PlatformNotificationData& notification_data);
87 84
88 // Checks if |origin| has permission to display notifications. May be called 85 // Checks if |origin| has permission to display notifications. May be called
89 // on both the IO and the UI threads. 86 // on both the IO and the UI threads.
90 blink::mojom::PermissionStatus CheckPermission(const GURL& origin); 87 blink::mojom::PermissionStatus CheckPermission(const GURL& origin);
91 88
92 std::map<std::string, DesktopNotificationDelegate*> page_notifications_; 89 std::unordered_map<std::string, PersistentNotification>
93 std::map<std::string, PersistentNotification> persistent_notifications_; 90 persistent_notifications_;
91 std::unordered_map<std::string, std::unique_ptr<DesktopNotificationDelegate>>
92 non_persistent_notifications_;
94 93
95 std::map<std::string, std::string> replacements_; 94 // Mapping of titles to notification ids giving test a usable identifier.
95 std::unordered_map<std::string, std::string> notification_id_map_;
96 96
97 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_; 97 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_;
98 98
99 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); 99 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager);
100 }; 100 };
101 101
102 } // content 102 } // content
103 103
104 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ 104 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698