Commit 3df7e2b6 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Minor optimisation for IsForExperimentalHostedAppBrowser

This CL refactors IsForExperimentalHostedAppBrowser to check for the
presence of browser->hosted_app_controller instead of looking up the
extension registry.

Change-Id: I3d407f6ac98466fa3b409001bdc569fb5bb1b399
Reviewed-on: https://chromium-review.googlesource.com/1150945
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578240}
parent 138f2bbb
...@@ -150,6 +150,7 @@ ...@@ -150,6 +150,7 @@
#include "chrome/browser/ui/window_sizer/window_sizer.h" #include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/browser/upgrade_detector.h" #include "chrome/browser/upgrade_detector.h"
#include "chrome/browser/vr/vr_tab_helper.h" #include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/browser/web_applications/extensions/web_app_extension_helpers.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/custom_handlers/protocol_handler.h" #include "chrome/common/custom_handlers/protocol_handler.h"
...@@ -291,6 +292,21 @@ const extensions::Extension* GetExtensionForOrigin( ...@@ -291,6 +292,21 @@ const extensions::Extension* GetExtensionForOrigin(
#endif #endif
} }
std::unique_ptr<extensions::HostedAppBrowserController>
MaybeCreateHostedAppController(Browser* browser) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
const std::string extension_id =
web_app::GetExtensionIdFromApplicationName(browser->app_name());
const Extension* extension =
extensions::ExtensionRegistry::Get(browser->profile())
->GetExtensionById(extension_id,
extensions::ExtensionRegistry::EVERYTHING);
if (extension && extension->is_hosted_app())
return std::make_unique<extensions::HostedAppBrowserController>(browser);
#endif
return nullptr;
}
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -381,6 +397,7 @@ Browser::Browser(const CreateParams& params) ...@@ -381,6 +397,7 @@ Browser::Browser(const CreateParams& params)
toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)),
live_tab_context_(new BrowserLiveTabContext(this)), live_tab_context_(new BrowserLiveTabContext(this)),
synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), synced_window_delegate_(new BrowserSyncedWindowDelegate(this)),
hosted_app_controller_(MaybeCreateHostedAppController(this)),
bookmark_bar_state_(BookmarkBar::HIDDEN), bookmark_bar_state_(BookmarkBar::HIDDEN),
command_controller_(new chrome::BrowserCommandController(this)), command_controller_(new chrome::BrowserCommandController(this)),
window_has_shown_(false), window_has_shown_(false),
...@@ -435,11 +452,6 @@ Browser::Browser(const CreateParams& params) ...@@ -435,11 +452,6 @@ Browser::Browser(const CreateParams& params)
if (search::IsInstantExtendedAPIEnabled() && is_type_tabbed()) if (search::IsInstantExtendedAPIEnabled() && is_type_tabbed())
instant_controller_.reset(new BrowserInstantController(this)); instant_controller_.reset(new BrowserInstantController(this));
if (extensions::HostedAppBrowserController::IsForHostedApp(this)) {
hosted_app_controller_.reset(
new extensions::HostedAppBrowserController(this));
}
UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
ProfileMetrics::LogProfileLaunch(profile_); ProfileMetrics::LogProfileLaunch(profile_);
......
...@@ -279,6 +279,9 @@ class Browser : public TabStripModelObserver, ...@@ -279,6 +279,9 @@ class Browser : public TabStripModelObserver,
BrowserInstantController* instant_controller() { BrowserInstantController* instant_controller() {
return instant_controller_.get(); return instant_controller_.get();
} }
const extensions::HostedAppBrowserController* hosted_app_controller() const {
return hosted_app_controller_.get();
}
extensions::HostedAppBrowserController* hosted_app_controller() { extensions::HostedAppBrowserController* hosted_app_controller() {
return hosted_app_controller_.get(); return hosted_app_controller_.get();
} }
...@@ -991,6 +994,8 @@ class Browser : public TabStripModelObserver, ...@@ -991,6 +994,8 @@ class Browser : public TabStripModelObserver,
std::unique_ptr<BrowserInstantController> instant_controller_; std::unique_ptr<BrowserInstantController> instant_controller_;
// Helper which handles bookmark app specific browser configuration. // Helper which handles bookmark app specific browser configuration.
// This must be initialized before |command_controller_| to ensure the correct
// set of commands are enabled.
std::unique_ptr<extensions::HostedAppBrowserController> std::unique_ptr<extensions::HostedAppBrowserController>
hosted_app_controller_; hosted_app_controller_;
......
...@@ -106,24 +106,11 @@ gfx::ImageSkia GetFallbackAppIcon(Browser* browser) { ...@@ -106,24 +106,11 @@ gfx::ImageSkia GetFallbackAppIcon(Browser* browser) {
const char kPwaWindowEngagementTypeHistogram[] = const char kPwaWindowEngagementTypeHistogram[] =
"Webapp.Engagement.EngagementType"; "Webapp.Engagement.EngagementType";
// static
bool HostedAppBrowserController::IsForHostedApp(const Browser* browser) {
if (!browser)
return false;
const std::string extension_id =
web_app::GetExtensionIdFromApplicationName(browser->app_name());
const Extension* extension =
ExtensionRegistry::Get(browser->profile())->GetExtensionById(
extension_id, ExtensionRegistry::EVERYTHING);
return extension && extension->is_hosted_app();
}
// static // static
bool HostedAppBrowserController::IsForExperimentalHostedAppBrowser( bool HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
const Browser* browser) { const Browser* browser) {
return base::FeatureList::IsEnabled(::features::kDesktopPWAWindowing) && return browser && browser->hosted_app_controller() &&
IsForHostedApp(browser); base::FeatureList::IsEnabled(::features::kDesktopPWAWindowing);
} }
// static // static
......
...@@ -30,9 +30,6 @@ class Extension; ...@@ -30,9 +30,6 @@ class Extension;
class HostedAppBrowserController : public SiteEngagementObserver, class HostedAppBrowserController : public SiteEngagementObserver,
public TabStripModelObserver { public TabStripModelObserver {
public: public:
// Indicates whether |browser| is a hosted app browser.
static bool IsForHostedApp(const Browser* browser);
// Returns whether |browser| uses the experimental hosted app experience. // Returns whether |browser| uses the experimental hosted app experience.
static bool IsForExperimentalHostedAppBrowser(const Browser* browser); static bool IsForExperimentalHostedAppBrowser(const Browser* browser);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment