| 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" | 7 #include "base/command_line.h" |
| 8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" | 10 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/search/hotword_service_factory.h" |
| 12 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 15 #include "components/signin/core/browser/signin_manager.h" | 16 #include "components/signin/core/browser/signin_manager.h" |
| 16 | 17 |
| 17 // TODO(thestig): Remove after extensions are disabled on mobile. | |
| 18 #if defined(ENABLE_EXTENSIONS) | |
| 19 #include "chrome/browser/search/hotword_service_factory.h" | |
| 20 #endif | |
| 21 | |
| 22 namespace { | 18 namespace { |
| 23 | 19 |
| 24 bool IsUserSignedin(Profile* profile) { | 20 bool IsUserSignedin(Profile* profile) { |
| 25 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); | 21 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); |
| 26 return signin && !signin->GetAuthenticatedUsername().empty(); | 22 return signin && !signin->GetAuthenticatedUsername().empty(); |
| 27 } | 23 } |
| 28 | 24 |
| 29 } // namespace | 25 } // namespace |
| 30 | 26 |
| 31 namespace extensions { | 27 namespace extensions { |
| 32 | 28 |
| 33 ExternalComponentLoader::ExternalComponentLoader(Profile* profile) | 29 ExternalComponentLoader::ExternalComponentLoader(Profile* profile) |
| 34 : profile_(profile) { | 30 : profile_(profile) { |
| 35 } | 31 } |
| 36 | 32 |
| 37 ExternalComponentLoader::~ExternalComponentLoader() {} | 33 ExternalComponentLoader::~ExternalComponentLoader() {} |
| 38 | 34 |
| 39 // static | 35 // static |
| 40 bool ExternalComponentLoader::IsModifiable( | 36 bool ExternalComponentLoader::IsModifiable(const Extension* extension) { |
| 41 const extensions::Extension* extension) { | 37 if (extension->location() == Manifest::EXTERNAL_COMPONENT) { |
| 42 if (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT) { | |
| 43 static const char* enhanced_extension_hashes[] = { | 38 static const char* enhanced_extension_hashes[] = { |
| 44 "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900 | 39 "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900 |
| 45 "D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444 | 40 "D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444 |
| 46 "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562 | 41 "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562 |
| 47 }; | 42 }; |
| 48 std::string hash = base::SHA1HashString(extension->id()); | 43 std::string hash = base::SHA1HashString(extension->id()); |
| 49 hash = base::HexEncode(hash.c_str(), hash.length()); | 44 hash = base::HexEncode(hash.c_str(), hash.length()); |
| 50 for (size_t i = 0; i < arraysize(enhanced_extension_hashes); i++) | 45 for (size_t i = 0; i < arraysize(enhanced_extension_hashes); i++) |
| 51 if (hash == enhanced_extension_hashes[i]) | 46 if (hash == enhanced_extension_hashes[i]) |
| 52 return true; | 47 return true; |
| 53 } | 48 } |
| 54 return false; | 49 return false; |
| 55 } | 50 } |
| 56 | 51 |
| 57 void ExternalComponentLoader::StartLoading() { | 52 void ExternalComponentLoader::StartLoading() { |
| 58 prefs_.reset(new base::DictionaryValue()); | 53 prefs_.reset(new base::DictionaryValue()); |
| 59 std::string appId = extension_misc::kInAppPaymentsSupportAppId; | 54 std::string appId = extension_misc::kInAppPaymentsSupportAppId; |
| 60 prefs_->SetString(appId + ".external_update_url", | 55 prefs_->SetString(appId + ".external_update_url", |
| 61 extension_urls::GetWebstoreUpdateUrl().spec()); | 56 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 62 | 57 |
| 63 #if defined(ENABLE_EXTENSIONS) | |
| 64 if (HotwordServiceFactory::IsHotwordAllowed(profile_)) { | 58 if (HotwordServiceFactory::IsHotwordAllowed(profile_)) { |
| 65 std::string hotwordId = extension_misc::kHotwordExtensionId; | 59 std::string hotwordId = extension_misc::kHotwordExtensionId; |
| 66 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 60 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 67 // TODO(amistry): Load the hotword shared module when enabling built-in | 61 // TODO(amistry): Load the hotword shared module when enabling built-in |
| 68 // hotword detection. | 62 // hotword detection. |
| 69 if (!command_line->HasSwitch(switches::kEnableExperimentalHotwording)) { | 63 if (!command_line->HasSwitch(switches::kEnableExperimentalHotwording)) { |
| 70 prefs_->SetString(hotwordId + ".external_update_url", | 64 prefs_->SetString(hotwordId + ".external_update_url", |
| 71 extension_urls::GetWebstoreUpdateUrl().spec()); | 65 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 72 } | 66 } |
| 73 } | 67 } |
| 74 #endif | |
| 75 | 68 |
| 76 UpdateBookmarksExperimentState( | 69 UpdateBookmarksExperimentState( |
| 77 profile_->GetPrefs(), | 70 profile_->GetPrefs(), |
| 78 g_browser_process->local_state(), | 71 g_browser_process->local_state(), |
| 79 IsUserSignedin(profile_), | 72 IsUserSignedin(profile_), |
| 80 BOOKMARKS_EXPERIMENT_ENABLED_FROM_SYNC_UNKNOWN); | 73 BOOKMARKS_EXPERIMENT_ENABLED_FROM_SYNC_UNKNOWN); |
| 81 std::string ext_id; | 74 std::string ext_id; |
| 82 if (GetBookmarksExperimentExtensionID(profile_->GetPrefs(), &ext_id) && | 75 if (GetBookmarksExperimentExtensionID(profile_->GetPrefs(), &ext_id) && |
| 83 !ext_id.empty()) { | 76 !ext_id.empty()) { |
| 84 prefs_->SetString(ext_id + ".external_update_url", | 77 prefs_->SetString(ext_id + ".external_update_url", |
| 85 extension_urls::GetWebstoreUpdateUrl().spec()); | 78 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 86 } | 79 } |
| 87 | 80 |
| 88 LoadFinished(); | 81 LoadFinished(); |
| 89 } | 82 } |
| 90 | 83 |
| 91 } // namespace extensions | 84 } // namespace extensions |
| OLD | NEW |