Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc

Issue 2867673004: Use OnceCallback on Mojo interfaces in //ash (Closed)
Patch Set: count -> container_count Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h " 5 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility>
10
9 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
10 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/chromeos/arc/arc_support_host.h" 13 #include "chrome/browser/chromeos/arc/arc_support_host.h"
12 #include "chrome/browser/extensions/launch_util.h" 14 #include "chrome/browser/extensions/launch_util.h"
13 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 15 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
14 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h" 16 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
17 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
18 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" 20 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); 88 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*"));
87 } 89 }
88 } 90 }
89 91
90 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {} 92 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {}
91 93
92 void AppShortcutLauncherItemController::ItemSelected( 94 void AppShortcutLauncherItemController::ItemSelected(
93 std::unique_ptr<ui::Event> event, 95 std::unique_ptr<ui::Event> event,
94 int64_t display_id, 96 int64_t display_id,
95 ash::ShelfLaunchSource source, 97 ash::ShelfLaunchSource source,
96 const ItemSelectedCallback& callback) { 98 ItemSelectedCallback callback) {
97 // In case of a keyboard event, we were called by a hotkey. In that case we 99 // In case of a keyboard event, we were called by a hotkey. In that case we
98 // activate the next item in line if an item of our list is already active. 100 // activate the next item in line if an item of our list is already active.
99 if (event && event->type() == ui::ET_KEY_RELEASED && AdvanceToNextApp()) { 101 if (event && event->type() == ui::ET_KEY_RELEASED && AdvanceToNextApp()) {
100 callback.Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); 102 std::move(callback).Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt);
101 return; 103 return;
102 } 104 }
103 105
104 content::WebContents* content = GetLRUApplication(); 106 content::WebContents* content = GetLRUApplication();
105 if (!content) { 107 if (!content) {
106 // Ideally we come here only once. After that ShellLauncherItemController 108 // Ideally we come here only once. After that ShellLauncherItemController
107 // will take over when the shell window gets opened. However there are apps 109 // will take over when the shell window gets opened. However there are apps
108 // which take a lot of time for pre-processing (like the files app) before 110 // which take a lot of time for pre-processing (like the files app) before
109 // they open a window. Since there is currently no other way to detect if an 111 // they open a window. Since there is currently no other way to detect if an
110 // app was started we suppress any further clicks within a special time out. 112 // app was started we suppress any further clicks within a special time out.
111 if (IsV2App() && !AllowNextLaunchAttempt()) { 113 if (IsV2App() && !AllowNextLaunchAttempt()) {
112 callback.Run(ash::SHELF_ACTION_NONE, 114 std::move(callback).Run(
113 GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); 115 ash::SHELF_ACTION_NONE,
116 GetAppMenuItems(event ? event->flags() : ui::EF_NONE));
114 return; 117 return;
115 } 118 }
116 119
117 // Launching some items replaces this item controller instance, which 120 // Launching some items replaces this item controller instance, which
118 // destroys its ShelfID string pair; making copies avoid crashes. 121 // destroys its ShelfID string pair; making copies avoid crashes.
119 ChromeLauncherController::instance()->LaunchApp(ash::ShelfID(shelf_id()), 122 ChromeLauncherController::instance()->LaunchApp(ash::ShelfID(shelf_id()),
120 source, ui::EF_NONE); 123 source, ui::EF_NONE);
121 callback.Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, base::nullopt); 124 std::move(callback).Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED,
125 base::nullopt);
122 return; 126 return;
123 } 127 }
124 128
125 const ash::ShelfAction action = ActivateContent(content); 129 const ash::ShelfAction action = ActivateContent(content);
126 callback.Run(action, GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); 130 std::move(callback).Run(
131 action, GetAppMenuItems(event ? event->flags() : ui::EF_NONE));
127 } 132 }
128 133
129 ash::MenuItemList AppShortcutLauncherItemController::GetAppMenuItems( 134 ash::MenuItemList AppShortcutLauncherItemController::GetAppMenuItems(
130 int event_flags) { 135 int event_flags) {
131 ash::MenuItemList items; 136 ash::MenuItemList items;
132 app_menu_items_ = GetRunningApplications(); 137 app_menu_items_ = GetRunningApplications();
133 ChromeLauncherController* controller = ChromeLauncherController::instance(); 138 ChromeLauncherController* controller = ChromeLauncherController::instance();
134 for (size_t i = 0; i < app_menu_items_.size(); i++) { 139 for (size_t i = 0; i < app_menu_items_.size(); i++) {
135 content::WebContents* tab = app_menu_items_[i]; 140 content::WebContents* tab = app_menu_items_[i];
136 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New()); 141 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New());
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 366
362 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 367 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
363 if (last_launch_attempt_.is_null() || 368 if (last_launch_attempt_.is_null() ||
364 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 369 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
365 kClickSuppressionInMS) < base::Time::Now()) { 370 kClickSuppressionInMS) < base::Time::Now()) {
366 last_launch_attempt_ = base::Time::Now(); 371 last_launch_attempt_ = base::Time::Now();
367 return true; 372 return true;
368 } 373 }
369 return false; 374 return false;
370 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698