Chromium Code Reviews| Index: chrome/browser/extensions/default_apps.cc |
| diff --git a/chrome/browser/extensions/default_apps.cc b/chrome/browser/extensions/default_apps.cc |
| index 31762906b121cdb5b6cc70d9f204879bd31ced62..44abbb20d1b884fa1b049c12f7ba72bd9b7a3876 100644 |
| --- a/chrome/browser/extensions/default_apps.cc |
| +++ b/chrome/browser/extensions/default_apps.cc |
| @@ -17,9 +17,45 @@ |
| #include "chrome/common/pref_names.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +namespace { |
| + |
| +const char gmail_id[] = "pjkljhegncpnkpknbcohdijeoejaedia"; |
|
Mihai Parparita -not on Chrome
2012/08/29 00:51:18
See http://google-styleguide.googlecode.com/svn/tr
|
| +const char search_id[] = "coobgpohoikkiipiblmjeljniedjpjpf"; |
| +const char youtube_id[] = "blpcfgokakmgnkcojhhkbfbldkacnbeo"; |
| + |
| +// Returns true if the app was a default app in Chrome 22 |
| +bool IsOldDefaultApp(const std::string& extension_id) { |
| + return extension_id == gmail_id || extension_id == search_id |
| + || extension_id == youtube_id; |
| +} |
| + |
| +bool IsLocaleSupported() { |
| + // Don't bother installing default apps in locales where it is known that |
| + // they don't work. |
| + // TODO(rogerta): Do this check dynamically once the webstore can expose |
| + // an API. See http://crbug.com/101357 |
| + const std::string& locale = g_browser_process->GetApplicationLocale(); |
| + static const char* unsupported_locales[] = {"CN", "TR", "IR"}; |
| + for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { |
| + if (EndsWith(locale, unsupported_locales[i], false)) { |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace |
| + |
| namespace default_apps { |
| -bool ShouldInstallInProfile(Profile* profile) { |
| +void RegisterUserPrefs(PrefService* prefs) { |
| + prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown, |
| + PrefService::UNSYNCABLE_PREF); |
| +} |
| + |
| +bool Provider::isMigration_ = false; |
| + |
| +bool Provider::ShouldInstallInProfile(Profile* profile) { |
| // We decide to install or not install default apps based on the following |
| // criteria, from highest priority to lowest priority: |
| // |
| @@ -33,12 +69,14 @@ bool ShouldInstallInProfile(Profile* profile) { |
| bool install_apps = |
| profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; |
| - default_apps::InstallState state = |
| - static_cast<default_apps::InstallState>(profile->GetPrefs()->GetInteger( |
| + InstallState state = |
| + static_cast<InstallState>(profile->GetPrefs()->GetInteger( |
| prefs::kDefaultAppsInstallState)); |
| + isMigration_ = (state == kProvideLegacyDefaultApps); |
| + |
| switch (state) { |
| - case default_apps::kUnknown: { |
| + case kUnknown: { |
| // This is the first time the default apps feature runs on this profile. |
| // Determine if we want to install them or not. |
| chrome::VersionInfo version_info; |
| @@ -52,21 +90,21 @@ bool ShouldInstallInProfile(Profile* profile) { |
| // apps affected all users. Migrate old default apps to new mechanism where |
| // they are installed only once as INTERNAL. |
| // TODO(grv) : remove after Q1-2013. |
| - case default_apps::kProvideLegacyDefaultApps: |
| + case kProvideLegacyDefaultApps: |
| profile->GetPrefs()->SetInteger( |
| prefs::kDefaultAppsInstallState, |
| - default_apps::kAlreadyInstalledDefaultApps); |
| + kAlreadyInstalledDefaultApps); |
| break; |
| - case default_apps::kAlreadyInstalledDefaultApps: |
| - case default_apps::kNeverInstallDefaultApps: |
| + case kAlreadyInstalledDefaultApps: |
| + case kNeverInstallDefaultApps: |
| install_apps = false; |
| break; |
| default: |
| NOTREACHED(); |
| } |
| - if (install_apps && !isLocaleSupported()) { |
| + if (install_apps && !IsLocaleSupported()) { |
| install_apps = false; |
| } |
| @@ -82,25 +120,20 @@ bool ShouldInstallInProfile(Profile* profile) { |
| // Default apps are only installed on profile creation or a new chrome |
| // download. |
| - if (state == default_apps::kUnknown) { |
| + if (state == kUnknown) { |
| if (install_apps) { |
| profile->GetPrefs()->SetInteger( |
| prefs::kDefaultAppsInstallState, |
| - default_apps::kAlreadyInstalledDefaultApps); |
| + kAlreadyInstalledDefaultApps); |
| } else { |
| profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, |
| - default_apps::kNeverInstallDefaultApps); |
| + kNeverInstallDefaultApps); |
| } |
| } |
| return install_apps; |
| } |
| -void RegisterUserPrefs(PrefService* prefs) { |
| - prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown, |
| - PrefService::UNSYNCABLE_PREF); |
| -} |
| - |
| Provider::Provider(Profile* profile, |
| VisitorInterface* service, |
| extensions::ExternalLoader* loader, |
| @@ -124,19 +157,23 @@ void Provider::VisitRegisteredExtension() { |
| extensions::ExternalProviderImpl::VisitRegisteredExtension(); |
| } |
| -bool isLocaleSupported() { |
| - // Don't bother installing default apps in locales where it is known that |
| - // they don't work. |
| - // TODO(rogerta): Do this check dynamically once the webstore can expose |
| - // an API. See http://crbug.com/101357 |
| - const std::string& locale = g_browser_process->GetApplicationLocale(); |
| - static const char* unsupported_locales[] = {"CN", "TR", "IR"}; |
| - for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { |
| - if (EndsWith(locale, unsupported_locales[i], false)) { |
| - return false; |
| +void Provider::SetPrefs(base::DictionaryValue* prefs) { |
| + if (isMigration_) { |
| + std::set<std::string> new_default_apps; |
| + for (base::DictionaryValue::key_iterator i = prefs->begin_keys(); |
| + i != prefs->end_keys(); ++i) { |
| + if (!IsOldDefaultApp(*i)) { |
| + new_default_apps.insert(*i); |
| + } |
| + } |
| + // Filter out the new default apps for migrating users. |
| + for (std::set<std::string>::iterator it = new_default_apps.begin(); |
| + it != new_default_apps.end(); ++it) { |
| + prefs->Remove(*it, NULL); |
| } |
| } |
| - return true; |
| + |
| + ExternalProviderImpl::SetPrefs(prefs); |
| } |
| } // namespace default_apps |