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

Side by Side Diff: chrome/browser/ui/app_list/app_list_service_mac.mm

Issue 492163002: Fix Profile* lifetime issues in Chrome's AppListViewDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update unit test, cl format Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #import "chrome/browser/ui/app_list/app_list_service_mac.h" 5 #import "chrome/browser/ui/app_list/app_list_service_mac.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 385
386 void AppListServiceMac::CreateForProfile(Profile* requested_profile) { 386 void AppListServiceMac::CreateForProfile(Profile* requested_profile) {
387 if (profile_ == requested_profile) 387 if (profile_ == requested_profile)
388 return; 388 return;
389 389
390 profile_ = requested_profile; 390 profile_ = requested_profile;
391 391
392 if (!window_controller_) 392 if (!window_controller_)
393 window_controller_.reset([[AppListWindowController alloc] init]); 393 window_controller_.reset([[AppListWindowController alloc] init]);
394 394
395 scoped_ptr<app_list::AppListViewDelegate> delegate( 395 scoped_ptr<AppListViewDelegate> delegate(
396 new AppListViewDelegate(profile_, GetControllerDelegate())); 396 new AppListViewDelegate(GetControllerDelegate()));
397 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; 397 delegate->SetProfile(profile_);
398 [[window_controller_ appListViewController]
399 setDelegate:delegate.PassAs<app_list::AppListViewDelegate>()];
Matt Giuca 2014/08/25 04:48:46 Can you explain this line? (To me: not necessarily
tapted 2014/08/25 06:17:00 Yeah - we really should rename ::AppListViewDelega
Matt Giuca 2014/08/26 01:29:45 But you reverted the use of PassAs now?
tapted 2014/08/26 02:43:57 Yep - since the constructor is calling SetProfile,
398 } 400 }
399 401
400 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { 402 void AppListServiceMac::ShowForProfile(Profile* requested_profile) {
401 InvalidatePendingProfileLoads(); 403 InvalidatePendingProfileLoads();
402 404
403 if (requested_profile == profile_) { 405 if (requested_profile == profile_) {
404 ShowWindowNearDock(); 406 ShowWindowNearDock();
405 return; 407 return;
406 } 408 }
407 409
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 AppListServiceImpl::EnableAppList(initial_profile, enable_source); 447 AppListServiceImpl::EnableAppList(initial_profile, enable_source);
446 AppController* controller = [NSApp delegate]; 448 AppController* controller = [NSApp delegate];
447 [controller initAppShimMenuController]; 449 [controller initAppShimMenuController];
448 } 450 }
449 451
450 void AppListServiceMac::CreateShortcut() { 452 void AppListServiceMac::CreateShortcut() {
451 CreateAppListShim(GetProfilePath( 453 CreateAppListShim(GetProfilePath(
452 g_browser_process->profile_manager()->user_data_dir())); 454 g_browser_process->profile_manager()->user_data_dir()));
453 } 455 }
454 456
457 void AppListServiceMac::DestroyAppList() {
458 // Due to reference counting, Mac can't guarantee that the widget is deleted,
459 // but mac supports a visible app list with a NULL profile, so there's also no
460 // need to tear it down completely.
461 DismissAppList();
462 [[window_controller_ appListViewController]
463 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()];
464
465 profile_ = NULL;
466 }
467
455 NSWindow* AppListServiceMac::GetAppListWindow() { 468 NSWindow* AppListServiceMac::GetAppListWindow() {
456 return [window_controller_ window]; 469 return [window_controller_ window];
457 } 470 }
458 471
459 AppListControllerDelegate* AppListServiceMac::GetControllerDelegate() { 472 AppListControllerDelegate* AppListServiceMac::GetControllerDelegate() {
460 return controller_delegate_.get(); 473 return controller_delegate_.get();
461 } 474 }
462 475
463 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host, 476 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host,
464 apps::AppShimLaunchType launch_type, 477 apps::AppShimLaunchType launch_type,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 606
594 - (void)animationDidEnd:(NSAnimation*)animation { 607 - (void)animationDidEnd:(NSAnimation*)animation {
595 content::BrowserThread::PostTask( 608 content::BrowserThread::PostTask(
596 content::BrowserThread::UI, 609 content::BrowserThread::UI,
597 FROM_HERE, 610 FROM_HERE,
598 base::Bind(&AppListServiceMac::WindowAnimationDidEnd, 611 base::Bind(&AppListServiceMac::WindowAnimationDidEnd,
599 base::Unretained(AppListServiceMac::GetInstance()))); 612 base::Unretained(AppListServiceMac::GetInstance())));
600 } 613 }
601 614
602 @end 615 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698