Chromium Code Reviews| 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 "base/strings/sys_string_conversions.h" | |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "third_party/zlib/google/zip.h" | 16 #include "third_party/zlib/google/zip.h" |
| 16 #include "ui/shell_dialogs/selected_file_info.h" | 17 #include "ui/shell_dialogs/selected_file_info.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Given the |path| of a package, returns the destination that the package | 21 // Given the |path| of a package, returns the destination that the package |
| 21 // should be zipped to. Returns an empty path on any errors. | 22 // should be zipped to. Returns an empty path on any errors. |
| 22 base::FilePath ZipDestination(const base::FilePath& path) { | 23 base::FilePath ZipDestination(const base::FilePath& path) { |
| 23 NSMutableString* dest = | 24 base::FilePath dest; |
| 24 [NSMutableString stringWithString:NSTemporaryDirectory()]; | |
| 25 | 25 |
| 26 // Couldn't get the temporary directory. | 26 if (!base::GetTempDir(&dest)) { |
| 27 if (!dest) | 27 // Couldn't get the temporary directory. |
| 28 return base::FilePath(); | 28 return base::FilePath(); |
| 29 } | |
| 29 | 30 |
| 30 [dest appendFormat:@"%@/zip_cache/%@", | 31 // TMPDIR/<bundleID>/zip_cache/<GUID> |
| 31 [[NSBundle mainBundle] bundleIdentifier], | |
| 32 [[NSProcessInfo processInfo] globallyUniqueString]]; | |
| 33 | 32 |
| 34 return base::mac::NSStringToFilePath(dest); | 33 NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier]; |
| 34 dest = dest.Append(base::SysNSStringToUTF8(bundleID)); | |
|
Mark Mentovai
2017/03/01 02:33:49
For things that become file paths, this is better
iannucci
2017/03/01 02:49:13
Done.
| |
| 35 | |
| 36 dest = dest.Append("zip_cache"); | |
| 37 | |
| 38 NSString* GUID = [[NSProcessInfo processInfo] globallyUniqueString]; | |
|
Mark Mentovai
2017/03/01 02:33:49
We name variables in lowercase, this should be “gu
iannucci
2017/03/01 02:49:13
Done.
| |
| 39 dest = dest.Append(base::SysNSStringToUTF8(GUID)); | |
| 40 | |
| 41 return dest; | |
| 35 } | 42 } |
| 36 | 43 |
| 37 // Returns the path of the package and its components relative to the package's | 44 // Returns the path of the package and its components relative to the package's |
| 38 // parent directory. | 45 // parent directory. |
| 39 std::vector<base::FilePath> RelativePathsForPackage( | 46 std::vector<base::FilePath> RelativePathsForPackage( |
| 40 const base::FilePath& package) { | 47 const base::FilePath& package) { |
| 41 // Get the base directory. | 48 // Get the base directory. |
| 42 base::FilePath base_dir = package.DirName(); | 49 base::FilePath base_dir = package.DirName(); |
| 43 | 50 |
| 44 // Add the package as the first relative path. | 51 // 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. | 138 // need to be deleted now. |
| 132 if (!web_contents_) { | 139 if (!web_contents_) { |
| 133 DeleteTemporaryFiles(); | 140 DeleteTemporaryFiles(); |
| 134 RunFileChooserEnd(); | 141 RunFileChooserEnd(); |
| 135 return; | 142 return; |
| 136 } | 143 } |
| 137 } | 144 } |
| 138 | 145 |
| 139 NotifyRenderFrameHostAndEnd(files); | 146 NotifyRenderFrameHostAndEnd(files); |
| 140 } | 147 } |
| OLD | NEW |