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

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

Powered by Google App Engine
This is Rietveld 408576698