]> khamidou — GitHub mirrors - electron.git/commitdiff
Move GetAsarArchivePath to asar_util.h
authorCheng Zhao <zcbenz@gmail.com>
Thu, 12 Feb 2015 09:31:14 +0000 (17:31 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 12 Feb 2015 09:31:14 +0000 (17:31 +0800)
atom/browser/net/asar/asar_protocol_handler.cc
atom/common/asar/asar_util.cc
atom/common/asar/asar_util.h

index 1e600feaa4fbec966d9f388c3be8e116a33fb516..0daa6f427e8f95d35209db43fa5faf0f9ebb1564 100644 (file)
 
 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<base::TaskRunner>& 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_);
 
index 256992c95899a928e74e377c5d6599d9a03d0c77..241f230c55b38948c20e1c7626a8879b86568f28 100644 (file)
@@ -17,8 +17,11 @@ typedef std::map<base::FilePath, std::shared_ptr<Archive>> ArchiveMap;
 
 namespace {
 
+// The global instance of ArchiveMap, will be destroyed on exit.
 static base::LazyInstance<ArchiveMap> g_archive_map = LAZY_INSTANCE_INITIALIZER;
 
+const base::FilePath::CharType kAsarExtension[] = FILE_PATH_LITERAL(".asar");
+
 }  // namespace
 
 std::shared_ptr<Archive> GetOrCreateAsarArchive(const base::FilePath& path) {
@@ -32,4 +35,26 @@ std::shared_ptr<Archive> 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
index f44204b2f7633132c4904b7d0e16056b317bcd0d..9df55da5f3cd25b96fecbc850ae172f55f73c9cf 100644 (file)
@@ -18,6 +18,11 @@ class Archive;
 // Gets or creates a new Archive from the path.
 std::shared_ptr<Archive> 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_