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 base_path_key) |
| 36 : base_path_key_(base_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 // LoadOnFileThread() should set |external_file_path_| to a non-empty |
| 44 // path. This function should not be called until after LoadOnFileThread() |
| 45 // is complete. |
| 46 CHECK(!base_path_.empty()); |
| 47 |
| 48 return base_path_; |
| 49 } |
| 50 |
39 void ExternalPrefExtensionLoader::StartLoading() { | 51 void ExternalPrefExtensionLoader::StartLoading() { |
40 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
41 BrowserThread::PostTask( | 53 BrowserThread::PostTask( |
42 BrowserThread::FILE, FROM_HERE, | 54 BrowserThread::FILE, FROM_HERE, |
43 NewRunnableMethod( | 55 NewRunnableMethod( |
44 this, | 56 this, |
45 &ExternalPrefExtensionLoader::LoadOnFileThread)); | 57 &ExternalPrefExtensionLoader::LoadOnFileThread)); |
46 } | 58 } |
47 | 59 |
48 void ExternalPrefExtensionLoader::LoadOnFileThread() { | 60 void ExternalPrefExtensionLoader::LoadOnFileThread() { |
49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 61 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 62 |
| 63 CHECK(PathService::Get(base_path_key_, &base_path_)); |
| 64 |
50 FilePath json_file; | 65 FilePath json_file; |
51 PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &json_file); | 66 json_file = base_path_.Append(FILE_PATH_LITERAL("external_extensions.json")); |
52 json_file = json_file.Append(FILE_PATH_LITERAL("external_extensions.json")); | 67 |
53 scoped_ptr<DictionaryValue> prefs; | 68 scoped_ptr<DictionaryValue> prefs; |
54 | |
55 if (file_util::PathExists(json_file)) { | 69 if (file_util::PathExists(json_file)) { |
56 JSONFileValueSerializer serializer(json_file); | 70 JSONFileValueSerializer serializer(json_file); |
57 prefs.reset(ExtractPrefs(&serializer)); | 71 prefs.reset(ExtractPrefs(&serializer)); |
58 } else { | 72 } else { |
59 prefs.reset(new DictionaryValue()); | 73 prefs.reset(new DictionaryValue()); |
60 } | 74 } |
61 | 75 |
62 prefs_.reset(prefs.release()); | 76 prefs_.reset(prefs.release()); |
63 BrowserThread::PostTask( | 77 BrowserThread::PostTask( |
64 BrowserThread::UI, FROM_HERE, | 78 BrowserThread::UI, FROM_HERE, |
65 NewRunnableMethod( | 79 NewRunnableMethod( |
66 this, | 80 this, |
67 &ExternalPrefExtensionLoader::LoadFinished)); | 81 &ExternalPrefExtensionLoader::LoadFinished)); |
68 } | 82 } |
69 | 83 |
70 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader( | 84 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader( |
71 const std::string& json_data) { | 85 const std::string& json_data, |
| 86 const FilePath& fake_base_path) |
| 87 : fake_base_path_(fake_base_path) { |
72 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
73 JSONStringValueSerializer serializer(json_data); | 89 JSONStringValueSerializer serializer(json_data); |
74 testing_prefs_.reset(ExtractPrefs(&serializer)); | 90 testing_prefs_.reset(ExtractPrefs(&serializer)); |
75 } | 91 } |
76 | 92 |
77 void ExternalTestingExtensionLoader::StartLoading() { | 93 void ExternalTestingExtensionLoader::StartLoading() { |
78 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
79 prefs_.reset(testing_prefs_->DeepCopy()); | 95 prefs_.reset(testing_prefs_->DeepCopy()); |
80 LoadFinished(); | 96 LoadFinished(); |
81 } | 97 } |
| 98 |
| 99 const FilePath ExternalTestingExtensionLoader::GetBaseCrxFilePath() { |
| 100 return fake_base_path_; |
| 101 } |
OLD | NEW |