Commit e360bc24 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Get rid of most of ash::ShellContentState.

Implemented by Chrome, the majority is only used from within //chrome/,
and only from one callsite each. Thus the implementations can be inlined.
The one remaining method in the interface is only used for ash tests.
Resolving that and removing the interface altogether is TODO.

Bug: 826374
Change-Id: Ib808ae70f3cf87be688b05c3cec15f35e4e121b5
Reviewed-on: https://chromium-review.googlesource.com/1107128
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569035}
parent 2b87b19c
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#ifndef ASH_CONTENT_ASH_WITH_CONTENT_EXPORT_H_ #ifndef ASH_CONTENT_ASH_WITH_CONTENT_EXPORT_H_
#define ASH_CONTENT_ASH_WITH_CONTENT_EXPORT_H_ #define ASH_CONTENT_ASH_WITH_CONTENT_EXPORT_H_
// Defines ASH_EXPORT so that functionality implemented by the Ash module can // Defines ASH_WITH_CONTENT_EXPORT so that functionality implemented by the Ash
// be exported to consumers. // module can be exported to consumers.
#if defined(COMPONENT_BUILD) #if defined(COMPONENT_BUILD)
#if defined(WIN32) #if defined(WIN32)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "ash/content/screen_orientation_delegate_chromeos.h"
#include "ash/content/shell_content_state.h" #include "ash/content/shell_content_state.h"
#include "ash/display/screen_orientation_controller.h" #include "ash/display/screen_orientation_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h" #include "ash/display/screen_orientation_controller_test_api.h"
...@@ -109,13 +110,7 @@ class ScreenOrientationControllerTest : public AshTestBase { ...@@ -109,13 +110,7 @@ class ScreenOrientationControllerTest : public AshTestBase {
ScreenOrientationControllerTest(); ScreenOrientationControllerTest();
~ScreenOrientationControllerTest() override; ~ScreenOrientationControllerTest() override;
content::ScreenOrientationDelegate* delegate() { content::ScreenOrientationDelegate* delegate() { return &delegate_; }
AshTestEnvironmentContent* test_environment_content =
static_cast<AshTestEnvironmentContent*>(
ash_test_helper()->ash_test_environment());
return test_environment_content->test_shell_content_state()
->screen_orientation_delegate();
}
// Creates and initializes and empty content::WebContents that is backed by a // Creates and initializes and empty content::WebContents that is backed by a
// content::BrowserContext and that has an aura::Window. // content::BrowserContext and that has an aura::Window.
...@@ -156,6 +151,8 @@ class ScreenOrientationControllerTest : public AshTestBase { ...@@ -156,6 +151,8 @@ class ScreenOrientationControllerTest : public AshTestBase {
} }
private: private:
ScreenOrientationDelegateChromeos delegate_;
// Optional content::BrowserContext used for two window tests. // Optional content::BrowserContext used for two window tests.
std::unique_ptr<content::BrowserContext> secondary_browser_context_; std::unique_ptr<content::BrowserContext> secondary_browser_context_;
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include "content/public/browser/screen_orientation_delegate.h" #include "content/public/browser/screen_orientation_delegate.h"
#include "base/macros.h" #include "ash/content/ash_with_content_export.h"
namespace ash { namespace ash {
class ScreenOrientationDelegateChromeos class ASH_WITH_CONTENT_EXPORT ScreenOrientationDelegateChromeos
: public content::ScreenOrientationDelegate { : public content::ScreenOrientationDelegate {
public: public:
ScreenOrientationDelegateChromeos(); ScreenOrientationDelegateChromeos();
...@@ -30,4 +30,4 @@ class ScreenOrientationDelegateChromeos ...@@ -30,4 +30,4 @@ class ScreenOrientationDelegateChromeos
} // namespace ash } // namespace ash
#endif // ASH_CONTENT_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ #endif // ASH_CONTENT_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_
\ No newline at end of file
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define ASH_CONTENT_SHELL_CONTENT_STATE_H_ #define ASH_CONTENT_SHELL_CONTENT_STATE_H_
#include "ash/content/ash_with_content_export.h" #include "ash/content/ash_with_content_export.h"
#include "ash/content/screen_orientation_delegate_chromeos.h"
#include "ash/public/cpp/session_types.h" #include "ash/public/cpp/session_types.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -31,25 +30,10 @@ class ASH_WITH_CONTENT_EXPORT ShellContentState { ...@@ -31,25 +30,10 @@ class ASH_WITH_CONTENT_EXPORT ShellContentState {
// current user scenario. Default implementation here returns nullptr. // current user scenario. Default implementation here returns nullptr.
virtual content::BrowserContext* GetActiveBrowserContext() = 0; virtual content::BrowserContext* GetActiveBrowserContext() = 0;
// Returns the browser context for the user given by |index|.
virtual content::BrowserContext* GetBrowserContextByIndex(
UserIndex index) = 0;
// Returns the browser context associated with the window.
virtual content::BrowserContext* GetBrowserContextForWindow(
aura::Window* window) = 0;
// Returns the browser context on which the window is currently shown. NULL
// means the window will be shown for every user.
virtual content::BrowserContext* GetUserPresentingBrowserContextForWindow(
aura::Window* window) = 0;
protected: protected:
ShellContentState(); ShellContentState();
virtual ~ShellContentState(); virtual ~ShellContentState();
ScreenOrientationDelegateChromeos orientation_delegate_;
private: private:
static ShellContentState* instance_; static ShellContentState* instance_;
......
...@@ -16,20 +16,4 @@ content::BrowserContext* ShellContentStateImpl::GetActiveBrowserContext() { ...@@ -16,20 +16,4 @@ content::BrowserContext* ShellContentStateImpl::GetActiveBrowserContext() {
return browser_context_; return browser_context_;
} }
content::BrowserContext* ShellContentStateImpl::GetBrowserContextByIndex(
UserIndex index) {
return browser_context_;
}
content::BrowserContext* ShellContentStateImpl::GetBrowserContextForWindow(
aura::Window* window) {
return browser_context_;
}
content::BrowserContext*
ShellContentStateImpl::GetUserPresentingBrowserContextForWindow(
aura::Window* window) {
return browser_context_;
}
} // namespace ash } // namespace ash
...@@ -19,11 +19,6 @@ class ShellContentStateImpl : public ShellContentState { ...@@ -19,11 +19,6 @@ class ShellContentStateImpl : public ShellContentState {
// Overridden from ShellContentState: // Overridden from ShellContentState:
content::BrowserContext* GetActiveBrowserContext() override; content::BrowserContext* GetActiveBrowserContext() override;
content::BrowserContext* GetBrowserContextByIndex(UserIndex index) override;
content::BrowserContext* GetBrowserContextForWindow(
aura::Window* window) override;
content::BrowserContext* GetUserPresentingBrowserContextForWindow(
aura::Window* window) override;
content::BrowserContext* browser_context_; content::BrowserContext* browser_context_;
......
...@@ -16,20 +16,4 @@ content::BrowserContext* TestShellContentState::GetActiveBrowserContext() { ...@@ -16,20 +16,4 @@ content::BrowserContext* TestShellContentState::GetActiveBrowserContext() {
return active_browser_context_.get(); return active_browser_context_.get();
} }
content::BrowserContext* TestShellContentState::GetBrowserContextByIndex(
UserIndex index) {
return nullptr;
}
content::BrowserContext* TestShellContentState::GetBrowserContextForWindow(
aura::Window* window) {
return nullptr;
}
content::BrowserContext*
TestShellContentState::GetUserPresentingBrowserContextForWindow(
aura::Window* window) {
return nullptr;
}
} // namespace ash } // namespace ash
...@@ -20,20 +20,11 @@ class TestShellContentState : public ShellContentState { ...@@ -20,20 +20,11 @@ class TestShellContentState : public ShellContentState {
public: public:
TestShellContentState(); TestShellContentState();
content::ScreenOrientationDelegate* screen_orientation_delegate() {
return &orientation_delegate_;
}
private: private:
~TestShellContentState() override; ~TestShellContentState() override;
// Overridden from ShellContentState: // Overridden from ShellContentState:
content::BrowserContext* GetActiveBrowserContext() override; content::BrowserContext* GetActiveBrowserContext() override;
content::BrowserContext* GetBrowserContextByIndex(UserIndex index) override;
content::BrowserContext* GetBrowserContextForWindow(
aura::Window* window) override;
content::BrowserContext* GetUserPresentingBrowserContextForWindow(
aura::Window* window) override;
std::unique_ptr<content::BrowserContext> active_browser_context_; std::unique_ptr<content::BrowserContext> active_browser_context_;
......
...@@ -1789,7 +1789,6 @@ split_static_library("ui") { ...@@ -1789,7 +1789,6 @@ split_static_library("ui") {
"ash/chrome_screenshot_grabber_test_observer.h", "ash/chrome_screenshot_grabber_test_observer.h",
"ash/chrome_shell_content_state.cc", "ash/chrome_shell_content_state.cc",
"ash/chrome_shell_content_state.h", "ash/chrome_shell_content_state.h",
"ash/chrome_shell_content_state_chromeos.cc",
"ash/chrome_shell_delegate.cc", "ash/chrome_shell_delegate.cc",
"ash/chrome_shell_delegate.h", "ash/chrome_shell_delegate.h",
"ash/ime_controller_client.cc", "ash/ime_controller_client.cc",
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
#include "chrome/browser/ui/ash/chrome_shell_content_state.h" #include "chrome/browser/ui/ash/chrome_shell_content_state.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
namespace { namespace {
...@@ -32,6 +30,5 @@ ChromeShellContentState::~ChromeShellContentState() { ...@@ -32,6 +30,5 @@ ChromeShellContentState::~ChromeShellContentState() {
} }
content::BrowserContext* ChromeShellContentState::GetActiveBrowserContext() { content::BrowserContext* ChromeShellContentState::GetActiveBrowserContext() {
DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
return ProfileManager::GetActiveUserProfile(); return ProfileManager::GetActiveUserProfile();
} }
...@@ -17,12 +17,6 @@ class ChromeShellContentState : public ash::ShellContentState { ...@@ -17,12 +17,6 @@ class ChromeShellContentState : public ash::ShellContentState {
// Overridden from ash::ShellContentState: // Overridden from ash::ShellContentState:
content::BrowserContext* GetActiveBrowserContext() override; content::BrowserContext* GetActiveBrowserContext() override;
content::BrowserContext* GetBrowserContextByIndex(
ash::UserIndex index) override;
content::BrowserContext* GetBrowserContextForWindow(
aura::Window* window) override;
content::BrowserContext* GetUserPresentingBrowserContextForWindow(
aura::Window* window) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ChromeShellContentState); DISALLOW_COPY_AND_ASSIGN(ChromeShellContentState);
......
// 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.
#include "chrome/browser/ui/ash/chrome_shell_content_state.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_context.h"
content::BrowserContext* ChromeShellContentState::GetBrowserContextByIndex(
ash::UserIndex index) {
DCHECK_LT(static_cast<size_t>(index),
user_manager::UserManager::Get()->GetLoggedInUsers().size());
user_manager::User* user =
user_manager::UserManager::Get()->GetLRULoggedInUsers()[index];
CHECK(user);
return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
}
content::BrowserContext* ChromeShellContentState::GetBrowserContextForWindow(
aura::Window* window) {
DCHECK(window);
// Speculative fix for multi-profile crash. crbug.com/661821
if (!MultiUserWindowManager::GetInstance())
return nullptr;
const AccountId& account_id =
MultiUserWindowManager::GetInstance()->GetWindowOwner(window);
return account_id.is_valid()
? multi_user_util::GetProfileFromAccountId(account_id)
: nullptr;
}
content::BrowserContext*
ChromeShellContentState::GetUserPresentingBrowserContextForWindow(
aura::Window* window) {
DCHECK(window);
// Speculative fix for multi-profile crash. crbug.com/661821
if (!MultiUserWindowManager::GetInstance())
return nullptr;
const AccountId& account_id =
MultiUserWindowManager::GetInstance()->GetUserPresentingWindow(window);
return account_id.is_valid()
? multi_user_util::GetProfileFromAccountId(account_id)
: nullptr;
}
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chromeos/extensions/media_player_api.h" #include "chrome/browser/chromeos/extensions/media_player_api.h"
#include "chrome/browser/chromeos/extensions/media_player_event_router.h" #include "chrome/browser/chromeos/extensions/media_player_event_router.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/chrome_shell_content_state.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
...@@ -198,10 +198,10 @@ void MediaClient::RequestCaptureState() { ...@@ -198,10 +198,10 @@ void MediaClient::RequestCaptureState() {
// asynchronous (see OnRequestUpdate's PostTask()), we're not worrying about // asynchronous (see OnRequestUpdate's PostTask()), we're not worrying about
// this right now. // this right now.
std::vector<MediaCaptureState> state; std::vector<MediaCaptureState> state;
for (uint32_t i = 0; for (user_manager::User* user :
i < user_manager::UserManager::Get()->GetLoggedInUsers().size(); ++i) { user_manager::UserManager::Get()->GetLoggedInUsers()) {
state.push_back( state.push_back(GetMediaCaptureStateOfAllWebContents(
GetMediaCaptureStateByIndex(static_cast<ash::UserIndex>(i))); chromeos::ProfileHelper::Get()->GetProfileByUser(user)));
} }
media_controller_->NotifyCaptureState(std::move(state)); media_controller_->NotifyCaptureState(std::move(state));
...@@ -225,10 +225,3 @@ void MediaClient::OnRequestUpdate(int render_process_id, ...@@ -225,10 +225,3 @@ void MediaClient::OnRequestUpdate(int render_process_id,
FROM_HERE, base::BindOnce(&MediaClient::RequestCaptureState, FROM_HERE, base::BindOnce(&MediaClient::RequestCaptureState,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
MediaCaptureState MediaClient::GetMediaCaptureStateByIndex(int user_index) {
content::BrowserContext* context =
ChromeShellContentState::GetInstance()->GetBrowserContextByIndex(
user_index);
return GetMediaCaptureStateOfAllWebContents(context);
}
...@@ -88,29 +88,6 @@ class TestShellContentState : public ash::ShellContentState { ...@@ -88,29 +88,6 @@ class TestShellContentState : public ash::ShellContentState {
: NULL; : NULL;
} }
content::BrowserContext* GetBrowserContextByIndex(
ash::UserIndex index) override {
return nullptr;
}
content::BrowserContext* GetBrowserContextForWindow(
aura::Window* window) override {
const AccountId& account_id =
MultiUserWindowManager::GetInstance()->GetWindowOwner(window);
return account_id.is_valid()
? multi_user_util::GetProfileFromAccountId(account_id)
: nullptr;
}
content::BrowserContext* GetUserPresentingBrowserContextForWindow(
aura::Window* window) override {
const AccountId& account_id =
MultiUserWindowManager::GetInstance()->GetUserPresentingWindow(window);
return account_id.is_valid()
? multi_user_util::GetProfileFromAccountId(account_id)
: nullptr;
}
DISALLOW_COPY_AND_ASSIGN(TestShellContentState); DISALLOW_COPY_AND_ASSIGN(TestShellContentState);
}; };
......
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
#include "chrome/browser/ui/ash/session_util.h" #include "chrome/browser/ui/ash/session_util.h"
#include "ash/content/shell_content_state.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -16,6 +17,31 @@ ...@@ -16,6 +17,31 @@
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
namespace {
// Gets the browser context (profile) associated with |window|. Either the
// profile of the user who owns the window or the profile of the desktop on
// which the window is positioned (for teleported windows) is returned, based on
// |presenting|.
content::BrowserContext* GetBrowserContextForWindow(aura::Window* window,
bool presenting) {
DCHECK(window);
// Speculative fix for multi-profile crash. crbug.com/661821
if (!MultiUserWindowManager::GetInstance())
return nullptr;
const AccountId& account_id =
presenting
? MultiUserWindowManager::GetInstance()->GetUserPresentingWindow(
window)
: MultiUserWindowManager::GetInstance()->GetWindowOwner(window);
return account_id.is_valid()
? multi_user_util::GetProfileFromAccountId(account_id)
: nullptr;
}
} // namespace
content::BrowserContext* GetActiveBrowserContext() { content::BrowserContext* GetActiveBrowserContext() {
DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size()); DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
return ProfileManager::GetActiveUserProfile(); return ProfileManager::GetActiveUserProfile();
...@@ -28,11 +54,10 @@ bool CanShowWindowForUser( ...@@ -28,11 +54,10 @@ bool CanShowWindowForUser(
if (user_manager::UserManager::Get()->GetLoggedInUsers().size() > 1u) { if (user_manager::UserManager::Get()->GetLoggedInUsers().size() > 1u) {
content::BrowserContext* active_browser_context = content::BrowserContext* active_browser_context =
get_context_callback.Run(); get_context_callback.Run();
ash::ShellContentState* state = ash::ShellContentState::GetInstance();
content::BrowserContext* owner_browser_context = content::BrowserContext* owner_browser_context =
state->GetBrowserContextForWindow(window); GetBrowserContextForWindow(window, false);
content::BrowserContext* shown_browser_context = content::BrowserContext* shown_browser_context =
state->GetUserPresentingBrowserContextForWindow(window); GetBrowserContextForWindow(window, true);
if (owner_browser_context && active_browser_context && if (owner_browser_context && active_browser_context &&
owner_browser_context != active_browser_context && owner_browser_context != active_browser_context &&
......
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