Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/shell_integration_linux.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/shell_integration_linux.h" 5 #include "chrome/browser/shell_integration_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <glib.h> 8 #include <glib.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 for (gfx::ImageFamily::const_iterator it = icon_images.begin(); 96 for (gfx::ImageFamily::const_iterator it = icon_images.begin();
97 it != icon_images.end(); ++it) { 97 it != icon_images.end(); ++it) {
98 int width = it->Width(); 98 int width = it->Width();
99 scoped_refptr<base::RefCountedMemory> png_data = it->As1xPNGBytes(); 99 scoped_refptr<base::RefCountedMemory> png_data = it->As1xPNGBytes();
100 if (png_data->size() == 0) { 100 if (png_data->size() == 0) {
101 // If the bitmap could not be encoded to PNG format, skip it. 101 // If the bitmap could not be encoded to PNG format, skip it.
102 LOG(WARNING) << "Could not encode icon " << icon_name << ".png at size " 102 LOG(WARNING) << "Could not encode icon " << icon_name << ".png at size "
103 << width << "."; 103 << width << ".";
104 continue; 104 continue;
105 } 105 }
106 int bytes_written = file_util::WriteFile(temp_file_path, 106 int bytes_written = base::WriteFile(temp_file_path,
107 png_data->front_as<char>(), 107 png_data->front_as<char>(),
108 png_data->size()); 108 png_data->size());
109 109
110 if (bytes_written != static_cast<int>(png_data->size())) 110 if (bytes_written != static_cast<int>(png_data->size()))
111 return std::string(); 111 return std::string();
112 112
113 std::vector<std::string> argv; 113 std::vector<std::string> argv;
114 argv.push_back("xdg-icon-resource"); 114 argv.push_back("xdg-icon-resource");
115 argv.push_back("install"); 115 argv.push_back("install");
116 116
117 // Always install in user mode, even if someone runs the browser as root 117 // Always install in user mode, even if someone runs the browser as root
118 // (people do that). 118 // (people do that).
(...skipping 29 matching lines...) Expand all
148 148
149 int fd = openat(desktop_fd, shortcut_filename.value().c_str(), 149 int fd = openat(desktop_fd, shortcut_filename.value().c_str(),
150 O_CREAT | O_EXCL | O_WRONLY, 150 O_CREAT | O_EXCL | O_WRONLY,
151 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); 151 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
152 if (fd < 0) { 152 if (fd < 0) {
153 if (IGNORE_EINTR(close(desktop_fd)) < 0) 153 if (IGNORE_EINTR(close(desktop_fd)) < 0)
154 PLOG(ERROR) << "close"; 154 PLOG(ERROR) << "close";
155 return false; 155 return false;
156 } 156 }
157 157
158 ssize_t bytes_written = file_util::WriteFileDescriptor(fd, contents.data(), 158 ssize_t bytes_written = base::WriteFileDescriptor(fd, contents.data(),
159 contents.length()); 159 contents.length());
160 if (IGNORE_EINTR(close(fd)) < 0) 160 if (IGNORE_EINTR(close(fd)) < 0)
161 PLOG(ERROR) << "close"; 161 PLOG(ERROR) << "close";
162 162
163 if (bytes_written != static_cast<ssize_t>(contents.length())) { 163 if (bytes_written != static_cast<ssize_t>(contents.length())) {
164 // Delete the file. No shortuct is better than corrupted one. Use unlinkat 164 // Delete the file. No shortuct is better than corrupted one. Use unlinkat
165 // to make sure we're deleting the file in the directory we think we are. 165 // to make sure we're deleting the file in the directory we think we are.
166 // Even if an attacker manager to put something other at 166 // Even if an attacker manager to put something other at
167 // |shortcut_filename| we'll just undo his action. 167 // |shortcut_filename| we'll just undo his action.
168 unlinkat(desktop_fd, shortcut_filename.value().c_str(), 0); 168 unlinkat(desktop_fd, shortcut_filename.value().c_str(), 0);
169 } 169 }
(...skipping 19 matching lines...) Expand all
189 const base::FilePath& directory_filename, 189 const base::FilePath& directory_filename,
190 const std::string& directory_contents) { 190 const std::string& directory_contents) {
191 base::ScopedTempDir temp_dir; 191 base::ScopedTempDir temp_dir;
192 if (!temp_dir.CreateUniqueTempDir()) 192 if (!temp_dir.CreateUniqueTempDir())
193 return false; 193 return false;
194 194
195 base::FilePath temp_directory_path; 195 base::FilePath temp_directory_path;
196 if (!directory_filename.empty()) { 196 if (!directory_filename.empty()) {
197 temp_directory_path = temp_dir.path().Append(directory_filename); 197 temp_directory_path = temp_dir.path().Append(directory_filename);
198 198
199 int bytes_written = file_util::WriteFile(temp_directory_path, 199 int bytes_written = base::WriteFile(temp_directory_path,
200 directory_contents.data(), 200 directory_contents.data(),
201 directory_contents.length()); 201 directory_contents.length());
202 202
203 if (bytes_written != static_cast<int>(directory_contents.length())) 203 if (bytes_written != static_cast<int>(directory_contents.length()))
204 return false; 204 return false;
205 } 205 }
206 206
207 base::FilePath temp_file_path = temp_dir.path().Append(shortcut_filename); 207 base::FilePath temp_file_path = temp_dir.path().Append(shortcut_filename);
208 208
209 int bytes_written = file_util::WriteFile(temp_file_path, contents.data(), 209 int bytes_written = base::WriteFile(temp_file_path, contents.data(),
210 contents.length()); 210 contents.length());
211 211
212 if (bytes_written != static_cast<int>(contents.length())) 212 if (bytes_written != static_cast<int>(contents.length()))
213 return false; 213 return false;
214 214
215 std::vector<std::string> argv; 215 std::vector<std::string> argv;
216 argv.push_back("xdg-desktop-menu"); 216 argv.push_back("xdg-desktop-menu");
217 argv.push_back("install"); 217 argv.push_back("install");
218 218
219 // Always install in user mode, even if someone runs the browser as root 219 // Always install in user mode, even if someone runs the browser as root
220 // (people do that). 220 // (people do that).
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 for (std::vector<base::FilePath>::const_iterator it = 1028 for (std::vector<base::FilePath>::const_iterator it =
1029 shortcut_filenames_app_menu.begin(); 1029 shortcut_filenames_app_menu.begin();
1030 it != shortcut_filenames_app_menu.end(); ++it) { 1030 it != shortcut_filenames_app_menu.end(); ++it) {
1031 DeleteShortcutInApplicationsMenu(*it, 1031 DeleteShortcutInApplicationsMenu(*it,
1032 base::FilePath(kDirectoryFilename)); 1032 base::FilePath(kDirectoryFilename));
1033 } 1033 }
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 } // namespace ShellIntegrationLinux 1037 } // namespace ShellIntegrationLinux
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698