summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/external_component_loader.cc
blob: 6ccfec488c45f04a59bde31ab7db51f1e8ea2661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/external_component_loader.h"

#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/values.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "components/variations/variations_associated_data.h"
#include "extensions/common/features/feature.h"
#include "extensions/common/features/feature_provider.h"

namespace extensions {

const char kFieldTrialName[] = "EnhancedBookmarks";

ExternalComponentLoader::ExternalComponentLoader() {}

ExternalComponentLoader::~ExternalComponentLoader() {}

// This function will be removed after experiment goes to all users or go away.
bool ExternalComponentLoader::IsEnhancedBookmarksExperimentEnabled() {
  const char kFieldTrialDefaultGroupName[] = "Default";
  std::string field_trial_group_name =
      base::FieldTrialList::FindFullName(kFieldTrialName);
  if (field_trial_group_name.empty() ||
      field_trial_group_name == kFieldTrialDefaultGroupName) {
    return false;
  }
  std::string app_id =
      chrome_variations::GetVariationParamValue(kFieldTrialName, "id");
  FeatureProvider* feature_provider = FeatureProvider::GetPermissionFeatures();
  Feature* feature = feature_provider->GetFeature("metricsPrivate");
  return (feature && feature->IsIdInWhitelist(app_id));
}

void ExternalComponentLoader::StartLoading() {
  prefs_.reset(new base::DictionaryValue());
  std::string appId = extension_misc::kInAppPaymentsSupportAppId;
  prefs_->SetString(appId + ".external_update_url",
                    extension_urls::GetWebstoreUpdateUrl().spec());

  if (IsEnhancedBookmarksExperimentEnabled() &&
      (CommandLine::ForCurrentProcess()->
          GetSwitchValueASCII(switches::kEnableEnhancedBookmarks) != "0")) {
    std::string app_id =
        chrome_variations::GetVariationParamValue(kFieldTrialName, "id");
    prefs_->SetString(app_id + ".external_update_url",
                      extension_urls::GetWebstoreUpdateUrl().spec());
  }
  LoadFinished();
}

}  // namespace extensions