| 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 "app/app_paths.h" | 7 #include "app/app_paths.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 NOTREACHED() << "Invalid json data"; | 25 NOTREACHED() << "Invalid json data"; |
| 26 } else { | 26 } else { |
| 27 return static_cast<DictionaryValue*>(extensions); | 27 return static_cast<DictionaryValue*>(extensions); |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 return new DictionaryValue; | 30 return new DictionaryValue; |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 ExternalPrefExtensionLoader::ExternalPrefExtensionLoader() { | 35 ExternalPrefExtensionLoader::ExternalPrefExtensionLoader(int path_key) |
| 36 : path_key_(path_key) { |
| 36 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 37 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 37 } | 38 } |
| 38 | 39 |
| 40 const FilePath ExternalPrefExtensionLoader::GetBaseCrxFilePath() { |
| 41 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 42 |
| 43 FilePath external_file_path; |
| 44 CHECK(PathService::Get(path_key_, &external_file_path)); |
| 45 return external_file_path; |
| 46 } |
| 47 |
| 39 void ExternalPrefExtensionLoader::StartLoading() { | 48 void ExternalPrefExtensionLoader::StartLoading() { |
| 40 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 41 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
| 42 BrowserThread::FILE, FROM_HERE, | 51 BrowserThread::FILE, FROM_HERE, |
| 43 NewRunnableMethod( | 52 NewRunnableMethod( |
| 44 this, | 53 this, |
| 45 &ExternalPrefExtensionLoader::LoadOnFileThread)); | 54 &ExternalPrefExtensionLoader::LoadOnFileThread)); |
| 46 } | 55 } |
| 47 | 56 |
| 48 void ExternalPrefExtensionLoader::LoadOnFileThread() { | 57 void ExternalPrefExtensionLoader::LoadOnFileThread() { |
| 49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 58 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 59 |
| 50 FilePath json_file; | 60 FilePath json_file; |
| 51 PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &json_file); | 61 CHECK(PathService::Get(path_key_, &json_file)); |
| 52 json_file = json_file.Append(FILE_PATH_LITERAL("external_extensions.json")); | 62 json_file = json_file.Append(FILE_PATH_LITERAL("external_extensions.json")); |
| 63 |
| 53 scoped_ptr<DictionaryValue> prefs; | 64 scoped_ptr<DictionaryValue> prefs; |
| 54 | |
| 55 if (file_util::PathExists(json_file)) { | 65 if (file_util::PathExists(json_file)) { |
| 56 JSONFileValueSerializer serializer(json_file); | 66 JSONFileValueSerializer serializer(json_file); |
| 57 prefs.reset(ExtractPrefs(&serializer)); | 67 prefs.reset(ExtractPrefs(&serializer)); |
| 58 } else { | 68 } else { |
| 59 prefs.reset(new DictionaryValue()); | 69 prefs.reset(new DictionaryValue()); |
| 60 } | 70 } |
| 61 | 71 |
| 62 prefs_.reset(prefs.release()); | 72 prefs_.reset(prefs.release()); |
| 63 BrowserThread::PostTask( | 73 BrowserThread::PostTask( |
| 64 BrowserThread::UI, FROM_HERE, | 74 BrowserThread::UI, FROM_HERE, |
| 65 NewRunnableMethod( | 75 NewRunnableMethod( |
| 66 this, | 76 this, |
| 67 &ExternalPrefExtensionLoader::LoadFinished)); | 77 &ExternalPrefExtensionLoader::LoadFinished)); |
| 68 } | 78 } |
| 69 | 79 |
| 70 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader( | 80 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader( |
| 71 const std::string& json_data) { | 81 const std::string& json_data, |
| 82 const FilePath& fake_base_path) |
| 83 : fake_base_path_(fake_base_path) { |
| 72 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 84 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 73 JSONStringValueSerializer serializer(json_data); | 85 JSONStringValueSerializer serializer(json_data); |
| 74 testing_prefs_.reset(ExtractPrefs(&serializer)); | 86 testing_prefs_.reset(ExtractPrefs(&serializer)); |
| 75 } | 87 } |
| 76 | 88 |
| 77 void ExternalTestingExtensionLoader::StartLoading() { | 89 void ExternalTestingExtensionLoader::StartLoading() { |
| 78 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 90 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 79 prefs_.reset( | 91 prefs_.reset( |
| 80 static_cast<DictionaryValue*>(testing_prefs_->DeepCopy())); | 92 static_cast<DictionaryValue*>(testing_prefs_->DeepCopy())); |
| 81 LoadFinished(); | 93 LoadFinished(); |
| 82 } | 94 } |
| 95 |
| 96 const FilePath ExternalTestingExtensionLoader::GetBaseCrxFilePath() { |
| 97 return fake_base_path_; |
| 98 } |
| OLD | NEW |