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.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 namespace default_apps { |
| 18 |
| 19 void RegisterUserPrefs(PrefService* prefs) { |
| 20 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown, |
| 21 PrefService::UNSYNCABLE_PREF); |
| 22 } |
| 23 |
| 24 bool ShouldInstallInProfile(Profile* profile) { |
| 25 // We decide to install or not install default apps based on the following |
| 26 // criteria, from highest priority to lowest priority: |
| 27 // |
| 28 // - If this instance of chrome is participating in the default apps |
| 29 // field trial, then install apps based on the group. |
| 30 // - The command line option. Tests use this option to disable installation |
| 31 // of default apps in some cases. |
| 32 // - If the locale is not compatible with the defaults, don't install them. |
| 33 // - If the profile says to either always install or never install default |
| 34 // apps, obey. |
| 35 // - The kDefaultApps preferences value in the profile. This value is |
| 36 // usually set in the master_preferences file. |
| 37 bool install_apps = |
| 38 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; |
| 39 |
| 40 InstallState state = static_cast<InstallState>(profile->GetPrefs()-> |
| 41 GetInteger(prefs::kDefaultAppsInstallState)); |
| 42 switch (state) { |
| 43 case kUnknown: { |
| 44 // We get here for either new profile, or profiles created before the |
| 45 // default apps feature was implemented. In the former case, we always |
| 46 // want to install default apps. In the latter case, we don't want to |
| 47 // disturb a user that has already installed and possibly curated a list |
| 48 // of favourite apps, so we only install if there are no apps in the |
| 49 // profile. We can check for both these cases by looking to see if |
| 50 // any apps already exist. |
| 51 ExtensionService* extension_service = profile->GetExtensionService(); |
| 52 if (extension_service && extension_service->HasApps()) |
| 53 install_apps = false; |
| 54 break; |
| 55 } |
| 56 case kAlwaysProvideDefaultApps: |
| 57 install_apps = true; |
| 58 break; |
| 59 case kNeverProvideDefaultApps: |
| 60 install_apps = false; |
| 61 break; |
| 62 default: |
| 63 NOTREACHED(); |
| 64 } |
| 65 |
| 66 if (install_apps) { |
| 67 // Don't bother installing default apps in locales where it is known that |
| 68 // they don't work. |
| 69 // TODO(rogerta): Do this check dynamically once the webstore can expose |
| 70 // an API. See http://crbug.com/101357 |
| 71 const std::string& locale = g_browser_process->GetApplicationLocale(); |
| 72 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; |
| 73 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { |
| 74 if (EndsWith(locale, unsupported_locales[i], false)) { |
| 75 install_apps = false; |
| 76 break; |
| 77 } |
| 78 } |
| 79 } |
| 80 |
| 81 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 82 switches::kDisableDefaultApps)) { |
| 83 install_apps = false; |
| 84 } |
| 85 |
| 86 if (base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name)) { |
| 87 install_apps = base::FieldTrialList::Find( |
| 88 kDefaultAppsTrial_Name)->group_name() != kDefaultAppsTrial_NoAppsGroup; |
| 89 } |
| 90 |
| 91 // Save the state if needed. |
| 92 if (state == kUnknown) { |
| 93 if (install_apps) { |
| 94 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, |
| 95 kAlwaysProvideDefaultApps); |
| 96 } else { |
| 97 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, |
| 98 kNeverProvideDefaultApps); |
| 99 } |
| 100 profile->GetPrefs()->ScheduleSavePersistentPrefs(); |
| 101 } |
| 102 |
| 103 return install_apps; |
| 104 } |
| 105 |
| 106 } // namespace default_apps |
OLD | NEW |