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