| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_select_helper.h" | 5 #include "chrome/browser/file_select_helper.h" |
| 6 | 6 |
| 7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "third_party/zlib/google/zip.h" | 15 #include "third_party/zlib/google/zip.h" |
| 16 #include "ui/shell_dialogs/selected_file_info.h" | 16 #include "ui/shell_dialogs/selected_file_info.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Given the |path| of a package, returns the destination that the package | 20 // Given the |path| of a package, returns the destination that the package |
| 21 // should be zipped to. Returns an empty path on any errors. | 21 // should be zipped to. Returns an empty path on any errors. |
| 22 base::FilePath ZipDestination(const base::FilePath& path) { | 22 base::FilePath ZipDestination(const base::FilePath& path) { |
| 23 NSMutableString* dest = | 23 base::FilePath dest; |
| 24 [NSMutableString stringWithString:NSTemporaryDirectory()]; | |
| 25 | 24 |
| 26 // Couldn't get the temporary directory. | 25 if (!base::GetTempDir(&dest)) { |
| 27 if (!dest) | 26 // Couldn't get the temporary directory. |
| 28 return base::FilePath(); | 27 return base::FilePath(); |
| 28 } |
| 29 | 29 |
| 30 [dest appendFormat:@"%@/zip_cache/%@", | 30 // TMPDIR/<bundleID>/zip_cache/<guid> |
| 31 [[NSBundle mainBundle] bundleIdentifier], | |
| 32 [[NSProcessInfo processInfo] globallyUniqueString]]; | |
| 33 | 31 |
| 34 return base::mac::NSStringToFilePath(dest); | 32 NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier]; |
| 33 dest = dest.Append([bundleID fileSystemRepresentation]); |
| 34 |
| 35 dest = dest.Append("zip_cache"); |
| 36 |
| 37 NSString* guid = [[NSProcessInfo processInfo] globallyUniqueString]; |
| 38 dest = dest.Append([guid fileSystemRepresentation]); |
| 39 |
| 40 return dest; |
| 35 } | 41 } |
| 36 | 42 |
| 37 // Returns the path of the package and its components relative to the package's | 43 // Returns the path of the package and its components relative to the package's |
| 38 // parent directory. | 44 // parent directory. |
| 39 std::vector<base::FilePath> RelativePathsForPackage( | 45 std::vector<base::FilePath> RelativePathsForPackage( |
| 40 const base::FilePath& package) { | 46 const base::FilePath& package) { |
| 41 // Get the base directory. | 47 // Get the base directory. |
| 42 base::FilePath base_dir = package.DirName(); | 48 base::FilePath base_dir = package.DirName(); |
| 43 | 49 |
| 44 // Add the package as the first relative path. | 50 // Add the package as the first relative path. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // need to be deleted now. | 137 // need to be deleted now. |
| 132 if (!web_contents_) { | 138 if (!web_contents_) { |
| 133 DeleteTemporaryFiles(); | 139 DeleteTemporaryFiles(); |
| 134 RunFileChooserEnd(); | 140 RunFileChooserEnd(); |
| 135 return; | 141 return; |
| 136 } | 142 } |
| 137 } | 143 } |
| 138 | 144 |
| 139 NotifyRenderFrameHostAndEnd(files); | 145 NotifyRenderFrameHostAndEnd(files); |
| 140 } | 146 } |
| OLD | NEW |