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

Unified Diff: chrome/browser/ui/exclusive_access/exclusive_access_controller_base.cc

Issue 836933005: Refactor fullscreen_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to TOT Created 5 years, 11 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/ui/exclusive_access/exclusive_access_controller_base.cc
diff --git a/chrome/browser/google/google_search_counter_android.cc b/chrome/browser/ui/exclusive_access/exclusive_access_controller_base.cc
similarity index 13%
copy from chrome/browser/google/google_search_counter_android.cc
copy to chrome/browser/ui/exclusive_access/exclusive_access_controller_base.cc
index 17699bee30e8f7293949ffbe3dee06a5640810bf..db8a243cad56fdaba299a21043d67b3d13d737eb 100644
--- a/chrome/browser/google/google_search_counter_android.cc
+++ b/chrome/browser/ui/exclusive_access/exclusive_access_controller_base.cc
@@ -1,54 +1,93 @@
-// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
-#include "chrome/browser/google/google_search_counter_android.h"
+#include "chrome/browser/ui/exclusive_access/exclusive_access_controller_base.h"
-#include "base/logging.h"
-#include "chrome/browser/google/google_search_counter.h"
-#include "chrome/browser/prerender/prerender_manager.h"
-#include "chrome/browser/prerender/prerender_manager_factory.h"
-#include "components/google/core/browser/google_search_metrics.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_types.h"
+#include "content/public/browser/web_contents.h"
-GoogleSearchCounterAndroid::GoogleSearchCounterAndroid(Profile* profile)
- : profile_(profile) {
- // We always listen for all COMMITTED navigations from all sources, as any
- // one of them could be a navigation of interest.
- registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources());
+using content::WebContents;
+
+ExclusiveAccessControllerBase::ExclusiveAccessControllerBase(
+ ExclusiveAccessManager* manager,
+ Browser* browser)
+ : manager_(manager),
+ browser_(browser),
+ profile_(browser->profile()),
+ tab_with_exclusive_access_(nullptr) {
+ DCHECK(profile_);
}
-GoogleSearchCounterAndroid::~GoogleSearchCounterAndroid() {
+ExclusiveAccessControllerBase::~ExclusiveAccessControllerBase() {
}
-void GoogleSearchCounterAndroid::ProcessCommittedEntry(
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- GoogleSearchCounter* counter = GoogleSearchCounter::GetInstance();
- DCHECK(counter);
- if (!counter->ShouldRecordCommittedDetails(details))
- return;
-
- const content::NavigationEntry& entry =
- *content::Details<content::LoadCommittedDetails>(details)->entry;
- prerender::PrerenderManager* prerender_manager =
- prerender::PrerenderManagerFactory::GetForProfile(profile_);
- // |prerender_manager| is NULL when prerendering is disabled.
- bool prerender_enabled =
- prerender_manager ? prerender_manager->IsEnabled() : false;
- counter->search_metrics()->RecordAndroidGoogleSearch(
- counter->GetGoogleSearchAccessPointForSearchNavEntry(entry),
- prerender_enabled);
-}
-
-void GoogleSearchCounterAndroid::Observe(
+GURL ExclusiveAccessControllerBase::GetExclusiveAccessBubbleURL() const {
+ return manager_->GetExclusiveAccessBubbleURL();
+}
+
+GURL ExclusiveAccessControllerBase::GetURLForExclusiveAccessBubble() const {
+ if (tab_with_exclusive_access_)
+ return tab_with_exclusive_access_->GetURL();
+ return GURL();
+}
+
+void ExclusiveAccessControllerBase::OnTabDeactivated(
+ WebContents* web_contents) {
+ if (web_contents == tab_with_exclusive_access_)
+ ExitExclusiveAccessIfNecessary();
+}
+
+void ExclusiveAccessControllerBase::OnTabDetachedFromView(
+ WebContents* old_contents) {
+ // Derived class will have to implement if necessary.
+}
+
+void ExclusiveAccessControllerBase::OnTabClosing(WebContents* web_contents) {
+ if (web_contents == tab_with_exclusive_access_) {
+ ExitExclusiveAccessIfNecessary();
+
+ // The call to exit exclusive access may result in asynchronous notification
+ // of state change (e.g. fullscreen change on Linux). We don't want to rely
+ // on it to call NotifyTabExclusiveAccessLost(), because at that point
+ // |tab_with_exclusive_access_| may not be valid. Instead, we call it here
+ // to clean up exclusive access tab related state.
+ NotifyTabExclusiveAccessLost();
+ }
+}
+
+void ExclusiveAccessControllerBase::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
- ProcessCommittedEntry(source, details);
+ if (content::Details<content::LoadCommittedDetails>(details)
+ ->is_navigation_to_different_page())
+ ExitExclusiveAccessIfNecessary();
+}
+
+void ExclusiveAccessControllerBase::SetTabWithExclusiveAccess(
+ WebContents* tab) {
+ // Tab should never be replaced with another tab, or
+ // UpdateNotificationRegistrations would need updating.
+ DCHECK(tab_with_exclusive_access_ == tab ||
+ tab_with_exclusive_access_ == nullptr || tab == nullptr);
+ tab_with_exclusive_access_ = tab;
+ UpdateNotificationRegistrations();
+}
+
+void ExclusiveAccessControllerBase::UpdateNotificationRegistrations() {
+ if (tab_with_exclusive_access_ && registrar_.IsEmpty()) {
+ registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::Source<content::NavigationController>(
+ &tab_with_exclusive_access_->GetController()));
+ } else if (!tab_with_exclusive_access_ && !registrar_.IsEmpty()) {
+ registrar_.RemoveAll();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698