Change the way that default apps are installed to use a more standard
mechanism that already exists. Also uses a field trial object, with a one-
to-one correspondence between field trial group and brand code, so that metrics
can be collected and properly attributed to a given brand code. This allows
the metrics to be isolated by group and correlated with the brand code.
A follow CL will contain the changes to collect the metrics based on this
field trial.
BUG=None
TEST=Default apps should be installed for all profiles, not just the first
one, and not just on chrome first run, assuming the user is not in the
experimental group where default apps are not installed.
Review URL: http://codereview.chromium.org/8020009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102956 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/external_extension_provider_impl.cc b/chrome/browser/extensions/external_extension_provider_impl.cc
index 8819640..5073eb7 100644
--- a/chrome/browser/extensions/external_extension_provider_impl.cc
+++ b/chrome/browser/extensions/external_extension_provider_impl.cc
@@ -7,9 +7,12 @@
#include "base/file_path.h"
#include "base/logging.h"
#include "base/memory/linked_ptr.h"
+#include "base/metrics/field_trial.h"
#include "base/path_service.h"
#include "base/values.h"
#include "base/version.h"
+#include "chrome/browser/extensions/default_apps_trial.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/external_extension_provider_interface.h"
#include "chrome/browser/extensions/external_policy_extension_loader.h"
#include "chrome/browser/extensions/external_pref_extension_loader.h"
@@ -30,6 +33,45 @@
const char ExternalExtensionProviderImpl::kExternalUpdateUrl[] =
"external_update_url";
+class DefaultAppsProvider : public ExternalExtensionProviderImpl {
+ public:
+ DefaultAppsProvider(VisitorInterface* service, Profile* profile)
+ : ExternalExtensionProviderImpl(service,
+ new ExternalPrefExtensionLoader(chrome::DIR_DEFAULT_APPS,
+ ExternalPrefExtensionLoader::NONE),
+ Extension::EXTERNAL_PREF, Extension::INVALID),
+ profile_(profile) {
+ DCHECK(profile_);
+ }
+
+ // ExternalExtensionProviderImpl overrides:
+ virtual void ServiceShutdown() OVERRIDE;
+ virtual void VisitRegisteredExtension() const OVERRIDE;
+
+ private:
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultAppsProvider);
+};
+
+void DefaultAppsProvider::ServiceShutdown() {
+ profile_ = NULL;
+ ExternalExtensionProviderImpl::ServiceShutdown();
+}
+
+void DefaultAppsProvider::VisitRegisteredExtension() const {
+ // Don't install default apps if the profile already has apps installed.
+ if (profile_) {
+ ExtensionService* extension_service = profile_->GetExtensionService();
+ if (extension_service && extension_service->HasApps()) {
+ service()->OnExternalProviderReady();
+ return;
+ }
+ }
+
+ ExternalExtensionProviderImpl::VisitRegisteredExtension();
+}
+
ExternalExtensionProviderImpl::ExternalExtensionProviderImpl(
VisitorInterface* service,
ExternalExtensionLoader* loader,
@@ -283,4 +325,16 @@
new ExternalPolicyExtensionLoader(profile),
Extension::INVALID,
Extension::EXTERNAL_POLICY_DOWNLOAD)));
+
+ // Install default apps, except for the experimental group of users that are
+ // to be excluded.
+ static bool install_apps = !base::FieldTrialList::TrialExists(
+ kDefaultAppsTrial_Name) || (base::FieldTrialList::Find(
+ kDefaultAppsTrial_Name)->group_name() !=
+ kDefaultAppsTrial_NoAppsGroup);
+ if (install_apps) {
+ provider_list->push_back(
+ linked_ptr<ExternalExtensionProviderInterface>(
+ new DefaultAppsProvider(service, profile)));
+ }
}