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

Unified Diff: chrome/browser/permissions/permission_infobar_manager.h

Issue 1337903002: permissions: remove PermissionQueueController and introduce PermissionInfoBarManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@callbacks-delegates
Patch Set: Fix compile failures Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/permissions/permission_infobar_manager.h
diff --git a/chrome/browser/permissions/permission_infobar_manager.h b/chrome/browser/permissions/permission_infobar_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..03b0f6d51594f6646ba8acc51d83f2df81c4f9b6
--- /dev/null
+++ b/chrome/browser/permissions/permission_infobar_manager.h
@@ -0,0 +1,84 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_
+#define CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_
+
+#include "base/callback_forward.h"
+#include "base/containers/scoped_ptr_hash_map.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/permissions/permission_request_id.h"
+#include "components/content_settings/core/common/content_settings.h"
+#include "components/content_settings/core/common/content_settings_types.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+class GURL;
+class PermissionInfoBarRequest;
+
+// Manages permsision requests using InfoBars. Requests are coalesced by
+// request_id. If multiple requests occur with overlapping permissions, both
+// will be shown and the last to have a response will be persisted.
+class PermissionInfoBarManager
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<PermissionInfoBarManager> {
+ public:
+ ~PermissionInfoBarManager() override;
+
+ // Queues an infobar request to be shown at some point. Requests with
+ // the same |request_id| are coalesced.
+ void CreateRequest(
+ const ContentSettingsType type,
+ const PermissionRequestID& request,
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ const base::Callback<void(bool, ContentSetting)>& callback);
+
+ // Cancels a specific infobar request.
+ void CancelRequest(const PermissionRequestID& request);
+
+ private:
+ friend class GeolocationPermissionContextTests;
+ friend class PermissionContextBaseTests;
+ friend class content::WebContentsUserData<PermissionInfoBarManager>;
+ using PermissionDecidedCallback = base::Callback<void(bool, ContentSetting)>;
+
+ explicit PermissionInfoBarManager(content::WebContents* web_contents);
+
+ // Posts a call to |ShowNextQueuedRequest| if there is no current request
+ // and |queued_requests_| is not empty.
+ void TriggerShowNextQueuedRequest();
+
+ // Shows the next request in |queued_requests_| if there is no current
+ // request and if |queued_requests_| is not empty
+ void ShowNextQueuedRequest();
+
+ // Callback function used when the infobar is dismissed, accepted or denied.
+ void OnInfoBarClosed();
+
+ // Removes the current request and shows a next queued request if available.
+ void ClearCurrentRequest();
+
+ // Returns whether the queue should be ignored when considering to show
+ // a new request.
+ bool ShouldIgnoreQueuedRequests();
+
+ // Pointer to the current request which is displayed to the user.
+ scoped_ptr<PermissionInfoBarRequest> current_request_;
+
+ // Indicates whether there is a currently pending call to
+ // |ShowNextQueuedRequest| in the UI thread even loop.
+ bool is_show_pending_;
+
+ // The mapping of request_id to queued requests. Note that |current_request_|
+ // will not be present in this map.
+ base::ScopedPtrHashMap<int,
+ scoped_ptr<PermissionInfoBarRequest>> queued_requests_;
+
+ base::WeakPtrFactory<PermissionInfoBarManager> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarManager);
+};
+
+#endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698