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

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

Issue 2251973003: arc: Fix crash on Arc window close. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
5 5
6 #include <string> 6 #include <string>
7 7
8 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Unowned pointer, represents host Arc window. 239 // Unowned pointer, represents host Arc window.
240 views::Widget* widget_ = nullptr; 240 views::Widget* widget_ = nullptr;
241 241
242 arc::mojom::OrientationLock requested_orientation_lock_ = 242 arc::mojom::OrientationLock requested_orientation_lock_ =
243 arc::mojom::OrientationLock::NONE; 243 arc::mojom::OrientationLock::NONE;
244 bool has_requested_orientation_lock_ = false; 244 bool has_requested_orientation_lock_ = false;
245 245
246 DISALLOW_COPY_AND_ASSIGN(AppWindow); 246 DISALLOW_COPY_AND_ASSIGN(AppWindow);
247 }; 247 };
248 248
249 struct ArcAppWindowLauncherController::TaskInfo {
250 TaskInfo(const std::string& package_name, const std::string& activity_name)
251 : package_name(package_name), activity_name(activity_name) {}
252 ~TaskInfo() {}
253
254 std::string package_name;
255 std::string activity_name;
256 };
257
249 ArcAppWindowLauncherController::ArcAppWindowLauncherController( 258 ArcAppWindowLauncherController::ArcAppWindowLauncherController(
250 ChromeLauncherController* owner, 259 ChromeLauncherController* owner,
251 ash::ShelfDelegate* shelf_delegate) 260 ash::ShelfDelegate* shelf_delegate)
252 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { 261 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) {
253 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { 262 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) {
254 observed_profile_ = owner->GetProfile(); 263 observed_profile_ = owner->GetProfile();
255 StartObserving(observed_profile_); 264 StartObserving(observed_profile_);
256 } 265 }
257 } 266 }
258 267
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 return; 313 return;
305 observed_windows_.push_back(window); 314 observed_windows_.push_back(window);
306 window->AddObserver(this); 315 window->AddObserver(this);
307 } 316 }
308 317
309 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( 318 void ArcAppWindowLauncherController::OnWindowVisibilityChanging(
310 aura::Window* window, 319 aura::Window* window,
311 bool visible) { 320 bool visible) {
312 // The application id property should be set at this time. 321 // The application id property should be set at this time.
313 if (visible) 322 if (visible)
314 CheckForAppWindowWidget(window); 323 MayAttachContollerToWindow(window);
315 } 324 }
316 325
317 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { 326 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
318 auto it = 327 auto it =
319 std::find(observed_windows_.begin(), observed_windows_.end(), window); 328 std::find(observed_windows_.begin(), observed_windows_.end(), window);
320 DCHECK(it != observed_windows_.end()); 329 DCHECK(it != observed_windows_.end());
321 observed_windows_.erase(it); 330 observed_windows_.erase(it);
322 window->RemoveObserver(this); 331 window->RemoveObserver(this);
323 332
324 for (auto& it : task_id_to_app_window_) { 333 for (auto& it : task_id_to_app_window_) {
325 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) 334 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window))
326 it.second->set_widget(nullptr); 335 it.second->set_widget(nullptr);
327 } 336 }
328 } 337 }
329 338
330 ArcAppWindowLauncherController::AppWindow* 339 ArcAppWindowLauncherController::AppWindow*
331 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { 340 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
332 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); 341 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id);
333 if (it == task_id_to_app_window_.end()) 342 if (it == task_id_to_app_window_.end())
334 return nullptr; 343 return nullptr;
335 return it->second.get(); 344 return it->second.get();
336 } 345 }
337 346
338 void ArcAppWindowLauncherController::CheckForAppWindowWidget( 347 void ArcAppWindowLauncherController::MayAttachContollerToWindow(
339 aura::Window* window) { 348 aura::Window* window) {
340 const std::string app_id = exo::ShellSurface::GetApplicationId(window); 349 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window);
341 if (app_id.empty()) 350 if (window_app_id.empty())
342 return; 351 return;
343 352
344 int task_id = -1; 353 int task_id = -1;
345 if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) 354 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
346 return; 355 return;
347 356
348 if (task_id) { 357 if (!task_id)
349 // We need to add the observer after exo started observing shell 358 return;
350 // because we want to update the orientation after exo send
351 // the layout switch information.
352 if (!observing_shell_) {
353 observing_shell_ = true;
354 ash::WmShell::Get()->AddShellObserver(this);
355 }
356 359
357 AppWindow* app_window = GetAppWindowForTask(task_id); 360 // We need to add the observer after exo started observing shell
358 if (app_window) { 361 // because we want to update the orientation after exo send
359 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); 362 // the layout switch information.
360 ash::SetShelfIDForWindow(app_window->shelf_id(), window); 363 if (!observing_shell_) {
361 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( 364 observing_shell_ = true;
362 window, 365 ash::WmShell::Get()->AddShellObserver(this);
363 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
364 if (ash::Shell::GetInstance()
365 ->maximize_mode_controller()
366 ->IsMaximizeModeWindowManagerEnabled()) {
367 SetOrientationLockForAppWindow(app_window);
368 }
369 }
370 } 366 }
367
368 // Check if we have controller for this task.
369 if (GetAppWindowForTask(task_id))
370 return;
371
372 // Create controller if we have task info.
373 TaskIdToTaskInfoMap::iterator it = task_id_to_task_info_.find(task_id);
374 if (it == task_id_to_task_info_.end())
375 return;
376
377 const TaskInfo& task_info = *it->second;
378 const std::string app_id =
379 GetShelfAppIdFromArcAppId(ArcAppListPrefs::GetAppId(
380 task_info.package_name, task_info.activity_name));
381
382 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this));
383 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window));
384 RegisterApp(app_window.get());
385 DCHECK(app_window->controller());
386 ash::SetShelfIDForWindow(app_window->shelf_id(), window);
387 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
388 window,
389 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
390 if (ash::WmShell::Get()
391 ->maximize_mode_controller()
392 ->IsMaximizeModeWindowManagerEnabled()) {
393 SetOrientationLockForAppWindow(app_window.get());
394 }
395 task_id_to_app_window_[task_id] = std::move(app_window);
396
397 // TaskInfo is no longer needed. Discard it.
398 task_id_to_task_info_.erase(task_id);
371 } 399 }
372 400
373 void ArcAppWindowLauncherController::OnAppReadyChanged( 401 void ArcAppWindowLauncherController::OnAppReadyChanged(
374 const std::string& app_id, 402 const std::string& app_id,
375 bool ready) { 403 bool ready) {
376 if (!ready) 404 if (!ready)
377 OnAppRemoved(app_id); 405 OnAppRemoved(app_id);
378 } 406 }
379 407
380 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { 408 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) {
(...skipping 15 matching lines...) Expand all
396 OnTaskDestroyed(task_id); 424 OnTaskDestroyed(task_id);
397 425
398 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); 426 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end());
399 } 427 }
400 428
401 void ArcAppWindowLauncherController::OnTaskCreated( 429 void ArcAppWindowLauncherController::OnTaskCreated(
402 int task_id, 430 int task_id,
403 const std::string& package_name, 431 const std::string& package_name,
404 const std::string& activity_name) { 432 const std::string& activity_name) {
405 DCHECK(!GetAppWindowForTask(task_id)); 433 DCHECK(!GetAppWindowForTask(task_id));
434 std::unique_ptr<TaskInfo> task_info(
435 new TaskInfo(package_name, activity_name));
436 task_id_to_task_info_[task_id] = std::move(task_info);
406 437
407 const std::string app_id = GetShelfAppIdFromArcAppId( 438 for (auto* window : observed_windows_)
408 ArcAppListPrefs::GetAppId(package_name, activity_name)); 439 MayAttachContollerToWindow(window);
409
410 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this));
411 RegisterApp(app_window.get());
412
413 task_id_to_app_window_[task_id] = std::move(app_window);
414
415 for (auto window : observed_windows_)
416 CheckForAppWindowWidget(window);
417 } 440 }
418 441
419 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { 442 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
443 task_id_to_task_info_.erase(task_id);
444
420 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); 445 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id);
421 if (it == task_id_to_app_window_.end()) 446 if (it == task_id_to_app_window_.end())
422 return; 447 return;
423 448
424 AppWindow* app_window = it->second.get(); 449 AppWindow* app_window = it->second.get();
425 UnregisterApp(app_window); 450 UnregisterApp(app_window);
426 451
427 task_id_to_app_window_.erase(it); 452 task_id_to_app_window_.erase(it);
428 } 453 }
429 454
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 625
601 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 626 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
602 // Resolve the orientation when it first resolved. 627 // Resolve the orientation when it first resolved.
603 orientation_lock = GetCurrentOrientation(); 628 orientation_lock = GetCurrentOrientation();
604 app_window->set_requested_orientation_lock(orientation_lock); 629 app_window->set_requested_orientation_lock(orientation_lock);
605 } 630 }
606 631
607 shell->screen_orientation_controller()->LockOrientationForWindow( 632 shell->screen_orientation_controller()->LockOrientationForWindow(
608 window, BlinkOrientationLockFromMojom(orientation_lock)); 633 window, BlinkOrientationLockFromMojom(orientation_lock));
609 } 634 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698