Chromium Code Reviews| 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 11% |
| copy from chrome/browser/google/google_search_counter_android.cc |
| copy to chrome/browser/ui/exclusive_access/exclusive_access_controller_base.cc |
| index 17699bee30e8f7293949ffbe3dee06a5640810bf..1795b266c1890157e16b912d13c265c015ead146 100644 |
| --- a/chrome/browser/google/google_search_counter_android.cc |
| +++ b/chrome/browser/ui/exclusive_access/exclusive_access_controller_base.cc |
| @@ -1,54 +1,122 @@ |
| -// 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( |
| + ExclusiveAccessControllerManager* manager, |
| + Browser* browser) |
| + : manager_(manager), |
| + browser_(browser), |
| + window_(browser->window()), |
| + profile_(browser->profile()), |
| + tab_with_exclusive_access_(nullptr) { |
| + DCHECK(window_); |
| + 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 to actually implement if necessary. |
|
scheib
2015/01/14 22:37:59
"will have to implement if"
Sriram
2015/01/15 00:34:28
Done.
|
| +} |
| + |
| +void ExclusiveAccessControllerBase::OnTabClosing( |
| + content::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 NotifyTabOfExitIfNecessary(), because at that point |
| + // |tab_with_exclusive_access_| may not be valid. Instead, we call it here |
| + // to clean up tab fullscreen related state. |
| + NotifyTabOfExclusiveAccessChange(); |
| + } |
| +} |
| + |
| +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_with_exclusive_access_ = tab; |
| + UpdateNotificationRegistrations(); |
| +} |
| + |
| +WebContents* ExclusiveAccessControllerBase::GetExclusiveAccessTab() const { |
| + return tab_with_exclusive_access_; |
| +} |
| + |
| +ExclusiveAccessControllerManager* ExclusiveAccessControllerBase::GetManager() |
| + const { |
| + return manager_; |
| +} |
| + |
| +Browser* ExclusiveAccessControllerBase::GetBrowser() const { |
| + return browser_; |
| +} |
| + |
| +Profile* ExclusiveAccessControllerBase::GetProfile() const { |
| + return profile_; |
| +} |
| + |
| +BrowserWindow* ExclusiveAccessControllerBase::GetWindow() const { |
| + return window_; |
| +} |
| + |
| +void ExclusiveAccessControllerBase::UpdateExclusiveAccessExitBubbleContent() { |
| + manager_->UpdateExclusiveAccessExitBubbleContent(); |
|
scheib
2015/01/14 22:37:59
For any Base method that just calls to a manager m
Sriram
2015/01/15 00:34:28
Done.
|
| +} |
| + |
| +ExclusiveAccessBubbleType |
| +ExclusiveAccessControllerBase::GetExclusiveAccessExitBubbleType() { |
| + return manager_->GetExclusiveAccessExitBubbleType(); |
| +} |
| + |
| +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(); |
| + } |
| } |