Skip to content

Commit

Permalink
Moved SidebarManager to ExtensionSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
ltilve committed Jun 3, 2015
1 parent 39964ab commit ff93fc0
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 82 deletions.
2 changes: 0 additions & 2 deletions chrome/browser/browser_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Profile;
class ProfileManager;
class PromoResourceService;
class SafeBrowsingService;
class SidebarManager;
class StatusTray;
class WatchDogThread;
#if defined(ENABLE_WEBRTC)
Expand Down Expand Up @@ -121,7 +120,6 @@ class BrowserProcess {
virtual rappor::RapporService* rappor_service() = 0;
virtual ProfileManager* profile_manager() = 0;
virtual PrefService* local_state() = 0;
virtual SidebarManager* sidebar_manager() = 0;
virtual net::URLRequestContextGetter* system_request_context() = 0;
virtual chrome_variations::VariationsService* variations_service() = 0;
virtual PromoResourceService* promo_resource_service() = 0;
Expand Down
15 changes: 0 additions & 15 deletions chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/sidebar/sidebar_manager.h"
#include "chrome/browser/status_icons/status_tray.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
Expand Down Expand Up @@ -175,7 +174,6 @@ BrowserProcessImpl::BrowserProcessImpl(
created_profile_manager_(false),
created_local_state_(false),
created_icon_manager_(false),
created_sidebar_manager_(false),
created_notification_ui_manager_(false),
created_safe_browsing_service_(false),
module_ref_count_(0),
Expand Down Expand Up @@ -569,13 +567,6 @@ PrefService* BrowserProcessImpl::local_state() {
return local_state_.get();
}

SidebarManager* BrowserProcessImpl::sidebar_manager() {
DCHECK(CalledOnValidThread());
if (!created_sidebar_manager_)
CreateSidebarManager();
return sidebar_manager_.get();
}

net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
DCHECK(CalledOnValidThread());
return io_thread()->system_url_request_context_getter();
Expand Down Expand Up @@ -1084,12 +1075,6 @@ void BrowserProcessImpl::CreateIconManager() {
icon_manager_.reset(new IconManager);
}

void BrowserProcessImpl::CreateSidebarManager() {
DCHECK(!created_sidebar_manager_ && sidebar_manager_.get() == NULL);
created_sidebar_manager_ = true;
sidebar_manager_ = new SidebarManager();
}

void BrowserProcessImpl::CreateIntranetRedirectDetector() {
DCHECK(intranet_redirect_detector_.get() == NULL);
scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
Expand Down
4 changes: 0 additions & 4 deletions chrome/browser/browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class BrowserProcessImpl : public BrowserProcess,
BrowserProcessPlatformPart* platform_part() override;
extensions::EventRouterForwarder* extension_event_router_forwarder() override;
NotificationUIManager* notification_ui_manager() override;
SidebarManager* sidebar_manager() override;
message_center::MessageCenter* message_center() override;
policy::BrowserPolicyConnector* browser_policy_connector() override;
policy::PolicyService* policy_service() override;
Expand Down Expand Up @@ -149,7 +148,6 @@ class BrowserProcessImpl : public BrowserProcess,
void CreateLocalState();
void CreateViewedPageTracker();
void CreateIconManager();
void CreateSidebarManager();
void CreateIntranetRedirectDetector();
void CreateNotificationUIManager();
void CreateStatusTrayManager();
Expand Down Expand Up @@ -208,8 +206,6 @@ class BrowserProcessImpl : public BrowserProcess,
#if !defined(OS_ANDROID)
scoped_ptr<RemoteDebuggingServer> remote_debugging_server_;
#endif
bool created_sidebar_manager_;
scoped_refptr<SidebarManager> sidebar_manager_;

#if defined(ENABLE_PRINT_PREVIEW)
scoped_refptr<printing::PrintPreviewDialogController>
Expand Down
13 changes: 13 additions & 0 deletions chrome/browser/extensions/extension_system_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "chrome/browser/extensions/navigation_observer.h"
#include "chrome/browser/extensions/shared_module_service.h"
#include "chrome/browser/extensions/shared_user_script_master.h"
#include "chrome/browser/extensions/sidebar_manager.h"
#include "chrome/browser/extensions/state_store_notification_observer.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -557,4 +558,16 @@ void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts(
base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason));
}

SidebarManager* ExtensionSystemImpl::sidebar_manager() {
if (!sidebar_manager_)
CreateSidebarManager();
return sidebar_manager_.get();
}

void ExtensionSystemImpl::CreateSidebarManager() {
DCHECK(sidebar_manager_.get() == NULL);
sidebar_manager_ = new SidebarManager();
}


} // namespace extensions
7 changes: 7 additions & 0 deletions chrome/browser/extensions/extension_system_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class InstallVerifier;
class NavigationObserver;
class SharedUserScriptMaster;
class StateStoreNotificationObserver;
// class SidebarManager;

// The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl.
// Implementation details: non-shared services are owned by
Expand Down Expand Up @@ -58,6 +59,10 @@ class ExtensionSystemImpl : public ExtensionSystem {
scoped_ptr<ExtensionSet> GetDependentExtensions(
const Extension* extension) override;

SidebarManager* sidebar_manager() override;
void CreateSidebarManager();


private:
friend class ExtensionSystemSharedFactory;

Expand Down Expand Up @@ -128,6 +133,8 @@ class ExtensionSystemImpl : public ExtensionSystem {

Shared* shared_;

scoped_refptr<SidebarManager> sidebar_manager_;

DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/sidebar/sidebar_container.h"
#include "chrome/browser/extensions/sidebar_container.h"

#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_view_host_factory.h"
#include "chrome/browser/extensions/sidebar_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sidebar/sidebar_manager.h"
#include "components/app_modal/javascript_dialog_manager.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
Expand Down Expand Up @@ -70,5 +70,6 @@ void SidebarContainer::Observe(int type,

// If we aren't the host of the popup, then disregard the notification.
if (content::Details<extensions::ExtensionHost>(host_.get()) == details)
SidebarManager::GetInstance()->HideSidebar(tab_, extension_id());
extensions::SidebarManager::GetFromContext(
host_->browser_context())->HideSidebar(tab_, extension_id());
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/sidebar/sidebar_manager.h"
#include "chrome/browser/extensions/sidebar_manager.h"

#include <vector>

#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sidebar/sidebar_container.h"
#include "chrome/browser/sidebar/sidebar_manager_observer.h"
#include "chrome/browser/extensions/sidebar_container.h"
#include "chrome/browser/extensions/sidebar_manager_observer.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/switches.h"
#include "url/gurl.h"

using content::BrowserContext;
using content::WebContents;

namespace extensions {
struct SidebarManager::SidebarStateForTab {
// Sidebars linked to this tab.
ContentIdToSidebarContainerMap content_id_to_sidebar_container;
// Content id of the currently active (expanded and visible) sidebar.
std::string active_content_id;
};


// static
SidebarManager* SidebarManager::GetInstance() {
return g_browser_process->sidebar_manager();
SidebarManager* SidebarManager::GetFromContext(BrowserContext* context) {
return ExtensionSystem::Get(context)->sidebar_manager();
}

SidebarManager::SidebarManager() {
Expand Down Expand Up @@ -306,3 +308,4 @@ void SidebarManager::AddObserver(SidebarManagerObserver* observer) {
void SidebarManager::RemoveObserver(SidebarManagerObserver* observer) {
observer_list_.RemoveObserver(observer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "chrome/browser/sidebar/sidebar_container.h"
#include "chrome/browser/extensions/sidebar_container.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"

Expand All @@ -20,9 +20,11 @@ class SidebarContainer;
class SidebarManagerObserver;

namespace content {
class BrowserContext;
class WebContents;
}

namespace extensions {
///////////////////////////////////////////////////////////////////////////////
// SidebarManager
//
Expand All @@ -32,8 +34,8 @@ class WebContents;
class SidebarManager : public content::NotificationObserver,
public base::RefCounted<SidebarManager> {
public:
// Returns s singleton instance.
static SidebarManager* GetInstance();
// Returns SidebarManager instance registered with BrowserContext.
static SidebarManager* GetFromContext(content::BrowserContext* context);

SidebarManager();

Expand Down Expand Up @@ -140,5 +142,6 @@ class SidebarManager : public content::NotificationObserver,

DISALLOW_COPY_AND_ASSIGN(SidebarManager);
};
}

#endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_MANAGER_H_
2 changes: 1 addition & 1 deletion chrome/browser/ui/cocoa/browser_window_cocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "base/mac/scoped_nsobject.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/extensions/extension_keybinding_registry.h"
#include "chrome/browser/sidebar/sidebar_manager_observer.h"
#include "chrome/browser/extensions/sidebar_manager_observer.h"
#include "chrome/browser/signin/signin_header_helper.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/ui/cocoa/browser_window_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/extensions/sidebar_container.h"
#include "chrome/browser/extensions/sidebar_manager.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/fullscreen.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/sidebar/sidebar_container.h"
#include "chrome/browser/sidebar/sidebar_manager.h"
#include "chrome/browser/signin/signin_header_helper.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/browser.h"
Expand Down Expand Up @@ -140,7 +140,8 @@ - (void)validateText:(NSString*)text {

browser_->search_model()->AddObserver(this);

SidebarManager *sidebar_manager = SidebarManager::GetInstance();
extensions::SidebarManager *sidebar_manager =
extensions::SidebarManager::GetFromContext(browser_->profile());
sidebar_manager->AddObserver(this);
}

Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/ui/cocoa/browser_window_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ - (void)updateDevToolsForContents:(WebContents*)contents {
}

- (void)updateSidebarForContents:(content::WebContents*)contents {
[sidebarController_ updateSidebarForTabContents:contents];
[sidebarController_ updateSidebarForTabContents:contents
withContext:browser_->profile()];
[sidebarController_ ensureContentsVisible];
}

Expand Down Expand Up @@ -1674,7 +1675,8 @@ - (void)onActivateTabWithContents:(WebContents*)contents {
windowShim_->UpdateTitleBar();

[sidebarController_
updateSidebarForTabContents:static_cast<content::WebContents*>(contents)];
updateSidebarForTabContents:static_cast<content::WebContents*>(contents)
withContext:browser_->profile()];
// Update the bookmark bar.
// TODO(viettrungluu): perhaps update to not terminate running animations (if
// applicable)?
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/ui/cocoa/sidebar_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@class NSSplitView;
@class NSView;
namespace content {
class BrowserContext;
class WebContents;
}

Expand All @@ -36,7 +37,8 @@ class WebContents;
// Depending on |contents|'s state, decides whether the sidebar
// should be shown or hidden and adjusts its width (|delegate_| handles
// the actual resize).
- (void)updateSidebarForTabContents:(content::WebContents*)contents;
- (void)updateSidebarForTabContents:(content::WebContents*)contents
withContext:(content::BrowserContext*)context;

// Call when the sidebar view is properly sized and the render widget host view
// should be put into the view hierarchy.
Expand Down
17 changes: 10 additions & 7 deletions chrome/browser/ui/cocoa/sidebar_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/sidebar/sidebar_manager.h"
#include "chrome/browser/extensions/sidebar_manager.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/web_contents.h"
Expand Down Expand Up @@ -65,17 +65,21 @@ - (NSSplitView*)view {
return splitView_.get();
}

- (void)updateSidebarForTabContents:(content::WebContents*)contents {
- (void)updateSidebarForTabContents:(content::WebContents*)contents
withContext:(content::BrowserContext*)context {
// Get the active sidebar content.
if (SidebarManager::GetInstance() == NULL) // Happens in tests.
extensions::SidebarManager* sidebarManager =
extensions::SidebarManager::GetFromContext(context);

if (sidebarManager == NULL) // Happens in tests.
return;

content::WebContents* sidebarContents = NULL;
if (contents) {
SidebarContainer* activeSidebar =
SidebarManager::GetInstance()->GetActiveSidebarContainerFor(contents);
sidebarManager->GetActiveSidebarContainerFor(contents);
if (!activeSidebar)
activeSidebar = SidebarManager::GetInstance()->MigrateSidebarTo(contents);
activeSidebar = sidebarManager->MigrateSidebarTo(contents);
if (activeSidebar)
sidebarContents = activeSidebar->host_contents();
}
Expand All @@ -93,8 +97,7 @@ - (void)updateSidebarForTabContents:(content::WebContents*)contents {
[self showSidebarContents:sidebarContents];

// Notify extensions.
SidebarManager::GetInstance()->NotifyStateChanges(oldSidebarContents,
sidebarContents);
sidebarManager->NotifyStateChanges(oldSidebarContents, sidebarContents);
}

- (void)ensureContentsVisible {
Expand Down
10 changes: 6 additions & 4 deletions chrome/browser/ui/cocoa/view_id_util_browsertest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/extensions/sidebar_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sidebar/sidebar_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
Expand Down Expand Up @@ -54,10 +54,12 @@ void DoTest() {
// Make sure sidebar is created to test VIEW_ID_SIDE_BAR_CONTAINER.
const char sidebar_content_id[] = "test_content_id";
GURL test_page_url = test_server()->GetURL(kSimplePage);
SidebarManager::GetInstance()->ShowSidebar(
static_cast<content::WebContents*>(
extensions::SidebarManager* sidebar_manager =
extensions::SidebarManager::GetFromContext(browser()->profile());

sidebar_manager->ShowSidebar(static_cast<content::WebContents*>(
browser()->tab_strip_model()->GetActiveWebContents()),
sidebar_content_id, test_page_url, browser());
sidebar_content_id, test_page_url, browser());

// Make sure docked devtools is created to test VIEW_ID_DEV_TOOLS_DOCKED
DevToolsWindow* devtools_window =
Expand Down
Loading

0 comments on commit ff93fc0

Please sign in to comment.