Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / external_component_loader.cc
1 // Copyright (c) 2013 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/external_component_loader.h"
6
7 #include "base/command_line.h"
8 #include "base/prefs/pref_change_registrar.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/values.h"
11 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/external_provider_impl.h"
14 #include "chrome/browser/search/hotword_service_factory.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/extension_constants.h"
17 #include "chrome/common/pref_names.h"
18 #include "components/user_prefs/pref_registry_syncable.h"
19 #include "content/public/browser/browser_thread.h"
20
21 namespace extensions {
22
23 ExternalComponentLoader::ExternalComponentLoader(Profile* profile)
24     : profile_(profile) {
25 }
26
27 ExternalComponentLoader::~ExternalComponentLoader() {}
28
29 void ExternalComponentLoader::StartLoading() {
30   prefs_.reset(new base::DictionaryValue());
31   std::string appId = extension_misc::kInAppPaymentsSupportAppId;
32   prefs_->SetString(appId + ".external_update_url",
33                     extension_urls::GetWebstoreUpdateUrl().spec());
34
35   if (HotwordServiceFactory::IsHotwordAllowed(profile_)) {
36     std::string hotwordId = extension_misc::kHotwordExtensionId;
37     prefs_->SetString(hotwordId + ".external_update_url",
38                       extension_urls::GetWebstoreUpdateUrl().spec());
39   }
40
41   if (CommandLine::ForCurrentProcess()->
42           GetSwitchValueASCII(switches::kEnableEnhancedBookmarks) != "0") {
43     std::string ext_id;
44     if (profile_->GetPrefs()->GetBoolean(
45             prefs::kEnhancedBookmarksExperimentEnabled)) {
46       ext_id =
47           profile_->GetPrefs()->GetString(prefs::kEnhancedBookmarksExtensionId);
48     } else {
49       ext_id = GetEnhancedBookmarksExtensionIdFromFinch();
50     }
51     if (!ext_id.empty()) {
52       prefs_->SetString(ext_id + ".external_update_url",
53                         extension_urls::GetWebstoreUpdateUrl().spec());
54     }
55   } else {
56     profile_->GetPrefs()->ClearPref(prefs::kEnhancedBookmarksExperimentEnabled);
57     profile_->GetPrefs()->ClearPref(prefs::kEnhancedBookmarksExtensionId);
58   }
59   LoadFinished();
60 }
61
62 }  // namespace extensions