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

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

Issue 22730003: Warm-up the App List when enabled from the webstore and not shown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 #include <ApplicationServices/ApplicationServices.h> 5 #include <ApplicationServices/ApplicationServices.h>
6 #import <Cocoa/Cocoa.h> 6 #import <Cocoa/Cocoa.h>
7 7
8 #include "apps/app_launcher.h" 8 #include "apps/app_launcher.h"
9 #include "apps/app_shim/app_shim_handler_mac.h" 9 #include "apps/app_shim/app_shim_handler_mac.h"
10 #include "apps/app_shim/app_shim_mac.h" 10 #include "apps/app_shim/app_shim_mac.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 class AppListServiceMac : public AppListServiceImpl, 52 class AppListServiceMac : public AppListServiceImpl,
53 public apps::AppShimHandler { 53 public apps::AppShimHandler {
54 public: 54 public:
55 virtual ~AppListServiceMac() {} 55 virtual ~AppListServiceMac() {}
56 56
57 static AppListServiceMac* GetInstance() { 57 static AppListServiceMac* GetInstance() {
58 return Singleton<AppListServiceMac, 58 return Singleton<AppListServiceMac,
59 LeakySingletonTraits<AppListServiceMac> >::get(); 59 LeakySingletonTraits<AppListServiceMac> >::get();
60 } 60 }
61 61
62 void CreateAppList(Profile* profile);
63 void ShowWindowNearDock(); 62 void ShowWindowNearDock();
64 63
65 // AppListService overrides: 64 // AppListService overrides:
66 virtual void Init(Profile* initial_profile) OVERRIDE; 65 virtual void Init(Profile* initial_profile) OVERRIDE;
66 virtual void CreateForProfile(Profile* requested_profile) OVERRIDE;
67 virtual void ShowForProfile(Profile* requested_profile) OVERRIDE; 67 virtual void ShowForProfile(Profile* requested_profile) OVERRIDE;
68 virtual void DismissAppList() OVERRIDE; 68 virtual void DismissAppList() OVERRIDE;
69 virtual bool IsAppListVisible() const OVERRIDE; 69 virtual bool IsAppListVisible() const OVERRIDE;
70 virtual gfx::NativeWindow GetAppListWindow() OVERRIDE; 70 virtual gfx::NativeWindow GetAppListWindow() OVERRIDE;
71 71
72 // AppListServiceImpl overrides: 72 // AppListServiceImpl overrides:
73 virtual void CreateShortcut() OVERRIDE; 73 virtual void CreateShortcut() OVERRIDE;
74 virtual void OnSigninStatusChanged() OVERRIDE; 74 virtual void OnSigninStatusChanged() OVERRIDE;
75 75
76 // AppShimHandler overrides: 76 // AppShimHandler overrides:
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 Profile* profile, const extensions::Extension* extension, int event_flags) { 261 Profile* profile, const extensions::Extension* extension, int event_flags) {
262 LaunchApp(profile, extension, event_flags); 262 LaunchApp(profile, extension, event_flags);
263 } 263 }
264 264
265 void AppListControllerDelegateCocoa::LaunchApp( 265 void AppListControllerDelegateCocoa::LaunchApp(
266 Profile* profile, const extensions::Extension* extension, int event_flags) { 266 Profile* profile, const extensions::Extension* extension, int event_flags) {
267 chrome::OpenApplication(chrome::AppLaunchParams( 267 chrome::OpenApplication(chrome::AppLaunchParams(
268 profile, extension, NEW_FOREGROUND_TAB)); 268 profile, extension, NEW_FOREGROUND_TAB));
269 } 269 }
270 270
271 void AppListServiceMac::CreateAppList(Profile* requested_profile) {
272 if (profile() == requested_profile)
273 return;
274
275 // The Objective C objects might be released at some unknown point in the
276 // future, so explicitly clear references to C++ objects.
277 [[window_controller_ appListViewController]
278 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()];
279
280 SetProfile(requested_profile);
281 scoped_ptr<app_list::AppListViewDelegate> delegate(
282 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile()));
283 window_controller_.reset([[AppListWindowController alloc] init]);
284 [[window_controller_ appListViewController] setDelegate:delegate.Pass()];
285 }
286
287 void AppListServiceMac::Init(Profile* initial_profile) { 271 void AppListServiceMac::Init(Profile* initial_profile) {
288 // On Mac, Init() is called multiple times for a process: any time there is no 272 // On Mac, Init() is called multiple times for a process: any time there is no
289 // browser window open and a new window is opened, and during process startup 273 // browser window open and a new window is opened, and during process startup
290 // to handle the silent launch case (e.g. for app shims). In the startup case, 274 // to handle the silent launch case (e.g. for app shims). In the startup case,
291 // a profile has not yet been determined so |initial_profile| will be NULL. 275 // a profile has not yet been determined so |initial_profile| will be NULL.
292 static bool init_called_with_profile = false; 276 static bool init_called_with_profile = false;
293 if (initial_profile && !init_called_with_profile) { 277 if (initial_profile && !init_called_with_profile) {
294 init_called_with_profile = true; 278 init_called_with_profile = true;
295 HandleCommandLineFlags(initial_profile); 279 HandleCommandLineFlags(initial_profile);
296 if (!apps::IsAppLauncherEnabled()) { 280 if (!apps::IsAppLauncherEnabled()) {
297 // Not yet enabled via the Web Store. Check for the chrome://flag. 281 // Not yet enabled via the Web Store. Check for the chrome://flag.
298 content::BrowserThread::PostTask( 282 content::BrowserThread::PostTask(
299 content::BrowserThread::FILE, FROM_HERE, 283 content::BrowserThread::FILE, FROM_HERE,
300 base::Bind(&CheckAppListShimOnFileThread, 284 base::Bind(&CheckAppListShimOnFileThread,
301 initial_profile->GetPath())); 285 initial_profile->GetPath()));
302 } 286 }
303 } 287 }
304 288
305 static bool init_called = false; 289 static bool init_called = false;
306 if (init_called) 290 if (init_called)
307 return; 291 return;
308 292
309 init_called = true; 293 init_called = true;
310 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, 294 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId,
311 AppListServiceMac::GetInstance()); 295 AppListServiceMac::GetInstance());
312 } 296 }
313 297
298 void AppListServiceMac::CreateForProfile(Profile* requested_profile) {
299 if (profile() == requested_profile)
300 return;
301
302 // The Objective C objects might be released at some unknown point in the
303 // future, so explicitly clear references to C++ objects.
304 [[window_controller_ appListViewController]
305 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()];
306
307 SetProfile(requested_profile);
308 scoped_ptr<app_list::AppListViewDelegate> delegate(
309 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile()));
310 window_controller_.reset([[AppListWindowController alloc] init]);
311 [[window_controller_ appListViewController] setDelegate:delegate.Pass()];
312 }
313
314 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { 314 void AppListServiceMac::ShowForProfile(Profile* requested_profile) {
315 InvalidatePendingProfileLoads(); 315 InvalidatePendingProfileLoads();
316 316
317 if (IsAppListVisible() && (requested_profile == profile())) { 317 if (IsAppListVisible() && (requested_profile == profile())) {
318 ShowWindowNearDock(); 318 ShowWindowNearDock();
319 return; 319 return;
320 } 320 }
321 321
322 SetProfilePath(requested_profile->GetPath()); 322 SetProfilePath(requested_profile->GetPath());
323 323
324 DismissAppList(); 324 DismissAppList();
325 CreateAppList(requested_profile); 325 CreateForProfile(requested_profile);
326 ShowWindowNearDock(); 326 ShowWindowNearDock();
327 } 327 }
328 328
329 void AppListServiceMac::DismissAppList() { 329 void AppListServiceMac::DismissAppList() {
330 if (!IsAppListVisible()) 330 if (!IsAppListVisible())
331 return; 331 return;
332 332
333 // If the app list is currently the main window, it will activate the next 333 // If the app list is currently the main window, it will activate the next
334 // Chrome window when dismissed. But if a different application was active 334 // Chrome window when dismissed. But if a different application was active
335 // when the app list was shown, activate that instead. 335 // when the app list was shown, activate that instead.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 508
509 // static 509 // static
510 AppListService* AppListService::Get() { 510 AppListService* AppListService::Get() {
511 return AppListServiceMac::GetInstance(); 511 return AppListServiceMac::GetInstance();
512 } 512 }
513 513
514 // static 514 // static
515 void AppListService::InitAll(Profile* initial_profile) { 515 void AppListService::InitAll(Profile* initial_profile) {
516 Get()->Init(initial_profile); 516 Get()->Init(initial_profile);
517 } 517 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/app_list_service_disabled.cc ('k') | chrome/browser/ui/ash/app_list/app_list_service_ash.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698