Override server-side simple-cache trial with commandline switches.
[chromium-blink-merge.git] / chrome / browser / geolocation / geolocation_infobar_queue_controller.h
blobcc87cba43ff4e1c69de25871aad79096202bbd44
1 // Copyright (c) 2012 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_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_
6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_
8 #include "base/bind.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
12 class GURL;
13 class GeolocationPermissionRequestID;
14 class InfoBarService;
15 class Profile;
17 // This class controls the geolocation infobar queue per profile, and it's
18 // used by GeolocationPermissionContext.
19 // An alternate approach would be to have this queue per tab, and use
20 // notifications to broadcast when permission is set / listen to notification to
21 // cancel pending requests. This may be specially useful if there are other
22 // things listening for such notifications.
23 // For the time being this class is self-contained and it doesn't seem pulling
24 // the notification infrastructure would simplify.
25 class GeolocationInfoBarQueueController : content::NotificationObserver {
26 public:
27 typedef base::Callback<void(bool /* allowed */)> PermissionDecidedCallback;
29 explicit GeolocationInfoBarQueueController(Profile* profile);
30 virtual ~GeolocationInfoBarQueueController();
32 // The InfoBar will be displayed immediately if the tab is not already
33 // displaying one, otherwise it'll be queued.
34 void CreateInfoBarRequest(const GeolocationPermissionRequestID& id,
35 const GURL& requesting_frame,
36 const GURL& embedder,
37 PermissionDecidedCallback callback);
39 // Cancels a specific infobar request.
40 void CancelInfoBarRequest(const GeolocationPermissionRequestID& id);
42 // Called by the InfoBarDelegate to notify permission has been set.
43 // It'll notify and dismiss any other pending InfoBar request for the same
44 // |requesting_frame| and embedder.
45 void OnPermissionSet(const GeolocationPermissionRequestID& id,
46 const GURL& requesting_frame,
47 const GURL& embedder,
48 bool update_content_setting,
49 bool allowed);
51 protected:
52 // content::NotificationObserver:
53 virtual void Observe(int type,
54 const content::NotificationSource& source,
55 const content::NotificationDetails& details) OVERRIDE;
57 private:
58 class PendingInfoBarRequest;
59 class RequestEquals;
61 typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests;
63 // Returns true if a geolocation infobar is already visible for the tab
64 // corresponding to |id|.
65 bool AlreadyShowingInfoBarForTab(
66 const GeolocationPermissionRequestID& id) const;
68 // Shows the next pending infobar for the tab corresponding to |id|, if any.
69 // Note that this may not be the pending request whose ID is |id| if other
70 // requests are higher in the queue. If we can't show infobars because there
71 // is no InfoBarService for this tab, removes all queued requests for this
72 // tab.
73 void ShowQueuedInfoBarForTab(const GeolocationPermissionRequestID& id);
75 void ClearPendingInfoBarRequestsForTab(
76 const GeolocationPermissionRequestID& id);
78 void RegisterForInfoBarNotifications(InfoBarService* infobar_service);
79 void UnregisterForInfoBarNotifications(InfoBarService* infobar_service);
81 void UpdateContentSetting(
82 const GURL& requesting_frame, const GURL& embedder, bool allowed);
84 content::NotificationRegistrar registrar_;
86 Profile* const profile_;
87 PendingInfoBarRequests pending_infobar_requests_;
89 DISALLOW_COPY_AND_ASSIGN(GeolocationInfoBarQueueController);
92 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_