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

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

Issue 2315903002: arc: Fix crash in multi-user env on task stop. (Closed)
Patch Set: rebase + comments Created 4 years, 3 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/shelf/shelf_delegate.h" 8 #include "ash/common/shelf/shelf_delegate.h"
9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
10 #include "ash/common/wm/window_state.h" 10 #include "ash/common/wm/window_state.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 // static 256 // static
257 std::string ArcAppWindowLauncherController::GetArcAppIdFromShelfAppId( 257 std::string ArcAppWindowLauncherController::GetArcAppIdFromShelfAppId(
258 const std::string& shelf_app_id) { 258 const std::string& shelf_app_id) {
259 return shelf_app_id == ArcSupportHost::kHostAppId ? arc::kPlayStoreAppId 259 return shelf_app_id == ArcSupportHost::kHostAppId ? arc::kPlayStoreAppId
260 : shelf_app_id; 260 : shelf_app_id;
261 } 261 }
262 262
263 void ArcAppWindowLauncherController::ActiveUserChanged( 263 void ArcAppWindowLauncherController::ActiveUserChanged(
264 const std::string& user_email) { 264 const std::string& user_email) {
265 for (auto& it : task_id_to_app_window_) { 265 const std::string& primary_user_email = user_manager::UserManager::Get()
266 AppWindow* app_window = it.second.get(); 266 ->GetPrimaryUser()
267 if (user_email == 267 ->GetAccountId()
268 user_manager::UserManager::Get() 268 .GetUserEmail();
269 ->GetPrimaryUser() 269 if (user_email == primary_user_email) {
270 ->GetAccountId() 270 // Restore existing Arc window and create controllers for them.
271 .GetUserEmail()) { 271 AttachControllerToWindowsIfNeeded();
272 RegisterApp(app_window); 272 // Update active status.
273 } else { 273 OnTaskSetActive(active_task_id_);
274 } else {
275 // Remove all Arc apps and destroy its controllers. There is no mapping
276 // task id to app window because it is not safe when controller is missing.
277 for (auto& it : task_id_to_app_window_) {
278 AppWindow* app_window = it.second.get();
274 UnregisterApp(app_window, true); 279 UnregisterApp(app_window, true);
275 } 280 }
281 task_id_to_app_window_.clear();
276 } 282 }
277 } 283 }
278 284
279 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( 285 void ArcAppWindowLauncherController::AdditionalUserAddedToSession(
280 Profile* profile) { 286 Profile* profile) {
281 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); 287 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile));
282 } 288 }
283 289
284 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { 290 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) {
285 // Arc windows has type WINDOW_TYPE_NORMAL. 291 // Arc windows has type WINDOW_TYPE_NORMAL.
286 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) 292 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL)
287 return; 293 return;
288 observed_windows_.push_back(window); 294 observed_windows_.push_back(window);
289 window->AddObserver(this); 295 window->AddObserver(this);
290 } 296 }
291 297
292 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( 298 void ArcAppWindowLauncherController::OnWindowVisibilityChanging(
293 aura::Window* window, 299 aura::Window* window,
294 bool visible) { 300 bool visible) {
295 // The application id property should be set at this time. 301 // The application id property should be set at this time.
296 if (visible) 302 if (visible)
297 MayAttachContollerToWindow(window); 303 AttachControllerToWindowIfNeeded(window);
298 } 304 }
299 305
300 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { 306 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
301 auto it = 307 auto it =
302 std::find(observed_windows_.begin(), observed_windows_.end(), window); 308 std::find(observed_windows_.begin(), observed_windows_.end(), window);
303 DCHECK(it != observed_windows_.end()); 309 DCHECK(it != observed_windows_.end());
304 observed_windows_.erase(it); 310 observed_windows_.erase(it);
305 window->RemoveObserver(this); 311 window->RemoveObserver(this);
306 312
307 auto it_app_window = 313 auto it_app_window =
(...skipping 11 matching lines...) Expand all
319 } 325 }
320 326
321 ArcAppWindowLauncherController::AppWindow* 327 ArcAppWindowLauncherController::AppWindow*
322 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { 328 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
323 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); 329 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id);
324 if (it == task_id_to_app_window_.end()) 330 if (it == task_id_to_app_window_.end())
325 return nullptr; 331 return nullptr;
326 return it->second.get(); 332 return it->second.get();
327 } 333 }
328 334
329 void ArcAppWindowLauncherController::MayAttachContollerToWindow( 335 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() {
336 for (auto* window : observed_windows_)
337 AttachControllerToWindowIfNeeded(window);
338 }
339
340 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
330 aura::Window* window) { 341 aura::Window* window) {
331 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); 342 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window);
332 if (window_app_id.empty()) 343 if (window_app_id.empty())
333 return; 344 return;
334 345
335 int task_id = -1; 346 int task_id = -1;
336 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) 347 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
337 return; 348 return;
338 349
339 if (!task_id) 350 if (!task_id)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 414 }
404 415
405 void ArcAppWindowLauncherController::OnTaskCreated( 416 void ArcAppWindowLauncherController::OnTaskCreated(
406 int task_id, 417 int task_id,
407 const std::string& package_name, 418 const std::string& package_name,
408 const std::string& activity_name) { 419 const std::string& activity_name) {
409 DCHECK(!GetAppWindowForTask(task_id)); 420 DCHECK(!GetAppWindowForTask(task_id));
410 task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId( 421 task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId(
411 ArcAppListPrefs::GetAppId(package_name, activity_name)); 422 ArcAppListPrefs::GetAppId(package_name, activity_name));
412 423
413 for (auto* window : observed_windows_) 424 AttachControllerToWindowsIfNeeded();
414 MayAttachContollerToWindow(window);
415 } 425 }
416 426
417 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { 427 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
418 auto it = task_id_to_app_window_.find(task_id); 428 auto it = task_id_to_app_window_.find(task_id);
419 if (it != task_id_to_app_window_.end()) { 429 if (it != task_id_to_app_window_.end()) {
420 AppWindow* app_window = it->second.get(); 430 AppWindow* app_window = it->second.get();
421 UnregisterApp(app_window, true); 431 UnregisterApp(app_window, true);
422 task_id_to_app_window_.erase(it); 432 task_id_to_app_window_.erase(it);
423 } 433 }
424 434
(...skipping 11 matching lines...) Expand all
436 if (!controller->window_count()) { 446 if (!controller->window_count()) {
437 owner()->CloseLauncherItem(controller->shelf_id()); 447 owner()->CloseLauncherItem(controller->shelf_id());
438 app_controller_map_.erase(it_controller); 448 app_controller_map_.erase(it_controller);
439 } 449 }
440 } 450 }
441 451
442 task_id_to_shelf_app_id_.erase(it_app_id); 452 task_id_to_shelf_app_id_.erase(it_app_id);
443 } 453 }
444 454
445 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { 455 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
446 if (observed_profile_ != owner()->GetProfile()) 456 if (observed_profile_ != owner()->GetProfile()) {
457 active_task_id_ = task_id;
447 return; 458 return;
459 }
448 460
449 TaskIdToAppWindow::iterator previous_active_app_it = 461 TaskIdToAppWindow::iterator previous_active_app_it =
450 task_id_to_app_window_.find(active_task_id_); 462 task_id_to_app_window_.find(active_task_id_);
451 if (previous_active_app_it != task_id_to_app_window_.end()) { 463 if (previous_active_app_it != task_id_to_app_window_.end()) {
452 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), 464 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(),
453 ash::STATUS_RUNNING); 465 ash::STATUS_RUNNING);
454 previous_active_app_it->second->SetFullscreenMode( 466 previous_active_app_it->second->SetFullscreenMode(
455 previous_active_app_it->second->widget() && 467 previous_active_app_it->second->widget() &&
456 previous_active_app_it->second->widget()->IsFullscreen() 468 previous_active_app_it->second->widget()->IsFullscreen()
457 ? FullScreenMode::ACTIVE 469 ? FullScreenMode::ACTIVE
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 controller->AddWindow(app_window); 588 controller->AddWindow(app_window);
577 controller->AddTaskId(app_window->task_id()); 589 controller->AddTaskId(app_window->task_id());
578 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 590 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
579 app_window->SetController(controller); 591 app_window->SetController(controller);
580 app_window->set_shelf_id(shelf_id); 592 app_window->set_shelf_id(shelf_id);
581 } 593 }
582 594
583 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, 595 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window,
584 bool close_controller) { 596 bool close_controller) {
585 const std::string app_id = app_window->app_id(); 597 const std::string app_id = app_window->app_id();
598
586 DCHECK(!app_id.empty()); 599 DCHECK(!app_id.empty());
587 AppControllerMap::iterator it = app_controller_map_.find(app_id); 600 AppControllerMap::iterator it = app_controller_map_.find(app_id);
588 DCHECK(it != app_controller_map_.end()); 601 CHECK(it != app_controller_map_.end());
589 602
590 ArcAppWindowLauncherItemController* controller = it->second; 603 ArcAppWindowLauncherItemController* controller = it->second;
591 controller->RemoveWindow(app_window); 604 controller->RemoveWindow(app_window);
592 if (close_controller && !controller->window_count()) { 605 if (close_controller && !controller->window_count()) {
593 ash::ShelfID shelf_id = app_window->shelf_id(); 606 ash::ShelfID shelf_id = app_window->shelf_id();
594 owner()->CloseLauncherItem(shelf_id); 607 owner()->CloseLauncherItem(shelf_id);
595 app_controller_map_.erase(it); 608 app_controller_map_.erase(it);
596 } 609 }
597 app_window->ResetController(); 610 app_window->ResetController();
598 } 611 }
(...skipping 19 matching lines...) Expand all
618 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 631 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
619 // Resolve the orientation when it first resolved. 632 // Resolve the orientation when it first resolved.
620 orientation_lock = GetCurrentOrientation(); 633 orientation_lock = GetCurrentOrientation();
621 app_window->set_requested_orientation_lock(orientation_lock); 634 app_window->set_requested_orientation_lock(orientation_lock);
622 } 635 }
623 636
624 ash::Shell* shell = ash::Shell::GetInstance(); 637 ash::Shell* shell = ash::Shell::GetInstance();
625 shell->screen_orientation_controller()->LockOrientationForWindow( 638 shell->screen_orientation_controller()->LockOrientationForWindow(
626 window, BlinkOrientationLockFromMojom(orientation_lock)); 639 window, BlinkOrientationLockFromMojom(orientation_lock));
627 } 640 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698