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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 BrowserThread::PostTask( | 53 BrowserThread::PostTask( |
54 BrowserThread::FILE, FROM_HERE, | 54 BrowserThread::FILE, FROM_HERE, |
55 NewRunnableMethod( | 55 NewRunnableMethod( |
56 this, | 56 this, |
57 &ExternalPrefExtensionLoader::LoadOnFileThread)); | 57 &ExternalPrefExtensionLoader::LoadOnFileThread)); |
58 } | 58 } |
59 | 59 |
60 void ExternalPrefExtensionLoader::LoadOnFileThread() { | 60 void ExternalPrefExtensionLoader::LoadOnFileThread() { |
61 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 61 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
62 | 62 |
63 CHECK(PathService::Get(base_path_key_, &base_path_)); | 63 scoped_ptr<DictionaryValue> prefs; |
64 | 64 |
65 FilePath json_file; | 65 if (PathService::Get(base_path_key_, &base_path_)) { |
66 json_file = base_path_.Append(FILE_PATH_LITERAL("external_extensions.json")); | 66 FilePath json_file; |
| 67 json_file = |
| 68 base_path_.Append(FILE_PATH_LITERAL("external_extensions.json")); |
67 | 69 |
68 scoped_ptr<DictionaryValue> prefs; | 70 if (file_util::PathExists(json_file)) { |
69 if (file_util::PathExists(json_file)) { | 71 JSONFileValueSerializer serializer(json_file); |
70 JSONFileValueSerializer serializer(json_file); | 72 prefs.reset(ExtractPrefs(&serializer)); |
71 prefs.reset(ExtractPrefs(&serializer)); | 73 } |
72 } else { | 74 } |
| 75 |
| 76 if (!prefs.get()) |
73 prefs.reset(new DictionaryValue()); | 77 prefs.reset(new DictionaryValue()); |
74 } | |
75 | 78 |
76 prefs_.reset(prefs.release()); | 79 prefs_.reset(prefs.release()); |
77 BrowserThread::PostTask( | 80 BrowserThread::PostTask( |
78 BrowserThread::UI, FROM_HERE, | 81 BrowserThread::UI, FROM_HERE, |
79 NewRunnableMethod( | 82 NewRunnableMethod( |
80 this, | 83 this, |
81 &ExternalPrefExtensionLoader::LoadFinished)); | 84 &ExternalPrefExtensionLoader::LoadFinished)); |
82 } | 85 } |
83 | 86 |
84 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader( | 87 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader( |
85 const std::string& json_data, | 88 const std::string& json_data, |
86 const FilePath& fake_base_path) | 89 const FilePath& fake_base_path) |
87 : fake_base_path_(fake_base_path) { | 90 : fake_base_path_(fake_base_path) { |
88 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 91 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
89 JSONStringValueSerializer serializer(json_data); | 92 JSONStringValueSerializer serializer(json_data); |
90 testing_prefs_.reset(ExtractPrefs(&serializer)); | 93 testing_prefs_.reset(ExtractPrefs(&serializer)); |
91 } | 94 } |
92 | 95 |
93 void ExternalTestingExtensionLoader::StartLoading() { | 96 void ExternalTestingExtensionLoader::StartLoading() { |
94 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
95 prefs_.reset(testing_prefs_->DeepCopy()); | 98 prefs_.reset(testing_prefs_->DeepCopy()); |
96 LoadFinished(); | 99 LoadFinished(); |
97 } | 100 } |
98 | 101 |
99 const FilePath ExternalTestingExtensionLoader::GetBaseCrxFilePath() { | 102 const FilePath ExternalTestingExtensionLoader::GetBaseCrxFilePath() { |
100 return fake_base_path_; | 103 return fake_base_path_; |
101 } | 104 } |
OLD | NEW |