Commit a8b6b277 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: exposes functions in ash to get window by window service ids

This is useful in single-process-mash to correlate windows.

BUG=756085
TEST=none

Change-Id: I8845b62754ba5c34d352b49491078e69a35719aa
Reviewed-on: https://chromium-review.googlesource.com/c/1323705
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606130}
parent 668af6e3
......@@ -84,6 +84,7 @@ component("ash") {
"wm/window_util.h",
"wm/wm_event.h",
"wm/workspace/workspace_window_resizer.h",
"ws/window_lookup.h",
]
sources = [
"accelerators/accelerator_commands.cc",
......@@ -1248,6 +1249,7 @@ component("ash") {
"ws/ash_gpu_interface_provider.h",
"ws/ash_window_manager.cc",
"ws/ash_window_manager.h",
"ws/window_lookup.cc",
"ws/window_service_delegate_impl.cc",
"ws/window_service_delegate_impl.h",
"ws/window_service_owner.cc",
......
// Copyright 2018 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 "ash/ws/window_lookup.h"
#include "ash/shell.h"
#include "ash/ws/window_service_owner.h"
#include "services/ws/window_service.h"
namespace ash {
namespace window_lookup {
aura::Window* GetWindowByClientId(ws::Id transport_id) {
return Shell::Get()
->window_service_owner()
->window_service()
->GetWindowByClientId(transport_id);
}
ws::ClientSpecificId GetFirstWindowTreeClientId() {
return Shell::Get()
->window_service_owner()
->window_service()
->GetFirstWindowTreeClientId();
}
} // namespace window_lookup
} // namespace ash
// Copyright 2018 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.
#ifndef ASH_WS_WINDOW_LOOKUP_H_
#define ASH_WS_WINDOW_LOOKUP_H_
#include "ash/ash_export.h"
#include "services/ws/common/types.h"
namespace aura {
class Window;
}
// TODO: this file is only necessary for single-process mash and should be
// removed.
namespace ash {
namespace window_lookup {
// Returns the aura::Window by transport id.
ASH_EXPORT aura::Window* GetWindowByClientId(ws::Id transport_id);
// Returns the id of the first WindowTreeClient. That is, the id assigned to
// the first client that connects to the WindowService.
ASH_EXPORT ws::ClientSpecificId GetFirstWindowTreeClientId();
} // namespace window_lookup
} // namespace ash
#endif // ASH_WS_WINDOW_LOOKUP_H_
......@@ -10,6 +10,7 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/service_manager/public/cpp/bind_source_info.h"
#include "services/ws/common/switches.h"
#include "services/ws/common/util.h"
#include "services/ws/embedding.h"
#include "services/ws/event_injector.h"
#include "services/ws/event_queue.h"
......@@ -78,6 +79,10 @@ WindowService::~WindowService() {
DCHECK(window_trees_.empty());
}
ClientSpecificId WindowService::GetFirstWindowTreeClientId() const {
return decrement_client_ids_ ? kInitialClientIdDecrement : kInitialClientId;
}
ServerWindow* WindowService::GetServerWindowForWindowCreateIfNecessary(
aura::Window* window) {
ServerWindow* server_window = ServerWindow::GetMayBeNull(window);
......@@ -126,6 +131,13 @@ bool WindowService::IsTopLevelWindow(const aura::Window* window) {
return server_window && server_window->IsTopLevel();
}
aura::Window* WindowService::GetWindowByClientId(Id transport_id) {
const ClientSpecificId client_id = ClientIdFromTransportId(transport_id);
WindowTree* window_tree = GetTreeById(client_id);
return window_tree ? window_tree->GetWindowByTransportId(transport_id)
: nullptr;
}
WindowService::TreeAndWindowId
WindowService::FindTreeWithScheduleEmbedForExistingClient(
const base::UnguessableToken& embed_token) {
......@@ -272,6 +284,14 @@ void WindowService::OnBindInterface(
}
}
WindowTree* WindowService::GetTreeById(ClientSpecificId id) {
for (WindowTree* tree : window_trees_) {
if (tree->client_id() == id)
return tree;
}
return nullptr;
}
void WindowService::SetSurfaceActivationCallback(
base::OnceCallback<void(const std::string&)> callback) {
// Surface activation callbacks are expensive, and allowed only in tests.
......
......@@ -87,6 +87,9 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowService
aura::Env* env = nullptr);
~WindowService() override;
// Returns the id of the first WindowTreeClient.
ClientSpecificId GetFirstWindowTreeClientId() const;
// Gets the ServerWindow for |window|, creating if necessary.
ServerWindow* GetServerWindowForWindowCreateIfNecessary(aura::Window* window);
......@@ -110,6 +113,9 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowService
// Returns true if |window| hosts a remote client and is a toplevel window.
static bool IsTopLevelWindow(const aura::Window* window);
// Returns the window representing the specified id.
aura::Window* GetWindowByClientId(Id transport_id);
struct TreeAndWindowId {
ClientWindowId id;
WindowTree* tree = nullptr;
......@@ -190,6 +196,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowService
friend class WindowServerTestImpl;
friend class WindowServiceTestHelper;
WindowTree* GetTreeById(ClientSpecificId id);
// Sets a callback to be called whenever a surface is activated. This
// corresponds to a client submitting a new CompositorFrame for a Window. This
// should only be called in a test configuration.
......
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