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

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: 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 static bool ShouldInstallInProfile(Profile* profile) {
21 // We decide to install or not install default apps based on the following 21 // We decide to install or not install default apps based on the following
22 // criteria, from highest priority to lowest priority: 22 // criteria, from highest priority to lowest priority:
23 // 23 //
24 // - If this instance of chrome is participating in the default apps 24 // - If this instance of chrome is participating in the default apps
25 // field trial, then install apps based on the group. 25 // field trial, then install apps based on the group.
26 // - The command line option. Tests use this option to disable installation 26 // - The command line option. Tests use this option to disable installation
27 // of default apps in some cases. 27 // of default apps in some cases.
28 // - If the locale is not compatible with the defaults, don't install them. 28 // - 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 29 // - The kDefaultApps preferences value in the profile. This value is
32 // usually set in the master_preferences file. 30 // usually set in the master_preferences file.
33 bool install_apps = 31 bool install_apps =
34 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; 32 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install";
35 33
36 default_apps::InstallState state = 34 default_apps::InstallState state =
37 static_cast<default_apps::InstallState>(profile->GetPrefs()->GetInteger( 35 static_cast<default_apps::InstallState>(profile->GetPrefs()->GetInteger(
38 prefs::kDefaultAppsInstallState)); 36 prefs::kDefaultAppsInstallState));
39 switch (state) { 37 switch (state) {
40 case default_apps::kUnknown: { 38 case default_apps::kUnknown: {
41 // This is the first time the default apps feature runs on this profile. 39 // This is the first time the default apps feature runs on this profile.
42 // Determine if we want to install them or not. 40 // Determine if we want to install them or not.
43 chrome::VersionInfo version_info; 41 chrome::VersionInfo version_info;
44 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str())) 42 if (!profile->WasCreatedByVersionOrLater(version_info.Version().c_str()))
45 install_apps = false; 43 install_apps = false;
46 break; 44 break;
47 } 45 }
46
48 case default_apps::kAlwaysProvideDefaultApps: 47 case default_apps::kAlwaysProvideDefaultApps:
Mihai Parparita -not on Chrome 2012/08/08 00:22:42 It seems like in this case you'll want to migrate
Gaurav 2012/08/10 23:06:55 install_apps becomes true in most cases from the k
49 install_apps = true; 48 case default_apps::kAlreadyInstalledDefaultApps:
50 break;
51 case default_apps::kNeverProvideDefaultApps: 49 case default_apps::kNeverProvideDefaultApps:
52 install_apps = false; 50 install_apps = false;
53 break; 51 break;
54 default: 52 default:
55 NOTREACHED(); 53 NOTREACHED();
56 } 54 }
57 55
58 if (install_apps) { 56 if (install_apps) {
59 // Don't bother installing default apps in locales where it is known that 57 // Don't bother installing default apps in locales where it is known that
60 // they don't work. 58 // they don't work.
61 // TODO(rogerta): Do this check dynamically once the webstore can expose 59 // TODO(rogerta): Do this check dynamically once the webstore can expose
62 // an API. See http://crbug.com/101357 60 // an API. See http://crbug.com/101357
63 const std::string& locale = g_browser_process->GetApplicationLocale(); 61 const std::string& locale = g_browser_process->GetApplicationLocale();
64 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; 62 static const char* unsupported_locales[] = {"CN", "TR", "IR"};
65 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { 63 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) {
66 if (EndsWith(locale, unsupported_locales[i], false)) { 64 if (EndsWith(locale, unsupported_locales[i], false)) {
67 install_apps = false; 65 install_apps = false;
68 break; 66 break;
69 } 67 }
70 } 68 }
71 } 69 }
72 70
73 if (CommandLine::ForCurrentProcess()->HasSwitch( 71 if (CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kDisableDefaultApps)) { 72 switches::kDisableDefaultApps)) {
75 install_apps = false; 73 install_apps = false;
76 } 74 }
77 75
78 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) { 76 if (base::FieldTrialList::TrialExists(kDefaultAppsTrialName)) {
79 install_apps = base::FieldTrialList::Find( 77 install_apps = base::FieldTrialList::Find(
Mihai Parparita -not on Chrome 2012/08/08 00:22:43 Is this how we end up with install_apps being true
80 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup; 78 kDefaultAppsTrialName)->group_name() != kDefaultAppsTrialNoAppsGroup;
81 } 79 }
82 80
83 // Save the state if needed. Once it is decided whether we are installing 81 // 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 82 // 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) { 83 if (state == default_apps::kUnknown) {
96 if (install_apps) { 84 if (install_apps) {
97 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, 85 profile->GetPrefs()->SetInteger(
98 default_apps::kAlwaysProvideDefaultApps); 86 prefs::kDefaultAppsInstallState,
87 default_apps::kAlreadyInstalledDefaultApps);
99 } else { 88 } else {
100 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, 89 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
101 default_apps::kNeverProvideDefaultApps); 90 default_apps::kNeverProvideDefaultApps);
102 } 91 }
103 } 92 }
104 93
105 return install_apps; 94 return install_apps;
106 } 95 }
107 96
108 namespace default_apps { 97 namespace default_apps {
(...skipping 20 matching lines...) Expand all
129 if (!profile_ || !ShouldInstallInProfile(profile_)) { 118 if (!profile_ || !ShouldInstallInProfile(profile_)) {
130 base::DictionaryValue* prefs = new base::DictionaryValue; 119 base::DictionaryValue* prefs = new base::DictionaryValue;
131 SetPrefs(prefs); 120 SetPrefs(prefs);
132 return; 121 return;
133 } 122 }
134 123
135 extensions::ExternalProviderImpl::VisitRegisteredExtension(); 124 extensions::ExternalProviderImpl::VisitRegisteredExtension();
136 } 125 }
137 126
138 } // namespace default_apps 127 } // namespace default_apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698