Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / permissions / permission_queue_controller.h
blobcbc52738d317a523d90328cf31687822bc7d1185
1 // Copyright 2013 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_PERMISSIONS_PERMISSION_QUEUE_CONTROLLER_H_
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_QUEUE_CONTROLLER_H_
8 #include "base/bind.h"
9 #include "components/content_settings/core/common/content_settings.h"
10 #include "components/content_settings/core/common/content_settings_types.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
14 class GURL;
15 class PermissionRequestID;
16 class InfoBarService;
17 class Profile;
19 // This class controls an infobar queue per profile, and it's used by
20 // GeolocationPermissionContext, and so on.
21 // An alternate approach would be to have this queue per tab, and use
22 // notifications to broadcast when permission is set / listen to notification to
23 // cancel pending requests. This may be specially useful if there are other
24 // things listening for such notifications.
25 // For the time being this class is self-contained and it doesn't seem pulling
26 // the notification infrastructure would simplify.
27 class PermissionQueueController : public content::NotificationObserver {
28 public:
29 using PermissionDecidedCallback = base::Callback<void(ContentSetting)>;
31 PermissionQueueController(Profile* profile, ContentSettingsType type);
32 ~PermissionQueueController() override;
34 // The InfoBar will be displayed immediately if the tab is not already
35 // displaying one, otherwise it'll be queued.
36 void CreateInfoBarRequest(const PermissionRequestID& id,
37 const GURL& requesting_frame,
38 const GURL& embedder,
39 const PermissionDecidedCallback& callback);
41 // Cancels a specific infobar request.
42 void CancelInfoBarRequest(const PermissionRequestID& id);
44 // Called by the InfoBarDelegate to notify permission has been set.
45 // It'll notify and dismiss any other pending InfoBar request for the same
46 // |requesting_frame| and embedder.
47 void OnPermissionSet(const PermissionRequestID& id,
48 const GURL& requesting_frame,
49 const GURL& embedder,
50 bool update_content_setting,
51 bool allowed);
53 // Performs the update to content settings for a particular request frame
54 // context.
55 void UpdateContentSetting(
56 const GURL& requesting_frame, const GURL& embedder, bool allowed);
58 protected:
59 // content::NotificationObserver:
60 void Observe(int type,
61 const content::NotificationSource& source,
62 const content::NotificationDetails& details) override;
64 private:
65 class PendingInfobarRequest;
66 class RequestEquals;
68 typedef std::vector<PendingInfobarRequest> PendingInfobarRequests;
70 // Returns true if a geolocation infobar is already visible for the tab
71 // corresponding to |id|.
72 bool AlreadyShowingInfoBarForTab(const PermissionRequestID& id) const;
74 // Shows the next pending infobar for the tab corresponding to |id|, if any.
75 // Note that this may not be the pending request whose ID is |id| if other
76 // requests are higher in the queue. If we can't show infobars because there
77 // is no InfoBarService for this tab, removes all queued requests for this
78 // tab.
79 void ShowQueuedInfoBarForTab(const PermissionRequestID& id);
81 void ClearPendingInfobarRequestsForTab(const PermissionRequestID& id);
83 void RegisterForInfoBarNotifications(InfoBarService* infobar_service);
84 void UnregisterForInfoBarNotifications(InfoBarService* infobar_service);
86 content::NotificationRegistrar registrar_;
88 Profile* const profile_;
89 ContentSettingsType type_;
90 PendingInfobarRequests pending_infobar_requests_;
91 bool in_shutdown_;
93 DISALLOW_COPY_AND_ASSIGN(PermissionQueueController);
96 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_QUEUE_CONTROLLER_H_