Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_pref_extension_loader.h" | 5 #include "chrome/browser/extensions/external_pref_extension_loader.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "chrome/common/chrome_paths.h" | |
| 11 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
| 12 #include "content/common/json_value_serializer.h" | 14 #include "content/common/json_value_serializer.h" |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 // Caller takes ownership of the returned dictionary. | 18 // Caller takes ownership of the returned dictionary. |
| 17 DictionaryValue* ExtractPrefs(const FilePath& path, | 19 DictionaryValue* ExtractPrefs(const FilePath& path, |
| 18 base::ValueSerializer* serializer) { | 20 base::ValueSerializer* serializer) { |
| 19 std::string error_msg; | 21 std::string error_msg; |
| 20 Value* extensions = serializer->Deserialize(NULL, &error_msg); | 22 Value* extensions = serializer->Deserialize(NULL, &error_msg); |
| 21 if (!extensions) { | 23 if (!extensions) { |
| 22 LOG(WARNING) << "Unable to deserialize json data: " << error_msg | 24 LOG(WARNING) << "Unable to deserialize json data: " << error_msg |
| 23 << " In file " << path.value() << " ."; | 25 << " In file " << path.value() << " ."; |
| 24 } else { | 26 } else { |
| 25 if (!extensions->IsType(Value::TYPE_DICTIONARY)) { | 27 if (!extensions->IsType(Value::TYPE_DICTIONARY)) { |
| 26 LOG(WARNING) << "Expected a JSON dictionary in file " | 28 LOG(WARNING) << "Expected a JSON dictionary in file " |
| 27 << path.value() << " ."; | 29 << path.value() << " ."; |
| 28 } else { | 30 } else { |
| 29 return static_cast<DictionaryValue*>(extensions); | 31 return static_cast<DictionaryValue*>(extensions); |
| 30 } | 32 } |
| 31 } | 33 } |
| 32 return new DictionaryValue; | 34 return new DictionaryValue; |
| 33 } | 35 } |
| 34 | 36 |
| 35 } // namespace | 37 } // namespace |
| 36 | 38 |
| 37 ExternalPrefExtensionLoader::ExternalPrefExtensionLoader(int base_path_key) | 39 ExternalPrefExtensionLoader::ExternalPrefExtensionLoader(int base_path_key, |
| 38 : base_path_key_(base_path_key) { | 40 Options options) |
| 41 : base_path_key_(base_path_key), | |
| 42 options_(options){ | |
| 39 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 40 } | 44 } |
| 41 | 45 |
| 42 const FilePath ExternalPrefExtensionLoader::GetBaseCrxFilePath() { | 46 const FilePath ExternalPrefExtensionLoader::GetBaseCrxFilePath() { |
| 43 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 44 | 48 |
| 45 // |base_path_| was set in LoadOnFileThread(). | 49 // |base_path_| was set in LoadOnFileThread(). |
| 46 return base_path_; | 50 return base_path_; |
| 47 } | 51 } |
| 48 | 52 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 65 // OS developer builds and linux install packages. | 69 // OS developer builds and linux install packages. |
| 66 // Tracked as crbug.com/70402 . | 70 // Tracked as crbug.com/70402 . |
| 67 | 71 |
| 68 scoped_ptr<DictionaryValue> prefs; | 72 scoped_ptr<DictionaryValue> prefs; |
| 69 if (PathService::Get(base_path_key_, &base_path_)) { | 73 if (PathService::Get(base_path_key_, &base_path_)) { |
| 70 FilePath json_file; | 74 FilePath json_file; |
| 71 json_file = | 75 json_file = |
| 72 base_path_.Append(FILE_PATH_LITERAL("external_extensions.json")); | 76 base_path_.Append(FILE_PATH_LITERAL("external_extensions.json")); |
| 73 | 77 |
| 74 if (file_util::PathExists(json_file)) { | 78 if (file_util::PathExists(json_file)) { |
| 75 JSONFileValueSerializer serializer(json_file); | 79 if (IsOptionSet(ENSURE_PATH_CONTROLLED_BY_ADMIN) && |
| 76 prefs.reset(ExtractPrefs(json_file, &serializer)); | 80 !file_util::IsPathControlledByAdmin(json_file)) { |
| 81 LOG(ERROR) << "Can not read external extensions source. The file " | |
| 82 << json_file.value() << " and every directory in its path " | |
| 83 << "must be owned by root, and not be writable by all " | |
| 84 << "users. This restriction prevents unprivleged users " | |
| 85 << "from making chrome install extensions on other users' " | |
| 86 << "accounts."; | |
| 87 } else { | |
| 88 JSONFileValueSerializer serializer(json_file); | |
| 89 prefs.reset(ExtractPrefs(json_file, &serializer)); | |
| 90 } | |
| 77 } | 91 } |
| 78 } | 92 } |
| 79 | 93 |
| 80 if (!prefs.get()) | 94 if (!prefs.get()) |
| 81 prefs.reset(new DictionaryValue()); | 95 prefs.reset(new DictionaryValue()); |
| 82 | 96 |
| 83 prefs_.reset(prefs.release()); | 97 prefs_.reset(prefs.release()); |
| 84 | 98 |
| 99 // We want to deprecate the external extensions file inside the app | |
| 100 // bundle on mac os. Use a histogram to see how many extensions | |
| 101 // are installed in this way. We can use this data to measure the | |
| 102 // effectiveness of asking developers to use the new path, or any | |
| 103 // automatic migration methods we implement. | |
|
TVL
2011/08/25 14:07:28
fyi - if folks were modifying the bundle link this
Sam Kerner (Chrome)
2011/08/25 14:29:58
Mark mentioned that in the bug. In order to figur
| |
| 104 if (base_path_key_ == chrome::DIR_DEPRICATED_EXTERNAL_EXTENSIONS) { | |
| 105 UMA_HISTOGRAM_COUNTS_100("Extensions.DepricatedExternalJsonCount", | |
| 106 prefs_->size()); | |
|
asargent_no_longer_on_chrome
2011/08/24 22:55:09
Optional suggestion - do we want to also measure t
Sam Kerner (Chrome)
2011/08/25 14:04:37
Good point. Done.
| |
| 107 } | |
| 108 | |
| 85 // If we have any records to process, then we must have | 109 // If we have any records to process, then we must have |
| 86 // read the .json file. If we read the .json file, then | 110 // read the .json file. If we read the .json file, then |
| 87 // we were should have set |base_path_|. | 111 // we were should have set |base_path_|. |
| 88 if (!prefs_->empty()) | 112 if (!prefs_->empty()) |
| 89 CHECK(!base_path_.empty()); | 113 CHECK(!base_path_.empty()); |
| 90 | 114 |
| 91 BrowserThread::PostTask( | 115 BrowserThread::PostTask( |
| 92 BrowserThread::UI, FROM_HERE, | 116 BrowserThread::UI, FROM_HERE, |
| 93 NewRunnableMethod( | 117 NewRunnableMethod( |
| 94 this, | 118 this, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 109 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 133 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 110 prefs_.reset(testing_prefs_->DeepCopy()); | 134 prefs_.reset(testing_prefs_->DeepCopy()); |
| 111 LoadFinished(); | 135 LoadFinished(); |
| 112 } | 136 } |
| 113 | 137 |
| 114 ExternalTestingExtensionLoader::~ExternalTestingExtensionLoader() {} | 138 ExternalTestingExtensionLoader::~ExternalTestingExtensionLoader() {} |
| 115 | 139 |
| 116 const FilePath ExternalTestingExtensionLoader::GetBaseCrxFilePath() { | 140 const FilePath ExternalTestingExtensionLoader::GetBaseCrxFilePath() { |
| 117 return fake_base_path_; | 141 return fake_base_path_; |
| 118 } | 142 } |
| OLD | NEW |