OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_loader.h" | 5 #include "chrome/browser/extensions/external_pref_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 if (!base::PathExists(external_extension_search_path)) { | 35 if (!base::PathExists(external_extension_search_path)) { |
36 // Does not have to exist. | 36 // Does not have to exist. |
37 return external_extension_paths; | 37 return external_extension_paths; |
38 } | 38 } |
39 | 39 |
40 base::FileEnumerator json_files( | 40 base::FileEnumerator json_files( |
41 external_extension_search_path, | 41 external_extension_search_path, |
42 false, // Recursive. | 42 false, // Recursive. |
43 base::FileEnumerator::FILES); | 43 base::FileEnumerator::FILES); |
44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
45 base::FilePath::StringType extension = base::UTF8ToWide(std::string(".json")); | 45 base::FilePath::StringType extension = base::UTF8ToWide(".json"); |
46 #elif defined(OS_POSIX) | 46 #elif defined(OS_POSIX) |
47 base::FilePath::StringType extension(".json"); | 47 base::FilePath::StringType extension(".json"); |
48 #endif | 48 #endif |
49 do { | 49 do { |
50 base::FilePath file = json_files.Next(); | 50 base::FilePath file = json_files.Next(); |
51 if (file.BaseName().value() == kExternalExtensionJson) | 51 if (file.BaseName().value() == kExternalExtensionJson) |
52 continue; // Already taken care of elsewhere. | 52 continue; // Already taken care of elsewhere. |
53 if (file.empty()) | 53 if (file.empty()) |
54 break; | 54 break; |
55 if (file.MatchesExtension(extension)) { | 55 if (file.MatchesExtension(extension)) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 for (std::set<base::FilePath>::const_iterator it = candidates.begin(); | 245 for (std::set<base::FilePath>::const_iterator it = candidates.begin(); |
246 it != candidates.end(); | 246 it != candidates.end(); |
247 ++it) { | 247 ++it) { |
248 base::FilePath extension_candidate_path = base_path_.Append(*it); | 248 base::FilePath extension_candidate_path = base_path_.Append(*it); |
249 | 249 |
250 std::string id = | 250 std::string id = |
251 #if defined(OS_WIN) | 251 #if defined(OS_WIN) |
252 base::UTF16ToASCII( | 252 base::UTF16ToASCII( |
253 extension_candidate_path.RemoveExtension().BaseName().value()); | 253 extension_candidate_path.RemoveExtension().BaseName().value()); |
254 #elif defined(OS_POSIX) | 254 #elif defined(OS_POSIX) |
255 extension_candidate_path.RemoveExtension().BaseName().value().c_str(); | 255 extension_candidate_path.RemoveExtension().BaseName().value(); |
256 #endif | 256 #endif |
257 | 257 |
258 DVLOG(1) << "Reading json file: " | 258 DVLOG(1) << "Reading json file: " |
259 << extension_candidate_path.LossyDisplayName().c_str(); | 259 << extension_candidate_path.LossyDisplayName(); |
260 | 260 |
261 JSONFileValueSerializer serializer(extension_candidate_path); | 261 JSONFileValueSerializer serializer(extension_candidate_path); |
262 scoped_ptr<base::DictionaryValue> ext_prefs( | 262 scoped_ptr<base::DictionaryValue> ext_prefs( |
263 ExtractExtensionPrefs(&serializer, extension_candidate_path)); | 263 ExtractExtensionPrefs(&serializer, extension_candidate_path)); |
264 if (ext_prefs) { | 264 if (ext_prefs) { |
265 DVLOG(1) << "Adding extension with id: " << id; | 265 DVLOG(1) << "Adding extension with id: " << id; |
266 prefs->Set(id, ext_prefs.release()); | 266 prefs->Set(id, ext_prefs.release()); |
267 } | 267 } |
268 } | 268 } |
269 } | 269 } |
(...skipping 14 matching lines...) Expand all Loading... |
284 LoadFinished(); | 284 LoadFinished(); |
285 } | 285 } |
286 | 286 |
287 ExternalTestingLoader::~ExternalTestingLoader() {} | 287 ExternalTestingLoader::~ExternalTestingLoader() {} |
288 | 288 |
289 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 289 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
290 return fake_base_path_; | 290 return fake_base_path_; |
291 } | 291 } |
292 | 292 |
293 } // namespace extensions | 293 } // namespace extensions |
OLD | NEW |