| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/extensions/app_launcher.h" | 5 #include "chrome/browser/extensions/app_launcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" |
| 10 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 11 | 14 |
| 12 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 13 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 16 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
| 14 #include "chrome/installer/util/browser_distribution.h" | 17 #include "chrome/installer/util/browser_distribution.h" |
| 15 #endif | 18 #endif |
| 16 | 19 |
| 17 namespace extensions { | 20 namespace extensions { |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 25 void UpdatePrefAndCallCallbackOnUI( |
| 26 bool result, |
| 27 const OnAppLauncherEnabledCompleted& completion_callback) { |
| 28 PrefService* prefs = g_browser_process->local_state(); |
| 29 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, result); |
| 30 completion_callback.Run(result); |
| 31 } |
| 32 |
| 22 void IsAppLauncherInstalledOnBlockingPool( | 33 void IsAppLauncherInstalledOnBlockingPool( |
| 23 const OnAppLauncherEnabledCompleted& completion_callback) { | 34 const OnAppLauncherEnabledCompleted& completion_callback) { |
| 24 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 35 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 25 bool result = chrome_launcher_support::IsAppLauncherPresent(); | 36 bool result = chrome_launcher_support::IsAppLauncherPresent(); |
| 26 content::BrowserThread::PostTask(content::BrowserThread::UI, | 37 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 27 FROM_HERE, | 38 base::Bind(UpdatePrefAndCallCallbackOnUI, result, completion_callback)); |
| 28 base::Bind(completion_callback, result)); | |
| 29 } | 39 } |
| 30 #endif | 40 #endif |
| 31 | 41 |
| 32 } // namespace | 42 } // namespace |
| 33 | 43 |
| 34 void GetIsAppLauncherEnabled( | 44 enum AppLauncherState { |
| 35 const OnAppLauncherEnabledCompleted& completion_callback) { | 45 APP_LAUNCHER_UNKNOWN, |
| 36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 46 APP_LAUNCHER_ENABLED, |
| 37 #if defined(OS_CHROMEOS) | 47 APP_LAUNCHER_DISABLED, |
| 38 completion_callback.Run(true); | 48 }; |
| 49 |
| 50 AppLauncherState SynchronousAppLauncherChecks() { |
| 51 #if defined(USE_ASH) |
| 52 return APP_LAUNCHER_ENABLED; |
| 39 #elif !defined(OS_WIN) | 53 #elif !defined(OS_WIN) |
| 40 completion_callback.Run(false); | 54 return APP_LAUNCHER_DISABLED; |
| 41 #else | 55 #else |
| 42 if (CommandLine::ForCurrentProcess()->HasSwitch( | 56 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 switches::kShowAppListShortcut)) { | 57 switches::kShowAppListShortcut)) { |
| 44 completion_callback.Run(true); | 58 return APP_LAUNCHER_ENABLED; |
| 59 } |
| 60 |
| 61 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported()) |
| 62 return APP_LAUNCHER_DISABLED; |
| 63 |
| 64 return APP_LAUNCHER_UNKNOWN; |
| 65 #endif |
| 66 } |
| 67 |
| 68 void UpdateIsAppLauncherEnabled( |
| 69 const OnAppLauncherEnabledCompleted& completion_callback) { |
| 70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 71 |
| 72 AppLauncherState state = SynchronousAppLauncherChecks(); |
| 73 |
| 74 if (state != APP_LAUNCHER_UNKNOWN) { |
| 75 bool is_enabled = state == APP_LAUNCHER_ENABLED; |
| 76 PrefService* prefs = g_browser_process->local_state(); |
| 77 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled); |
| 78 completion_callback.Run(is_enabled); |
| 45 return; | 79 return; |
| 46 } | 80 } |
| 47 | 81 |
| 48 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported()) { | |
| 49 completion_callback.Run(false); | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 content::BrowserThread::PostBlockingPoolTask( | 82 content::BrowserThread::PostBlockingPoolTask( |
| 54 FROM_HERE, | 83 FROM_HERE, |
| 55 base::Bind(&IsAppLauncherInstalledOnBlockingPool, | 84 base::Bind(&IsAppLauncherInstalledOnBlockingPool, |
| 56 completion_callback)); | 85 completion_callback)); |
| 57 #endif | |
| 58 } | 86 } |
| 59 | 87 |
| 88 bool IsAppLauncherEnabled() { |
| 89 PrefService* prefs = g_browser_process->local_state(); |
| 90 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled); |
| 91 } |
| 92 |
| 93 namespace app_launcher { |
| 94 |
| 95 void RegisterPrefs(PrefServiceSimple* pref_service) { |
| 96 // If it is impossible to synchronously determine whether the app launcher is |
| 97 // enabled, assume it is disabled. Anything that needs to know the absolute |
| 98 // truth should call UpdateIsAppLauncherEnabled(). |
| 99 // |
| 100 // This pref is just a cache of the value from the registry from last time |
| 101 // Chrome ran. To avoid having the NTP block on a registry check, it guesses |
| 102 // that the value hasn't changed since last time it was checked, using this |
| 103 // preference. |
| 104 bool is_enabled = SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; |
| 105 pref_service->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, is_enabled); |
| 106 } |
| 107 |
| 108 } // namespace app_launcher |
| 109 |
| 60 } // namespace extensions | 110 } // namespace extensions |
| OLD | NEW |