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

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: pref -> app_launcher 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,
47 APP_LAUNCHER_DISABLED,
48 };
49
50 AppLauncherState SynchronousAppLauncherChecks() {
37 #if defined(OS_CHROMEOS) 51 #if defined(OS_CHROMEOS)
Evan Stade 2013/01/24 18:40:17 should this be USE_ASH?
jeremya 2013/01/25 00:06:19 Yeah, I think that makes sense. Changed.
38 completion_callback.Run(true); 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 }
Evan Stade 2013/01/24 18:40:17 nit: no curlies
jeremya 2013/01/25 00:06:19 Done.
64
65 return APP_LAUNCHER_UNKNOWN;
66 #endif
67 }
68
69 void UpdateIsAppLauncherEnabled(
70 const OnAppLauncherEnabledCompleted& completion_callback) {
71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
72
73 AppLauncherState state = SynchronousAppLauncherChecks();
74
75 if (state != APP_LAUNCHER_UNKNOWN) {
76 bool is_enabled = state == APP_LAUNCHER_ENABLED;
77 PrefService* prefs = g_browser_process->local_state();
78 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled);
79 completion_callback.Run(is_enabled);
45 return; 80 return;
46 } 81 }
47 82
48 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported()) {
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));
57 #endif
58 } 87 }
59 88
89 bool IsAppLauncherEnabled() {
90 PrefService* prefs = g_browser_process->local_state();
91 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
92 }
93
94 namespace app_launcher {
Evan Stade 2013/01/24 18:40:17 \n
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 bool is_enabled = SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
100 pref_service->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, is_enabled);
Evan Stade 2013/01/24 18:40:17 would be nice to explain a bit more why this is ne
jeremya 2013/01/25 00:06:19 Done.
101 }
Evan Stade 2013/01/24 18:40:17 \n
102 } // namespace app_launcher
103
60 } // namespace extensions 104 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698