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

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

Issue 8245018: Remove race condition when installing default apps into a new profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressing review comments, merge after sync Created 9 years, 2 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/default_apps_provider.h"
6
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/default_apps_trial.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h"
15 #include "ui/base/l10n/l10n_util.h"
16
17 void DefaultAppsProvider::RegisterUserPrefs(PrefService* prefs) {
18 prefs->RegisterIntegerPref(prefs::kDefaultAppsInstallState, kUnknown,
19 PrefService::UNSYNCABLE_PREF);
20 }
21
22 bool DefaultAppsProvider::ShouldInstallInProfile(Profile* profile) {
23 // We decide to install or not install default apps based on the following
24 // criteria, from highest priority to lowest priority:
25 //
26 // - If this instance of chrome is participating in the default apps
27 // field trial, then install apps based on the group.
28 // - The command line option. Tests use this option to disable installation
29 // of default apps in some cases.
30 // - If the locale is not compatible with the defaults, don't install them.
31 // - If the profile says to either always install or never install default
32 // apps, obey.
33 // - The kDefaultApps preferences value in the profile. This value is
34 // usually set in the master_preferences file.
35 bool install_apps =
36 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install";
37
38 InstallState state = static_cast<InstallState>(profile->GetPrefs()->
39 GetInteger(prefs::kDefaultAppsInstallState));
40 switch (state) {
41 case kUnknown: {
42 // We get here for either new profile, or profiles created before the
43 // default apps feature was implemented. In the former case, we always
44 // want to install default apps. In the latter case, we don't want to
45 // disturb a user that has already installed and possibly curated a list
46 // of favourite apps, so we only install if there are no apps in the
47 // profile. We can check for both these cases by looking to see if
48 // any apps already exist.
49 ExtensionService* extension_service = profile->GetExtensionService();
50 if (extension_service && extension_service->HasApps())
51 install_apps = false;
52 break;
53 }
54 case kAlwaysProvideDefaultApps:
55 install_apps = true;
56 break;
57 case kNeverProvideDefaultApps:
58 install_apps = false;
59 break;
60 default:
61 NOTREACHED();
62 }
63
64 if (install_apps) {
65 // Don't bother installing default apps in locales where its known that
Mihai Parparita -not on Chrome 2011/10/24 17:28:05 Typo (its -> it's).
Roger Tawa OOO till Jul 10th 2011/10/24 21:07:16 Done.
66 // they don't work.
67 // TODO(rogerta): Do this check dynamically once the webstore can expose
68 // an API. See http://crbug.com/101357
69 const std::string& locale = g_browser_process->GetApplicationLocale();
70 static const char* unsupported_locales[] = {"CN", "TR", "IR"};
71 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) {
72 if (EndsWith(locale, unsupported_locales[i], false)) {
Sam Kerner (Chrome) 2011/10/24 14:46:04 Is there a locale utility function that tests this
Roger Tawa OOO till Jul 10th 2011/10/24 15:35:36 There does not seem to be anything in l10_util.h t
73 install_apps = false;
74 break;
75 }
76 }
77 }
78
79 if (CommandLine::ForCurrentProcess()->HasSwitch(
80 switches::kDisableDefaultApps)) {
81 install_apps = false;
82 }
83
84 if (base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name)) {
85 install_apps = base::FieldTrialList::Find(
86 kDefaultAppsTrial_Name)->group_name() != kDefaultAppsTrial_NoAppsGroup;
87 }
88
89 // Save the state if needed.
90 if (state == kUnknown) {
91 if (install_apps) {
92 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
93 kAlwaysProvideDefaultApps);
94 } else {
95 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
96 kNeverProvideDefaultApps);
97 }
98 profile->GetPrefs()->ScheduleSavePersistentPrefs();
99 }
100
101 return install_apps;
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698