|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/default_apps_provider.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/metrics/field_trial.h" | |
9 #include "chrome/browser/browser_process.h" | |
10 #include "chrome/browser/extensions/default_apps_trial.h" | |
11 #include "chrome/browser/extensions/extension_service.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/common/chrome_switches.h" | |
14 #include "chrome/common/pref_names.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 | |
17 void DefaultAppsProvider::RegisterUserPrefs(PrefService* prefs) { | |
18 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown, | |
19 PrefService::UNSYNCABLE_PREF); | |
20 } | |
21 | |
22 bool DefaultAppsProvider::ShouldRegister(Profile* profile) { | |
23 // We decide to install or not install default apps based on the following | |
24 // criteria, from highest priority to lowest priority: | |
25 // | |
26 // - if this instance of chrome is participating in the default apps | |
27 // field trial, then install apps based on the group | |
28 // - the command line option. Tests use this option to disable installation | |
29 // of default apps in some cases | |
30 // - if the locale is not compatible with the defaults, don't install them | |
31 // - if the profile says to either always install or never install default | |
32 // apps, obey | |
33 // - the kDefaultApps preferences value in the profile. This value is | |
34 // usually set in the master_preferences file | |
Finnur
2011/10/21 09:59:32
Nit: Capitalize first word of comments (personal p
Roger Tawa OOO till Jul 10th
2011/10/24 14:23:14
Done.
| |
35 bool install_apps = | |
36 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; | |
37 | |
38 int state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
39 switch (state) { | |
40 case kUnknown: { | |
41 // We get here for either new profile, or profiles created before the | |
42 // default apps feature was implemented. In the former case, we always | |
43 // want to install default apps. In the latter case, we don't want to | |
44 // disturb a user that has already installed and possibly curated a list | |
45 // of favourite apps, so we only install if there are no apps in the | |
46 // profile. We can check for both these cases by looking to see if | |
47 // any apps already exist. | |
48 ExtensionService* extension_service = profile->GetExtensionService(); | |
49 if (extension_service && extension_service->HasApps()) | |
50 install_apps = false; | |
51 break; | |
52 } | |
53 case kAlwaysProvideDefaultApps: | |
54 install_apps = true; | |
55 break; | |
56 case kNeverProvideDefaultApps: | |
57 install_apps = false; | |
58 break; | |
59 default: | |
60 NOTREACHED(); | |
Finnur
2011/10/21 09:59:32
Just something to consider: If you leave out the d
Roger Tawa OOO till Jul 10th
2011/10/24 14:23:14
Done.
| |
61 } | |
62 | |
63 if (install_apps) { | |
64 // Don't bother installing default apps in locales where its known that | |
65 // they don't work. | |
66 // TODO(rogerta): Do this check dynamically once the webstore can expose | |
67 // an API. | |
Finnur
2011/10/21 09:59:32
Is there a bug on this you can reference?
Roger Tawa OOO till Jul 10th
2011/10/24 14:23:14
No, created one and added to comment.
| |
68 const std::string& locale = g_browser_process->GetApplicationLocale(); | |
69 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; | |
70 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { | |
71 if (EndsWith(locale, unsupported_locales[i], false)) { | |
72 install_apps = false; | |
73 break; | |
74 } | |
75 } | |
76 } | |
77 | |
78 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
79 switches::kDisableDefaultApps)) { | |
80 install_apps = false; | |
81 } | |
82 | |
83 if (base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name)) { | |
84 install_apps = base::FieldTrialList::Find( | |
85 kDefaultAppsTrial_Name)->group_name() != kDefaultAppsTrial_NoAppsGroup; | |
86 } | |
87 | |
88 // Save the state if needed. | |
89 if (state == kUnknown) { | |
90 if (install_apps) { | |
91 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
92 kAlwaysProvideDefaultApps); | |
93 } else { | |
94 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
95 kNeverProvideDefaultApps); | |
96 } | |
97 profile->GetPrefs()->ScheduleSavePersistentPrefs(); | |
98 } | |
99 | |
100 return install_apps; | |
101 } | |
OLD | NEW |