| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/default_apps.h" | 5 #include "chrome/browser/extensions/default_apps.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/first_run/first_run.h" | 10 #include "chrome/browser/first_run/first_run.h" |
| 11 #include "chrome/browser/extensions/default_apps_trial.h" | 11 #include "chrome/browser/extensions/default_apps_trial.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/chrome_version_info.h" | 15 #include "chrome/common/chrome_version_info.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 | 19 |
| 20 namespace default_apps { | 20 namespace default_apps { |
| 21 | 21 |
| 22 bool isMigration; |
| 23 |
| 22 bool ShouldInstallInProfile(Profile* profile) { | 24 bool ShouldInstallInProfile(Profile* profile) { |
| 23 // We decide to install or not install default apps based on the following | 25 // We decide to install or not install default apps based on the following |
| 24 // criteria, from highest priority to lowest priority: | 26 // criteria, from highest priority to lowest priority: |
| 25 // | 27 // |
| 26 // - If this instance of chrome is participating in the default apps | 28 // - If this instance of chrome is participating in the default apps |
| 27 // field trial, then install apps based on the group. | 29 // field trial, then install apps based on the group. |
| 28 // - The command line option. Tests use this option to disable installation | 30 // - The command line option. Tests use this option to disable installation |
| 29 // of default apps in some cases. | 31 // of default apps in some cases. |
| 30 // - If the locale is not compatible with the defaults, don't install them. | 32 // - If the locale is not compatible with the defaults, don't install them. |
| 31 // - The kDefaultApps preferences value in the profile. This value is | 33 // - The kDefaultApps preferences value in the profile. This value is |
| 32 // usually set in the master_preferences file. | 34 // usually set in the master_preferences file. |
| 33 bool install_apps = | 35 bool install_apps = |
| 34 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; | 36 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; |
| 35 | 37 |
| 36 default_apps::InstallState state = | 38 InstallState state = |
| 37 static_cast<default_apps::InstallState>(profile->GetPrefs()->GetInteger( | 39 static_cast<InstallState>(profile->GetPrefs()->GetInteger( |
| 38 prefs::kDefaultAppsInstallState)); | 40 prefs::kDefaultAppsInstallState)); |
| 39 | 41 |
| 42 isMigration = (state == kProvideLegacyDefaultApps); |
| 43 |
| 40 switch (state) { | 44 switch (state) { |
| 41 case default_apps::kUnknown: { | 45 case kUnknown: { |
| 42 // This is the first time the default apps feature runs on this profile. | 46 // This is the first time the default apps feature runs on this profile. |
| 43 // Determine if we want to install them or not. | 47 // Determine if we want to install them or not. |
| 44 chrome::VersionInfo version_info; | 48 chrome::VersionInfo version_info; |
| 45 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str())) | 49 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str())) |
| 46 install_apps = false; | 50 install_apps = false; |
| 47 break; | 51 break; |
| 48 } | 52 } |
| 49 | 53 |
| 50 // The old default apps were provided as external extensions and were | 54 // The old default apps were provided as external extensions and were |
| 51 // installed everytime Chrome was run. Thus, changing the list of default | 55 // installed everytime Chrome was run. Thus, changing the list of default |
| 52 // apps affected all users. Migrate old default apps to new mechanism where | 56 // apps affected all users. Migrate old default apps to new mechanism where |
| 53 // they are installed only once as INTERNAL. | 57 // they are installed only once as INTERNAL. |
| 54 // TODO(grv) : remove after Q1-2013. | 58 // TODO(grv) : remove after Q1-2013. |
| 55 case default_apps::kProvideLegacyDefaultApps: | 59 case kProvideLegacyDefaultApps: |
| 56 profile->GetPrefs()->SetInteger( | 60 profile->GetPrefs()->SetInteger( |
| 57 prefs::kDefaultAppsInstallState, | 61 prefs::kDefaultAppsInstallState, |
| 58 default_apps::kAlreadyInstalledDefaultApps); | 62 kAlreadyInstalledDefaultApps); |
| 59 break; | 63 break; |
| 60 | 64 |
| 61 case default_apps::kAlreadyInstalledDefaultApps: | 65 case kAlreadyInstalledDefaultApps: |
| 62 case default_apps::kNeverInstallDefaultApps: | 66 case kNeverInstallDefaultApps: |
| 63 install_apps = false; | 67 install_apps = false; |
| 64 break; | 68 break; |
| 65 default: | 69 default: |
| 66 NOTREACHED(); | 70 NOTREACHED(); |
| 67 } | 71 } |
| 68 | 72 |
| 69 if (install_apps && !isLocaleSupported()) { | 73 if (install_apps && !isLocaleSupported()) { |
| 70 install_apps = false; | 74 install_apps = false; |
| 71 } | 75 } |
| 72 | 76 |
| 73 if (CommandLine::ForCurrentProcess()->HasSwitch( | 77 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 74 switches::kDisableDefaultApps)) { | 78 switches::kDisableDefaultApps)) { |
| 75 install_apps = false; | 79 install_apps = false; |
| 76 } | 80 } |
| 77 | 81 |
| 78 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) { | 82 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) { |
| 79 install_apps = base::FieldTrialList::Find( | 83 install_apps = base::FieldTrialList::Find( |
| 80 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup; | 84 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup; |
| 81 } | 85 } |
| 82 | 86 |
| 83 // Default apps are only installed on profile creation or a new chrome | 87 // Default apps are only installed on profile creation or a new chrome |
| 84 // download. | 88 // download. |
| 85 if (state == default_apps::kUnknown) { | 89 if (state == kUnknown) { |
| 86 if (install_apps) { | 90 if (install_apps) { |
| 87 profile->GetPrefs()->SetInteger( | 91 profile->GetPrefs()->SetInteger( |
| 88 prefs::kDefaultAppsInstallState, | 92 prefs::kDefaultAppsInstallState, |
| 89 default_apps::kAlreadyInstalledDefaultApps); | 93 kAlreadyInstalledDefaultApps); |
| 90 } else { | 94 } else { |
| 91 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | 95 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, |
| 92 default_apps::kNeverInstallDefaultApps); | 96 kNeverInstallDefaultApps); |
| 93 } | 97 } |
| 94 } | 98 } |
| 95 | 99 |
| 96 return install_apps; | 100 return install_apps; |
| 97 } | 101 } |
| 98 | 102 |
| 99 void RegisterUserPrefs(PrefService* prefs) { | 103 void RegisterUserPrefs(PrefService* prefs) { |
| 100 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown, | 104 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown, |
| 101 PrefService::UNSYNCABLE_PREF); | 105 PrefService::UNSYNCABLE_PREF); |
| 102 } | 106 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 133 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; | 137 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; |
| 134 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { | 138 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { |
| 135 if (EndsWith(locale, unsupported_locales[i], false)) { | 139 if (EndsWith(locale, unsupported_locales[i], false)) { |
| 136 return false; | 140 return false; |
| 137 } | 141 } |
| 138 } | 142 } |
| 139 return true; | 143 return true; |
| 140 } | 144 } |
| 141 | 145 |
| 142 } // namespace default_apps | 146 } // namespace default_apps |
| OLD | NEW |