| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/external_component_loader.h" | 5 #include "chrome/browser/extensions/external_component_loader.h" |
| 6 | 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" | 7 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" |
| 12 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/external_provider_impl.h" | |
| 14 #include "chrome/browser/search/hotword_service_factory.h" | 9 #include "chrome/browser/search/hotword_service_factory.h" |
| 15 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/common/extensions/extension_constants.h" | 11 #include "chrome/common/extensions/extension_constants.h" |
| 17 #include "chrome/common/pref_names.h" | 12 #include "components/signin/core/browser/signin_manager.h" |
| 18 #include "components/sync_driver/pref_names.h" | 13 |
| 19 #include "components/user_prefs/pref_registry_syncable.h" | 14 namespace { |
| 20 #include "content/public/browser/browser_thread.h" | 15 |
| 16 bool IsUserSignedin(Profile* profile) { |
| 17 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); |
| 18 return signin && !signin->GetAuthenticatedUsername().empty(); |
| 19 } |
| 20 |
| 21 } // namespace |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 | 24 |
| 24 ExternalComponentLoader::ExternalComponentLoader(Profile* profile) | 25 ExternalComponentLoader::ExternalComponentLoader(Profile* profile) |
| 25 : profile_(profile) { | 26 : profile_(profile) { |
| 26 } | 27 } |
| 27 | 28 |
| 28 ExternalComponentLoader::~ExternalComponentLoader() {} | 29 ExternalComponentLoader::~ExternalComponentLoader() {} |
| 29 | 30 |
| 30 void ExternalComponentLoader::StartLoading() { | 31 void ExternalComponentLoader::StartLoading() { |
| 31 prefs_.reset(new base::DictionaryValue()); | 32 prefs_.reset(new base::DictionaryValue()); |
| 32 std::string appId = extension_misc::kInAppPaymentsSupportAppId; | 33 std::string appId = extension_misc::kInAppPaymentsSupportAppId; |
| 33 prefs_->SetString(appId + ".external_update_url", | 34 prefs_->SetString(appId + ".external_update_url", |
| 34 extension_urls::GetWebstoreUpdateUrl().spec()); | 35 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 35 | 36 |
| 36 if (HotwordServiceFactory::IsHotwordAllowed(profile_)) { | 37 if (HotwordServiceFactory::IsHotwordAllowed(profile_)) { |
| 37 std::string hotwordId = extension_misc::kHotwordExtensionId; | 38 std::string hotwordId = extension_misc::kHotwordExtensionId; |
| 38 prefs_->SetString(hotwordId + ".external_update_url", | 39 prefs_->SetString(hotwordId + ".external_update_url", |
| 39 extension_urls::GetWebstoreUpdateUrl().spec()); | 40 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 40 } | 41 } |
| 41 | 42 |
| 42 BookmarksExperimentState bookmarks_experiment_state_before = | 43 UpdateBookmarksExperimentState(profile_->GetPrefs(), |
| 43 static_cast<BookmarksExperimentState>(profile_->GetPrefs()->GetInteger( | 44 g_browser_process->local_state(), |
| 44 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled)); | 45 IsUserSignedin(profile_)); |
| 45 if (bookmarks_experiment_state_before == kBookmarksExperimentEnabled) { | 46 std::string ext_id; |
| 46 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0". | 47 if (GetBookmarksExperimentExtensionID(profile_->GetPrefs(), &ext_id) && |
| 47 // "0" - user opted out. | 48 !ext_id.empty()) { |
| 48 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 49 prefs_->SetString(ext_id + ".external_update_url", |
| 49 switches::kEnhancedBookmarksExperiment) != "0") { | 50 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 50 // Experiment enabled. | |
| 51 std::string ext_id = profile_->GetPrefs()->GetString( | |
| 52 sync_driver::prefs::kEnhancedBookmarksExtensionId); | |
| 53 if (!ext_id.empty()) { | |
| 54 prefs_->SetString(ext_id + ".external_update_url", | |
| 55 extension_urls::GetWebstoreUpdateUrl().spec()); | |
| 56 } | |
| 57 } else { | |
| 58 // Experiment enabled but user opted out. | |
| 59 profile_->GetPrefs()->SetInteger( | |
| 60 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled, | |
| 61 kBookmarksExperimentEnabledUserOptOut); | |
| 62 } | |
| 63 } else if (bookmarks_experiment_state_before == | |
| 64 kBookmarksExperimentEnabledUserOptOut) { | |
| 65 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 66 switches::kEnhancedBookmarksExperiment) != "0") { | |
| 67 // User opted in again. | |
| 68 profile_->GetPrefs()->SetInteger( | |
| 69 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled, | |
| 70 kBookmarksExperimentEnabled); | |
| 71 std::string ext_id = profile_->GetPrefs()->GetString( | |
| 72 sync_driver::prefs::kEnhancedBookmarksExtensionId); | |
| 73 if (!ext_id.empty()) { | |
| 74 prefs_->SetString(ext_id + ".external_update_url", | |
| 75 extension_urls::GetWebstoreUpdateUrl().spec()); | |
| 76 } | |
| 77 } | |
| 78 } else { | |
| 79 // Experiment disabled. | |
| 80 profile_->GetPrefs()->ClearPref( | |
| 81 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled); | |
| 82 profile_->GetPrefs()->ClearPref( | |
| 83 sync_driver::prefs::kEnhancedBookmarksExtensionId); | |
| 84 } | |
| 85 BookmarksExperimentState bookmarks_experiment_state = | |
| 86 static_cast<BookmarksExperimentState>(profile_->GetPrefs()->GetInteger( | |
| 87 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled)); | |
| 88 if (bookmarks_experiment_state_before != bookmarks_experiment_state) { | |
| 89 UpdateBookmarksExperiment(g_browser_process->local_state(), | |
| 90 bookmarks_experiment_state); | |
| 91 } | 51 } |
| 92 | 52 |
| 93 LoadFinished(); | 53 LoadFinished(); |
| 94 } | 54 } |
| 95 | 55 |
| 96 } // namespace extensions | 56 } // namespace extensions |
| OLD | NEW |