0
Files
src/ash/autotest_private_api_utils.cc
Gabriel Charette 9f60dd1181 Reland "IWYU for bind/callback_helpers.h and ptr_util.h"
This reverts commit 7a13e2645a.

Reason for revert: same as original % tools/clang

Original change's description:
> Revert "IWYU for bind/callback_helpers.h and ptr_util.h"
> 
> This reverts commit b8ffaf4cfc.
> 
> Reason for revert:
> This broke the build of the blink_gc_plugin, which does not use base/
> (see bug). Please don't commit to tools/clang/ without review.
> 
> Original change's description:
> > IWYU for bind/callback_helpers.h and ptr_util.h
> > 
> > These missing includes are preventing removal of unused headers from
> > task_runner_util.h and consequently migration from task_runner_util.h to
> > task_runner.h's new PostTaskAndReplyWithResult member method.
> > 
> > The following script was run on every file in the codebase, prioritizing
> > .h over matching .cc to best enforce the rule of not include a header
> > included by your .h :
> > 
> > def Fix(file_path):
> >   content = refactor_lib.ReadFile(file_path)
> > 
> >   # Assume fwd-decls are correct in first pass.
> >   fwd_decls_match = re.compile(r'\n *[^/\n][^/\n][^/\n]*class (NullCallback|DoNothing|ScopedClosureRunner);', re.DOTALL).findall(content)
> >   if fwd_decls_match:
> >     print 'fwd_decls_match in %s' % (file_path)
> >     return False
> > 
> >   bind_helpers_match = re.compile(
> >       # Doesn't begin with a comment.
> >       r'\n *[^/\n][^/\n]'
> >       # Anything else after a non-comment start (and don't allow this to capture a comment start either)
> >       r'[^/\n]*'
> >       # Anything before but an open angle-bracket to avoid cases like unique_ptr<Foo> where you don't need the full definition of Foo.
> >       r'[^<]'
> >       # Only match with base:: prefix; more precise, can manually fix missing includes in //base proper in a follow-up pass if needed.
> >       r'base::(NullCallback|DoNothing|DeletePointer)\b[^*]', re.DOTALL).findall(content)
> > 
> >   callback_helpers_match = re.compile(r'\n *[^/\n][^/\n][^/\n]*[^<]base::(IsBaseCallback|EnableIfIsBaseCallback|AdaptCallbackForRepeating|ScopedClosureRunner)\b[^*]', re.DOTALL).findall(content)
> > 
> >   ptr_util_match = re.compile(r'\n *[^/\n][^/\n][^/\n]*[^<]base::WrapUnique\b[^*]', re.DOTALL).findall(content)
> > 
> >   if not bind_helpers_match and not callback_helpers_match and not ptr_util_match:
> >     return False
> > 
> >   updated_content = content
> >   if bind_helpers_match:
> >     updated_content = refactor_lib.AddInclude(file_path, updated_content, "base/bind_helpers.h")
> >   if callback_helpers_match:
> >     updated_content = refactor_lib.AddInclude(file_path, updated_content, "base/callback_helpers.h")
> >   if ptr_util_match:
> >     updated_content = refactor_lib.AddInclude(file_path, updated_content, "base/memory/ptr_util.h")
> > 
> >   if updated_content == content:
> >     return False
> > 
> >   # Write updated file
> >   refactor_lib.WriteFile(file_path, updated_content)
> > 
> >   return True
> > 
> > TBR=danakj@chromium.org
> > (mechanical change for //base API)
> > 
> > Bug: 1026641
> > Change-Id: Ic88585c62dd2f74d34c59c708faeddb231aee47f
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087971
> > Reviewed-by: Gabriel Charette <gab@chromium.org>
> > Reviewed-by: danakj <danakj@chromium.org>
> > Commit-Queue: Gabriel Charette <gab@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#747685}
> 
> TBR=danakj@chromium.org,gab@chromium.org
> 
> Change-Id: I59d6cd69bd898e9f6d10922c67d8c24ba582bf7f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 1026641, 1059359
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2091356
> Reviewed-by: Hans Wennborg <hans@chromium.org>
> Commit-Queue: Hans Wennborg <hans@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#747804}

TBR=danakj@chromium.org,gab@chromium.org,hans@chromium.org

Change-Id: I721391eba68ea55830dca4f1ac34ff633f714f72
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1026641, 1059359
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090509
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747844}
2020-03-06 20:48:04 +00:00

136 lines
4.9 KiB
C++

// Copyright 2019 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/public/cpp/autotest_private_api_utils.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/frame/non_client_frame_view_ash.h"
#include "ash/home_screen/home_screen_controller.h"
#include "ash/shell.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/tablet_mode/scoped_skip_user_session_blocked_check.h"
#include "base/bind_helpers.h"
namespace ash {
namespace {
class HomeLauncherStateWaiter {
public:
HomeLauncherStateWaiter(bool target_shown, base::OnceClosure closure)
: target_shown_(target_shown), closure_(std::move(closure)) {
Shell::Get()
->app_list_controller()
->SetHomeLauncherAnimationCallbackForTesting(base::BindRepeating(
&HomeLauncherStateWaiter::OnHomeLauncherAnimationCompleted,
base::Unretained(this)));
}
~HomeLauncherStateWaiter() {
Shell::Get()
->app_list_controller()
->SetHomeLauncherAnimationCallbackForTesting(base::NullCallback());
}
private:
// Passed to AppListControllerImpl as a callback to run when home launcher
// transition animation is complete.
void OnHomeLauncherAnimationCompleted(bool shown) {
if (shown == target_shown_) {
std::move(closure_).Run();
delete this;
}
}
bool target_shown_;
base::OnceClosure closure_;
DISALLOW_COPY_AND_ASSIGN(HomeLauncherStateWaiter);
};
// A waiter that waits until the animation ended with the target state, and
// execute the callback. This self destruction upon completion.
class LauncherStateWaiter {
public:
LauncherStateWaiter(ash::AppListViewState state, base::OnceClosure closure)
: target_state_(state), closure_(std::move(closure)) {
Shell::Get()
->app_list_controller()
->SetStateTransitionAnimationCallbackForTesting(base::BindRepeating(
&LauncherStateWaiter::OnStateChanged, base::Unretained(this)));
}
~LauncherStateWaiter() {
Shell::Get()
->app_list_controller()
->SetStateTransitionAnimationCallbackForTesting(base::NullCallback());
}
void OnStateChanged(ash::AppListViewState state) {
if (target_state_ == state) {
std::move(closure_).Run();
delete this;
}
}
private:
ash::AppListViewState target_state_;
base::OnceClosure closure_;
DISALLOW_COPY_AND_ASSIGN(LauncherStateWaiter);
};
} // namespace
std::vector<aura::Window*> GetAppWindowList() {
ScopedSkipUserSessionBlockedCheck skip_session_blocked;
return Shell::Get()->mru_window_tracker()->BuildAppWindowList(kAllDesks);
}
bool WaitForLauncherState(AppListViewState target_state,
base::OnceClosure closure) {
// In the tablet mode, some of the app-list state switching is handled
// differently. For open and close, HomeLauncherGestureHandler handles the
// gestures and animation. HomeLauncherStateWaiter can wait for such
// animation. For switching between the search and apps-grid,
// LauncherStateWaiter can wait for the animation.
bool should_wait_for_home_launcher = false;
if (Shell::Get()->tablet_mode_controller()->InTabletMode() &&
target_state != AppListViewState::kFullscreenSearch) {
// App-list can't enter into kPeeking or kHalf state. Thus |target_state|
// should be either kClosed or kFullscreenAllApps.
DCHECK(target_state == AppListViewState::kClosed ||
target_state == AppListViewState::kFullscreenAllApps);
const AppListViewState current_state =
Shell::Get()->app_list_controller()->GetAppListViewState();
should_wait_for_home_launcher =
(target_state == AppListViewState::kClosed) ||
(current_state != AppListViewState::kFullscreenSearch);
}
if (should_wait_for_home_launcher) {
// We don't check if the home launcher is animating to the target visibility
// because a) home launcher behavior is deterministic, b) correctly
// deteching if the home launcher is animating to visibile/invisible require
// some refactoring.
bool target_visible = target_state != AppListViewState::kClosed;
new HomeLauncherStateWaiter(target_visible, std::move(closure));
} else {
// Don't wait if the launcher is already in the target state and not
// animating.
auto* app_list_view =
Shell::Get()->app_list_controller()->presenter()->GetView();
bool animating =
app_list_view &&
app_list_view->GetWidget()->GetLayer()->GetAnimator()->is_animating();
bool at_target_state =
(!app_list_view && target_state == AppListViewState::kClosed) ||
(app_list_view && app_list_view->app_list_state() == target_state);
if (at_target_state && !animating) {
std::move(closure).Run();
return true;
}
new LauncherStateWaiter(target_state, std::move(closure));
}
return false;
}
} // namespace ash