diff --git a/atom/browser/net/asar/asar_protocol_handler.cc b/atom/browser/net/asar/asar_protocol_handler.cc index 1e600feaa4fb..0daa6f427e8f 100644 --- a/atom/browser/net/asar/asar_protocol_handler.cc +++ b/atom/browser/net/asar/asar_protocol_handler.cc @@ -14,35 +14,6 @@ namespace asar { -namespace { - -const base::FilePath::CharType kAsarExtension[] = FILE_PATH_LITERAL(".asar"); - -// Get the relative path in asar archive. -bool GetAsarPath(const base::FilePath& full_path, - base::FilePath* asar_path, - base::FilePath* relative_path) { - base::FilePath iter = full_path; - while (true) { - base::FilePath dirname = iter.DirName(); - if (iter.MatchesExtension(kAsarExtension)) - break; - else if (iter == dirname) - return false; - iter = dirname; - } - - base::FilePath tail; - if (!iter.AppendRelativePath(full_path, &tail)) - return false; - - *asar_path = iter; - *relative_path = tail; - return true; -} - -} // namespace - AsarProtocolHandler::AsarProtocolHandler( const scoped_refptr& file_task_runner) : file_task_runner_(file_task_runner) {} @@ -59,7 +30,7 @@ net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob( // Create asar:// job when the path contains "xxx.asar/", otherwise treat the // URL request as file://. base::FilePath asar_path, relative_path; - if (!GetAsarPath(full_path, &asar_path, &relative_path)) + if (!GetAsarArchivePath(full_path, &asar_path, &relative_path)) return new net::URLRequestFileJob(request, network_delegate, full_path, file_task_runner_); diff --git a/atom/common/asar/asar_util.cc b/atom/common/asar/asar_util.cc index 256992c95899..241f230c55b3 100644 --- a/atom/common/asar/asar_util.cc +++ b/atom/common/asar/asar_util.cc @@ -17,8 +17,11 @@ typedef std::map> ArchiveMap; namespace { +// The global instance of ArchiveMap, will be destroyed on exit. static base::LazyInstance g_archive_map = LAZY_INSTANCE_INITIALIZER; +const base::FilePath::CharType kAsarExtension[] = FILE_PATH_LITERAL(".asar"); + } // namespace std::shared_ptr GetOrCreateAsarArchive(const base::FilePath& path) { @@ -32,4 +35,26 @@ std::shared_ptr GetOrCreateAsarArchive(const base::FilePath& path) { return archive_map[path]; } +bool GetAsarArchivePath(const base::FilePath& full_path, + base::FilePath* asar_path, + base::FilePath* relative_path) { + base::FilePath iter = full_path; + while (true) { + base::FilePath dirname = iter.DirName(); + if (iter.MatchesExtension(kAsarExtension)) + break; + else if (iter == dirname) + return false; + iter = dirname; + } + + base::FilePath tail; + if (!iter.AppendRelativePath(full_path, &tail)) + return false; + + *asar_path = iter; + *relative_path = tail; + return true; +} + } // namespace asar diff --git a/atom/common/asar/asar_util.h b/atom/common/asar/asar_util.h index f44204b2f763..9df55da5f3cd 100644 --- a/atom/common/asar/asar_util.h +++ b/atom/common/asar/asar_util.h @@ -18,6 +18,11 @@ class Archive; // Gets or creates a new Archive from the path. std::shared_ptr GetOrCreateAsarArchive(const base::FilePath& path); +// Separates the path to Archive out. +bool GetAsarArchivePath(const base::FilePath& full_path, + base::FilePath* asar_path, + base::FilePath* relative_path); + } // namespace asar #endif // ATOM_COMMON_ASAR_ASAR_UTIL_H_