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

Side by Side Diff: chrome/browser/extensions/app_launcher.cc

Issue 11953021: Don't show the apps page on the NTP if the app launcher is installed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move getShouldShowApps message to onLoad. Created 7 years, 11 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 (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()) { 82 #if defined(OS_WIN)
49 completion_callback.Run(false);
50 return;
51 }
52
53 content::BrowserThread::PostBlockingPoolTask( 83 content::BrowserThread::PostBlockingPoolTask(
54 FROM_HERE, 84 FROM_HERE,
55 base::Bind(&IsAppLauncherInstalledOnBlockingPool, 85 base::Bind(&IsAppLauncherInstalledOnBlockingPool,
56 completion_callback)); 86 completion_callback));
87 #else
88 // SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on
89 // !defined(OS_WIN), so this path is never reached.
90 NOTREACHED();
57 #endif 91 #endif
58 } 92 }
59 93
94 bool IsAppLauncherEnabled() {
95 PrefService* prefs = g_browser_process->local_state();
96 // In some tests, the prefs aren't initialised, but the NTP still needs to
97 // work.
98 if (!prefs)
99 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
100 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
101 }
102
103 namespace app_launcher {
104
105 void RegisterPrefs(PrefServiceSimple* pref_service) {
106 // If it is impossible to synchronously determine whether the app launcher is
107 // enabled, assume it is disabled. Anything that needs to know the absolute
108 // truth should call UpdateIsAppLauncherEnabled().
109 //
110 // This pref is just a cache of the value from the registry from last time
111 // Chrome ran. To avoid having the NTP block on a registry check, it guesses
112 // that the value hasn't changed since last time it was checked, using this
113 // preference.
114 bool is_enabled = SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
115 pref_service->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, is_enabled);
116 }
117
118 } // namespace app_launcher
119
60 } // namespace extensions 120 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_launcher.h ('k') | chrome/browser/extensions/extension_install_ui_default.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698