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

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

Issue 2684723003: Remove LauncherItemController::Launch, cleanup. (Closed)
Patch Set: Use AppLauncherId Created 3 years, 10 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 "ash/public/cpp/shelf_application_menu_item.h" 9 #include "ash/public/cpp/shelf_application_menu_item.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // used URL. This will also work with applications like Google Drive. 85 // used URL. This will also work with applications like Google Drive.
86 const Extension* extension = 86 const Extension* extension =
87 GetExtensionForAppID(app_id, controller->profile()); 87 GetExtensionForAppID(app_id, controller->profile());
88 // Some unit tests have no real extension. 88 // Some unit tests have no real extension.
89 if (extension) { 89 if (extension) {
90 set_refocus_url(GURL( 90 set_refocus_url(GURL(
91 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); 91 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*"));
92 } 92 }
93 } 93 }
94 94
95 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() { 95 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {}
96 }
97
98 void AppShortcutLauncherItemController::Launch(ash::LaunchSource source,
99 int event_flags) {
100 // Launching an app replaces shortcut item controller to app controller. As
101 // result app_id_, launch_id_ are deleted during this call. Use local copies
102 // to prevent crash condition.
103 launcher_controller()->LaunchAppWithLaunchId(
104 std::string(app_id()), std::string(launch_id()), source, event_flags);
105 }
106 96
107 ash::ShelfItemDelegate::PerformedAction 97 ash::ShelfItemDelegate::PerformedAction
108 AppShortcutLauncherItemController::Activate(ash::LaunchSource source) { 98 AppShortcutLauncherItemController::Activate(ash::LaunchSource source) {
109 content::WebContents* content = GetLRUApplication(); 99 content::WebContents* content = GetLRUApplication();
110 if (!content) { 100 if (!content) {
111 if (IsV2App()) { 101 // Ideally we come here only once. After that ShellLauncherItemController
112 // Ideally we come here only once. After that ShellLauncherItemController 102 // will take over when the shell window gets opened. However there are apps
113 // will take over when the shell window gets opened. However there are 103 // which take a lot of time for pre-processing (like the files app) before
114 // apps which take a lot of time for pre-processing (like the files app) 104 // they open a window. Since there is currently no other way to detect if an
115 // before they open a window. Since there is currently no other way to 105 // app was started we suppress any further clicks within a special time out.
116 // detect if an app was started we suppress any further clicks within a 106 if (IsV2App() && !AllowNextLaunchAttempt())
117 // special time out. 107 return kNoAction;
118 if (!AllowNextLaunchAttempt()) 108
119 return kNoAction; 109 // Launching some items replaces this item controller instance, which
120 } 110 // destroys the app and launch id strings; making copies avoid crashes.
121 Launch(source, ui::EF_NONE); 111 launcher_controller()->LaunchApp(
112 ash::launcher::AppLauncherId(app_id(), launch_id()), source,
113 ui::EF_NONE);
122 return kNewWindowCreated; 114 return kNewWindowCreated;
123 } 115 }
124 return ActivateContent(content); 116 return ActivateContent(content);
125 } 117 }
126 118
127 ash::ShelfItemDelegate::PerformedAction 119 ash::ShelfItemDelegate::PerformedAction
128 AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) { 120 AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) {
129 // In case of a keyboard event, we were called by a hotkey. In that case we 121 // In case of a keyboard event, we were called by a hotkey. In that case we
130 // activate the next item in line if an item of our list is already active. 122 // activate the next item in line if an item of our list is already active.
131 if (event.type() == ui::ET_KEY_RELEASED && AdvanceToNextApp()) 123 if (event.type() == ui::ET_KEY_RELEASED && AdvanceToNextApp())
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 326
335 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 327 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
336 if (last_launch_attempt_.is_null() || 328 if (last_launch_attempt_.is_null() ||
337 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 329 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
338 kClickSuppressionInMS) < base::Time::Now()) { 330 kClickSuppressionInMS) < base::Time::Now()) {
339 last_launch_attempt_ = base::Time::Now(); 331 last_launch_attempt_ = base::Time::Now();
340 return true; 332 return true;
341 } 333 }
342 return false; 334 return false;
343 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698