| 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/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_enumerator.h" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
| 11 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 | 20 |
| 20 using content::BrowserThread; | 21 using content::BrowserThread; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 base::FilePath::CharType kExternalExtensionJson[] = | 25 base::FilePath::CharType kExternalExtensionJson[] = |
| 25 FILE_PATH_LITERAL("external_extensions.json"); | 26 FILE_PATH_LITERAL("external_extensions.json"); |
| 26 | 27 |
| 27 std::set<base::FilePath> GetPrefsCandidateFilesFromFolder( | 28 std::set<base::FilePath> GetPrefsCandidateFilesFromFolder( |
| 28 const base::FilePath& external_extension_search_path) { | 29 const base::FilePath& external_extension_search_path) { |
| 29 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 30 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 30 | 31 |
| 31 std::set<base::FilePath> external_extension_paths; | 32 std::set<base::FilePath> external_extension_paths; |
| 32 | 33 |
| 33 if (!file_util::PathExists(external_extension_search_path)) { | 34 if (!file_util::PathExists(external_extension_search_path)) { |
| 34 // Does not have to exist. | 35 // Does not have to exist. |
| 35 return external_extension_paths; | 36 return external_extension_paths; |
| 36 } | 37 } |
| 37 | 38 |
| 38 file_util::FileEnumerator json_files( | 39 base::FileEnumerator json_files( |
| 39 external_extension_search_path, | 40 external_extension_search_path, |
| 40 false, // Recursive. | 41 false, // Recursive. |
| 41 file_util::FileEnumerator::FILES); | 42 base::FileEnumerator::FILES); |
| 42 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 43 base::FilePath::StringType extension = UTF8ToWide(std::string(".json")); | 44 base::FilePath::StringType extension = UTF8ToWide(std::string(".json")); |
| 44 #elif defined(OS_POSIX) | 45 #elif defined(OS_POSIX) |
| 45 base::FilePath::StringType extension(".json"); | 46 base::FilePath::StringType extension(".json"); |
| 46 #endif | 47 #endif |
| 47 do { | 48 do { |
| 48 base::FilePath file = json_files.Next(); | 49 base::FilePath file = json_files.Next(); |
| 49 if (file.BaseName().value() == kExternalExtensionJson) | 50 if (file.BaseName().value() == kExternalExtensionJson) |
| 50 continue; // Already taken care of elsewhere. | 51 continue; // Already taken care of elsewhere. |
| 51 if (file.empty()) | 52 if (file.empty()) |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 LoadFinished(); | 246 LoadFinished(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 ExternalTestingLoader::~ExternalTestingLoader() {} | 249 ExternalTestingLoader::~ExternalTestingLoader() {} |
| 249 | 250 |
| 250 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 251 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
| 251 return fake_base_path_; | 252 return fake_base_path_; |
| 252 } | 253 } |
| 253 | 254 |
| 254 } // extensions | 255 } // extensions |
| OLD | NEW |