Commit 42968739 authored by riajiang's avatar riajiang Committed by Commit bot

Fix MediaClient::RequestCaptureState().

MediaClient::RequestCaptureState() was failing because chrome
does not have access to ash::SessionStateDelegate and ash::
ShellContentState.

1. Changed places that used ash::SessionStateDelegate to use
UserManager.

2. Changed places that used ash::ShellContentState to use
ChromeShellContentState. Right now the only places in ash that
use ash::ShellContentState are in tests so maybe we can move
ShellContentState to chrome completely in the future.

3. Changed MultiProfileMediaTrayItem and TrayUser in ash to
use SessionController to get the number of logged in users.

BUG=676091
TEST=ash_unittests

Review-Url: https://codereview.chromium.org/2615663002
Cr-Commit-Position: refs/heads/master@{#442679}
parent 24ccd068
......@@ -57,10 +57,7 @@ class SessionStateDelegateStub : public SessionStateDelegate {
// SessionStateDelegate:
int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
int NumberOfLoggedInUsers() const override {
// ash_shell has 2 users.
return 2;
}
int NumberOfLoggedInUsers() const override { return 1; }
bool IsActiveUserSessionStarted() const override { return true; }
bool CanLockScreen() const override { return true; }
bool IsScreenLocked() const override { return screen_locked_; }
......
......@@ -9,8 +9,27 @@
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_context.h"
ChromeShellContentState::ChromeShellContentState() {}
ChromeShellContentState::~ChromeShellContentState() {}
namespace {
ChromeShellContentState* g_instance = nullptr;
} // namespace
// static
ChromeShellContentState* ChromeShellContentState::GetInstance() {
DCHECK(g_instance);
return g_instance;
}
ChromeShellContentState::ChromeShellContentState() {
DCHECK(!g_instance);
g_instance = this;
}
ChromeShellContentState::~ChromeShellContentState() {
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
}
content::BrowserContext* ChromeShellContentState::GetActiveBrowserContext() {
DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
......
......@@ -11,10 +11,10 @@
class ChromeShellContentState : public ash::ShellContentState {
public:
ChromeShellContentState();
private:
~ChromeShellContentState() override;
static ChromeShellContentState* GetInstance();
// Overridden from ash::ShellContentState:
content::BrowserContext* GetActiveBrowserContext() override;
content::BrowserContext* GetBrowserContextByIndex(
......@@ -24,6 +24,7 @@ class ChromeShellContentState : public ash::ShellContentState {
content::BrowserContext* GetUserPresentingBrowserContextForWindow(
aura::Window* window) override;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeShellContentState);
};
......
......@@ -4,8 +4,6 @@
#include "chrome/browser/ui/ash/chrome_shell_content_state.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/wm_shell.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"
......@@ -15,9 +13,8 @@
content::BrowserContext* ChromeShellContentState::GetBrowserContextByIndex(
ash::UserIndex index) {
ash::SessionStateDelegate* session_state_delegate =
ash::WmShell::Get()->GetSessionStateDelegate();
DCHECK_LT(index, session_state_delegate->NumberOfLoggedInUsers());
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);
......
......@@ -4,9 +4,6 @@
#include "chrome/browser/ui/ash/media_client.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/wm_shell.h"
#include "ash/content/shell_content_state.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
......@@ -17,10 +14,12 @@
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/ash/chrome_shell_content_state.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/service_manager_connection.h"
......@@ -170,12 +169,11 @@ void MediaClient::RequestCaptureState() {
// thinks [user2, user1]. However, since parts of this system are already
// asynchronous (see OnRequestUpdate's PostTask()), we're not worrying about
// this right now.
ash::SessionStateDelegate* session_state_delegate =
ash::WmShell::Get()->GetSessionStateDelegate();
std::vector<MediaCaptureState> state;
for (ash::UserIndex i = 0;
i < session_state_delegate->NumberOfLoggedInUsers(); ++i) {
state.push_back(GetMediaCaptureStateByIndex(i));
for (uint32_t i = 0;
i < user_manager::UserManager::Get()->GetLoggedInUsers().size(); ++i) {
state.push_back(
GetMediaCaptureStateByIndex(static_cast<ash::UserIndex>(i)));
}
media_controller_->NotifyCaptureState(std::move(state));
......@@ -195,7 +193,7 @@ void MediaClient::OnRequestUpdate(int render_process_id,
MediaCaptureState MediaClient::GetMediaCaptureStateByIndex(int user_index) {
content::BrowserContext* context =
ash::ShellContentState::GetInstance()->GetBrowserContextByIndex(
ChromeShellContentState::GetInstance()->GetBrowserContextByIndex(
user_index);
return GetMediaCaptureStateOfAllWebContents(context);
}
......@@ -16,6 +16,7 @@
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/ash/cast_config_client_media_router.h"
#include "chrome/browser/ui/ash/chrome_new_window_client.h"
#include "chrome/browser/ui/ash/chrome_shell_content_state.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_mus.h"
#include "chrome/browser/ui/ash/media_client.h"
#include "chrome/browser/ui/views/ash/tab_scrubber.h"
......@@ -81,6 +82,7 @@ void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
chrome_launcher_controller_mus_ =
base::MakeUnique<ChromeLauncherControllerMus>();
chrome_launcher_controller_mus_->Init();
chrome_shell_content_state_ = base::MakeUnique<ChromeShellContentState>();
}
cast_config_client_media_router_ =
......
......@@ -14,6 +14,7 @@ class CastConfigClientMediaRouter;
class ChromeBrowserMainExtraPartsViews;
class ChromeLauncherControllerMus;
class ChromeNewWindowClient;
class ChromeShellContentState;
class ImmersiveContextMus;
class ImmersiveHandlerFactoryMus;
class MediaClient;
......@@ -37,6 +38,7 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts {
ChromeBrowserMainExtraPartsViews* extra_parts_views_;
std::unique_ptr<ChromeLauncherControllerMus> chrome_launcher_controller_mus_;
std::unique_ptr<ChromeShellContentState> chrome_shell_content_state_;
std::unique_ptr<CastConfigClientMediaRouter> cast_config_client_media_router_;
std::unique_ptr<MediaClient> media_client_;
std::unique_ptr<ImmersiveHandlerFactoryMus> immersive_handler_factory_;
......
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