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

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

Issue 10834191: new implementation of default apps (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fixed broken test Created 8 years, 4 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 static bool ShouldInstallInProfile(Profile* profile) { 20 namespace default_apps {
21
22 bool ShouldInstallInProfile(Profile* profile) {
21 // We decide to install or not install default apps based on the following 23 // We decide to install or not install default apps based on the following
22 // criteria, from highest priority to lowest priority: 24 // criteria, from highest priority to lowest priority:
23 // 25 //
24 // - If this instance of chrome is participating in the default apps 26 // - If this instance of chrome is participating in the default apps
25 // field trial, then install apps based on the group. 27 // field trial, then install apps based on the group.
26 // - The command line option. Tests use this option to disable installation 28 // - The command line option. Tests use this option to disable installation
27 // of default apps in some cases. 29 // of default apps in some cases.
28 // - If the locale is not compatible with the defaults, don't install them. 30 // - If the locale is not compatible with the defaults, don't install them.
29 // - If the profile says to either always install or never install default
30 // apps, obey.
31 // - The kDefaultApps preferences value in the profile. This value is 31 // - The kDefaultApps preferences value in the profile. This value is
32 // usually set in the master_preferences file. 32 // usually set in the master_preferences file.
33 bool install_apps = 33 bool install_apps =
34 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; 34 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install";
35 35
36 default_apps::InstallState state = 36 default_apps::InstallState state =
37 static_cast<default_apps::InstallState>(profile->GetPrefs()->GetInteger( 37 static_cast<default_apps::InstallState>(profile->GetPrefs()->GetInteger(
38 prefs::kDefaultAppsInstallState)); 38 prefs::kDefaultAppsInstallState));
39
40 // migrate old default_apps. This will install them once changing the location
Mihai Parparita -not on Chrome 2012/08/15 00:32:13 - Capitalize "Migrate" - Remove the underscore in
41 // from external to internal.
42 if (state == default_apps::kAlwaysProvideDefaultApps) {
43 state = default_apps::kUnknown;
Mihai Parparita -not on Chrome 2012/08/15 00:32:13 I think this will mean that users will lose their
44 }
45
39 switch (state) { 46 switch (state) {
40 case default_apps::kUnknown: { 47 case default_apps::kUnknown: {
41 // This is the first time the default apps feature runs on this profile. 48 // This is the first time the default apps feature runs on this profile.
42 // Determine if we want to install them or not. 49 // Determine if we want to install them or not.
43 chrome::VersionInfo version_info; 50 chrome::VersionInfo version_info;
44 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str())) 51 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str()))
45 install_apps = false; 52 install_apps = false;
46 break; 53 break;
47 } 54 }
48 case default_apps::kAlwaysProvideDefaultApps: 55
49 install_apps = true; 56 case default_apps::kAlreadyInstalledDefaultApps:
50 break;
51 case default_apps::kNeverProvideDefaultApps: 57 case default_apps::kNeverProvideDefaultApps:
52 install_apps = false; 58 install_apps = false;
53 break; 59 break;
54 default: 60 default:
55 NOTREACHED(); 61 NOTREACHED();
56 } 62 }
57 63
58 if (install_apps) { 64 if (install_apps && !isLocaleSupported()) {
59 // Don't bother installing default apps in locales where it is known that 65 install_apps = false;
60 // they don't work.
61 // TODO(rogerta): Do this check dynamically once the webstore can expose
62 // an API. See http://crbug.com/101357
63 const std::string& locale = g_browser_process->GetApplicationLocale();
64 static const char* unsupported_locales[] = {"CN", "TR", "IR"};
65 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) {
66 if (EndsWith(locale, unsupported_locales[i], false)) {
67 install_apps = false;
68 break;
69 }
70 }
71 } 66 }
72 67
73 if (CommandLine::ForCurrentProcess()->HasSwitch( 68 if (CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kDisableDefaultApps)) { 69 switches::kDisableDefaultApps)) {
75 install_apps = false; 70 install_apps = false;
76 } 71 }
77 72
78 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) { 73 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) {
79 install_apps = base::FieldTrialList::Find( 74 install_apps = base::FieldTrialList::Find(
80 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup; 75 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup;
81 } 76 }
82 77
83 // Save the state if needed. Once it is decided whether we are installing 78 // Default apps are only installed on profile creation or a new chrome
84 // default apps or not, we want to always respond with same value. Therefore 79 // download.
85 // on first run of this feature (i.e. the current state is kUnknown) the
86 // state is updated to remember the choice that was made at this time. The
87 // next time chrome runs it will use the same decision.
88 //
89 // The reason for responding with the same value is that once an external
90 // extenson provider has provided apps for a given profile, it must continue
91 // to provide those extensions on each subsequent run. Otherwise the
92 // extension manager will automatically uninstall the apps. The extension
93 // manager is smart enough to know not to reinstall the apps on all
94 // subsequent runs of chrome.
95 if (state == default_apps::kUnknown) { 80 if (state == default_apps::kUnknown) {
96 if (install_apps) { 81 if (install_apps) {
97 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, 82 profile->GetPrefs()->SetInteger(
98 default_apps::kAlwaysProvideDefaultApps); 83 prefs::kDefaultAppsInstallState,
84 default_apps::kAlreadyInstalledDefaultApps);
99 } else { 85 } else {
100 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, 86 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
101 default_apps::kNeverProvideDefaultApps); 87 default_apps::kNeverProvideDefaultApps);
102 } 88 }
103 } 89 }
104 90
105 return install_apps; 91 return install_apps;
106 } 92 }
107 93
108 namespace default_apps {
109
110 void RegisterUserPrefs(PrefService* prefs) { 94 void RegisterUserPrefs(PrefService* prefs) {
111 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown, 95 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown,
112 PrefService::UNSYNCABLE_PREF); 96 PrefService::UNSYNCABLE_PREF);
113 } 97 }
114 98
115 Provider::Provider(Profile* profile, 99 Provider::Provider(Profile* profile,
116 VisitorInterface* service, 100 VisitorInterface* service,
117 extensions::ExternalLoader* loader, 101 extensions::ExternalLoader* loader,
118 extensions::Extension::Location crx_location, 102 extensions::Extension::Location crx_location,
119 extensions::Extension::Location download_location, 103 extensions::Extension::Location download_location,
120 int creation_flags) 104 int creation_flags)
121 : extensions::ExternalProviderImpl(service, loader, crx_location, 105 : extensions::ExternalProviderImpl(service, loader, crx_location,
122 download_location, creation_flags), 106 download_location, creation_flags),
123 profile_(profile) { 107 profile_(profile) {
124 DCHECK(profile); 108 DCHECK(profile);
125 set_auto_acknowledge(true); 109 set_auto_acknowledge(true);
126 } 110 }
127 111
128 void Provider::VisitRegisteredExtension() { 112 void Provider::VisitRegisteredExtension() {
129 if (!profile_ || !ShouldInstallInProfile(profile_)) { 113 if (!profile_ || !ShouldInstallInProfile(profile_)) {
130 base::DictionaryValue* prefs = new base::DictionaryValue; 114 base::DictionaryValue* prefs = new base::DictionaryValue;
131 SetPrefs(prefs); 115 SetPrefs(prefs);
132 return; 116 return;
133 } 117 }
134 118
135 extensions::ExternalProviderImpl::VisitRegisteredExtension(); 119 extensions::ExternalProviderImpl::VisitRegisteredExtension();
136 } 120 }
137 121
122 bool isLocaleSupported() {
123 // Don't bother installing default apps in locales where it is known that
Mihai Parparita -not on Chrome 2012/08/15 00:32:13 Intended one too many times.
124 // they don't work.
125 // TODO(rogerta): Do this check dynamically once the webstore can expose
126 // an API. See http://crbug.com/101357
127 const std::string& locale = g_browser_process->GetApplicationLocale();
128 static const char* unsupported_locales[] = {"CN", "TR", "IR"};
129 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) {
130 if (EndsWith(locale, unsupported_locales[i], false)) {
131 return false;
132 }
133 }
134 return true;
135 }
136
138 } // namespace default_apps 137 } // namespace default_apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698