Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: chrome/browser/extensions/default_apps.cc

Issue 10875065: Disable install of new default_apps for existing users (Closed) Base URL: http://git.chromium.org/git/chromium.git@disable_sync_behav
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
21
22 const char gmail_id[] = "pjkljhegncpnkpknbcohdijeoejaedia";
Mihai Parparita -not on Chrome 2012/08/29 00:51:18 See http://google-styleguide.googlecode.com/svn/tr
23 const char search_id[] = "coobgpohoikkiipiblmjeljniedjpjpf";
24 const char youtube_id[] = "blpcfgokakmgnkcojhhkbfbldkacnbeo";
25
26 // Returns true if the app was a default app in Chrome 22
27 bool IsOldDefaultApp(const std::string& extension_id) {
28 return extension_id == gmail_id || extension_id == search_id
29 || extension_id == youtube_id;
30 }
31
32 bool IsLocaleSupported() {
33 // Don't bother installing default apps in locales where it is known that
34 // they don't work.
35 // TODO(rogerta): Do this check dynamically once the webstore can expose
36 // an API. See http://crbug.com/101357
37 const std::string& locale = g_browser_process->GetApplicationLocale();
38 static const char* unsupported_locales[] = {"CN", "TR", "IR"};
39 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) {
40 if (EndsWith(locale, unsupported_locales[i], false)) {
41 return false;
42 }
43 }
44 return true;
45 }
46
47 } // namespace
48
20 namespace default_apps { 49 namespace default_apps {
21 50
22 bool ShouldInstallInProfile(Profile* profile) { 51 void RegisterUserPrefs(PrefService* prefs) {
52 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown,
53 PrefService::UNSYNCABLE_PREF);
54 }
55
56 bool Provider::isMigration_ = false;
57
58 bool Provider::ShouldInstallInProfile(Profile* profile) {
23 // We decide to install or not install default apps based on the following 59 // We decide to install or not install default apps based on the following
24 // criteria, from highest priority to lowest priority: 60 // criteria, from highest priority to lowest priority:
25 // 61 //
26 // - If this instance of chrome is participating in the default apps 62 // - If this instance of chrome is participating in the default apps
27 // field trial, then install apps based on the group. 63 // field trial, then install apps based on the group.
28 // - The command line option. Tests use this option to disable installation 64 // - The command line option. Tests use this option to disable installation
29 // of default apps in some cases. 65 // of default apps in some cases.
30 // - If the locale is not compatible with the defaults, don't install them. 66 // - If the locale is not compatible with the defaults, don't install them.
31 // - The kDefaultApps preferences value in the profile. This value is 67 // - The kDefaultApps preferences value in the profile. This value is
32 // usually set in the master_preferences file. 68 // usually set in the master_preferences file.
33 bool install_apps = 69 bool install_apps =
34 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; 70 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install";
35 71
36 default_apps::InstallState state = 72 InstallState state =
37 static_cast<default_apps::InstallState>(profile->GetPrefs()->GetInteger( 73 static_cast<InstallState>(profile->GetPrefs()->GetInteger(
38 prefs::kDefaultAppsInstallState)); 74 prefs::kDefaultAppsInstallState));
39 75
76 isMigration_ = (state == kProvideLegacyDefaultApps);
77
40 switch (state) { 78 switch (state) {
41 case default_apps::kUnknown: { 79 case kUnknown: {
42 // This is the first time the default apps feature runs on this profile. 80 // This is the first time the default apps feature runs on this profile.
43 // Determine if we want to install them or not. 81 // Determine if we want to install them or not.
44 chrome::VersionInfo version_info; 82 chrome::VersionInfo version_info;
45 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str())) 83 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str()))
46 install_apps = false; 84 install_apps = false;
47 break; 85 break;
48 } 86 }
49 87
50 // The old default apps were provided as external extensions and were 88 // The old default apps were provided as external extensions and were
51 // installed everytime Chrome was run. Thus, changing the list of default 89 // installed everytime Chrome was run. Thus, changing the list of default
52 // apps affected all users. Migrate old default apps to new mechanism where 90 // apps affected all users. Migrate old default apps to new mechanism where
53 // they are installed only once as INTERNAL. 91 // they are installed only once as INTERNAL.
54 // TODO(grv) : remove after Q1-2013. 92 // TODO(grv) : remove after Q1-2013.
55 case default_apps::kProvideLegacyDefaultApps: 93 case kProvideLegacyDefaultApps:
56 profile->GetPrefs()->SetInteger( 94 profile->GetPrefs()->SetInteger(
57 prefs::kDefaultAppsInstallState, 95 prefs::kDefaultAppsInstallState,
58 default_apps::kAlreadyInstalledDefaultApps); 96 kAlreadyInstalledDefaultApps);
59 break; 97 break;
60 98
61 case default_apps::kAlreadyInstalledDefaultApps: 99 case kAlreadyInstalledDefaultApps:
62 case default_apps::kNeverInstallDefaultApps: 100 case kNeverInstallDefaultApps:
63 install_apps = false; 101 install_apps = false;
64 break; 102 break;
65 default: 103 default:
66 NOTREACHED(); 104 NOTREACHED();
67 } 105 }
68 106
69 if (install_apps && !isLocaleSupported()) { 107 if (install_apps && !IsLocaleSupported()) {
70 install_apps = false; 108 install_apps = false;
71 } 109 }
72 110
73 if (CommandLine::ForCurrentProcess()->HasSwitch( 111 if (CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kDisableDefaultApps)) { 112 switches::kDisableDefaultApps)) {
75 install_apps = false; 113 install_apps = false;
76 } 114 }
77 115
78 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) { 116 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) {
79 install_apps = base::FieldTrialList::Find( 117 install_apps = base::FieldTrialList::Find(
80 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup; 118 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup;
81 } 119 }
82 120
83 // Default apps are only installed on profile creation or a new chrome 121 // Default apps are only installed on profile creation or a new chrome
84 // download. 122 // download.
85 if (state == default_apps::kUnknown) { 123 if (state == kUnknown) {
86 if (install_apps) { 124 if (install_apps) {
87 profile->GetPrefs()->SetInteger( 125 profile->GetPrefs()->SetInteger(
88 prefs::kDefaultAppsInstallState, 126 prefs::kDefaultAppsInstallState,
89 default_apps::kAlreadyInstalledDefaultApps); 127 kAlreadyInstalledDefaultApps);
90 } else { 128 } else {
91 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, 129 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
92 default_apps::kNeverInstallDefaultApps); 130 kNeverInstallDefaultApps);
93 } 131 }
94 } 132 }
95 133
96 return install_apps; 134 return install_apps;
97 } 135 }
98 136
99 void RegisterUserPrefs(PrefService* prefs) {
100 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown,
101 PrefService::UNSYNCABLE_PREF);
102 }
103
104 Provider::Provider(Profile* profile, 137 Provider::Provider(Profile* profile,
105 VisitorInterface* service, 138 VisitorInterface* service,
106 extensions::ExternalLoader* loader, 139 extensions::ExternalLoader* loader,
107 extensions::Extension::Location crx_location, 140 extensions::Extension::Location crx_location,
108 extensions::Extension::Location download_location, 141 extensions::Extension::Location download_location,
109 int creation_flags) 142 int creation_flags)
110 : extensions::ExternalProviderImpl(service, loader, crx_location, 143 : extensions::ExternalProviderImpl(service, loader, crx_location,
111 download_location, creation_flags), 144 download_location, creation_flags),
112 profile_(profile) { 145 profile_(profile) {
113 DCHECK(profile); 146 DCHECK(profile);
114 set_auto_acknowledge(true); 147 set_auto_acknowledge(true);
115 } 148 }
116 149
117 void Provider::VisitRegisteredExtension() { 150 void Provider::VisitRegisteredExtension() {
118 if (!profile_ || !ShouldInstallInProfile(profile_)) { 151 if (!profile_ || !ShouldInstallInProfile(profile_)) {
119 base::DictionaryValue* prefs = new base::DictionaryValue; 152 base::DictionaryValue* prefs = new base::DictionaryValue;
120 SetPrefs(prefs); 153 SetPrefs(prefs);
121 return; 154 return;
122 } 155 }
123 156
124 extensions::ExternalProviderImpl::VisitRegisteredExtension(); 157 extensions::ExternalProviderImpl::VisitRegisteredExtension();
125 } 158 }
126 159
127 bool isLocaleSupported() { 160 void Provider::SetPrefs(base::DictionaryValue* prefs) {
128 // Don't bother installing default apps in locales where it is known that 161 if (isMigration_) {
129 // they don't work. 162 std::set<std::string> new_default_apps;
130 // TODO(rogerta): Do this check dynamically once the webstore can expose 163 for (base::DictionaryValue::key_iterator i = prefs->begin_keys();
131 // an API. See http://crbug.com/101357 164 i != prefs->end_keys(); ++i) {
132 const std::string& locale = g_browser_process->GetApplicationLocale(); 165 if (!IsOldDefaultApp(*i)) {
133 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; 166 new_default_apps.insert(*i);
134 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { 167 }
135 if (EndsWith(locale, unsupported_locales[i], false)) { 168 }
136 return false; 169 // Filter out the new default apps for migrating users.
170 for (std::set<std::string>::iterator it = new_default_apps.begin();
171 it != new_default_apps.end(); ++it) {
172 prefs->Remove(*it, NULL);
137 } 173 }
138 } 174 }
139 return true; 175
176 ExternalProviderImpl::SetPrefs(prefs);
140 } 177 }
141 178
142 } // namespace default_apps 179 } // namespace default_apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698