Chromium Code Reviews| 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; | |
|
Mihai Parparita -not on Chrome
2012/08/27 23:36:21
It's a bit better now that this global is not expo
| |
| 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 14 matching lines...) Expand all Loading... | |
| 117 void Provider::VisitRegisteredExtension() { | 121 void Provider::VisitRegisteredExtension() { |
| 118 if (!profile_ || !ShouldInstallInProfile(profile_)) { | 122 if (!profile_ || !ShouldInstallInProfile(profile_)) { |
| 119 base::DictionaryValue* prefs = new base::DictionaryValue; | 123 base::DictionaryValue* prefs = new base::DictionaryValue; |
| 120 SetPrefs(prefs); | 124 SetPrefs(prefs); |
| 121 return; | 125 return; |
| 122 } | 126 } |
| 123 | 127 |
| 124 extensions::ExternalProviderImpl::VisitRegisteredExtension(); | 128 extensions::ExternalProviderImpl::VisitRegisteredExtension(); |
| 125 } | 129 } |
| 126 | 130 |
| 131 void Provider::SetPrefs(base::DictionaryValue* prefs) { | |
| 132 if (isMigration) { | |
| 133 // Filter out the new default apps for migrating users. | |
| 134 for (base::DictionaryValue::key_iterator i = prefs->begin_keys(); | |
| 135 i != prefs->end_keys(); ++i) { | |
| 136 if (!isOldDefaultApp(*i)) { | |
| 137 prefs->Remove(*i, NULL); | |
| 138 } | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 ExternalProviderImpl::SetPrefs(prefs); | |
| 143 } | |
| 144 | |
| 145 bool isOldDefaultApp(const std::string& extension_id) { | |
| 146 const std::string gmail_id = "pjkljhegncpnkpknbcohdijeoejaedia"; | |
| 147 const std::string search_id = "coobgpohoikkiipiblmjeljniedjpjpf"; | |
| 148 const std::string youtube_id = "blpcfgokakmgnkcojhhkbfbldkacnbeo"; | |
| 149 return extension_id == gmail_id || extension_id == search_id | |
| 150 || extension_id == youtube_id; | |
| 151 } | |
| 152 | |
| 127 bool isLocaleSupported() { | 153 bool isLocaleSupported() { |
| 128 // Don't bother installing default apps in locales where it is known that | 154 // Don't bother installing default apps in locales where it is known that |
| 129 // they don't work. | 155 // they don't work. |
| 130 // TODO(rogerta): Do this check dynamically once the webstore can expose | 156 // TODO(rogerta): Do this check dynamically once the webstore can expose |
| 131 // an API. See http://crbug.com/101357 | 157 // an API. See http://crbug.com/101357 |
| 132 const std::string& locale = g_browser_process->GetApplicationLocale(); | 158 const std::string& locale = g_browser_process->GetApplicationLocale(); |
| 133 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; | 159 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; |
| 134 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { | 160 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { |
| 135 if (EndsWith(locale, unsupported_locales[i], false)) { | 161 if (EndsWith(locale, unsupported_locales[i], false)) { |
| 136 return false; | 162 return false; |
| 137 } | 163 } |
| 138 } | 164 } |
| 139 return true; | 165 return true; |
| 140 } | 166 } |
| 141 | 167 |
| 142 } // namespace default_apps | 168 } // namespace default_apps |
| OLD | NEW |