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

Side by Side Diff: chrome/browser/web_applications/web_app_win.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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/web_applications/web_app_win.h" 5 #include "chrome/browser/web_applications/web_app_win.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 sizeof(digest)) == sizeof(digest); 68 sizeof(digest)) == sizeof(digest);
69 } 69 }
70 70
71 // Returns true if |icon_file| is missing or different from |image|. 71 // Returns true if |icon_file| is missing or different from |image|.
72 bool ShouldUpdateIcon(const base::FilePath& icon_file, 72 bool ShouldUpdateIcon(const base::FilePath& icon_file,
73 const gfx::ImageFamily& image) { 73 const gfx::ImageFamily& image) {
74 base::FilePath checksum_file( 74 base::FilePath checksum_file(
75 icon_file.ReplaceExtension(kIconChecksumFileExt)); 75 icon_file.ReplaceExtension(kIconChecksumFileExt));
76 76
77 // Returns true if icon_file or checksum file is missing. 77 // Returns true if icon_file or checksum file is missing.
78 if (!file_util::PathExists(icon_file) || 78 if (!base::PathExists(icon_file) ||
79 !file_util::PathExists(checksum_file)) 79 !base::PathExists(checksum_file))
80 return true; 80 return true;
81 81
82 base::MD5Digest persisted_image_checksum; 82 base::MD5Digest persisted_image_checksum;
83 if (sizeof(persisted_image_checksum) != file_util::ReadFile(checksum_file, 83 if (sizeof(persisted_image_checksum) != file_util::ReadFile(checksum_file,
84 reinterpret_cast<char*>(&persisted_image_checksum), 84 reinterpret_cast<char*>(&persisted_image_checksum),
85 sizeof(persisted_image_checksum))) 85 sizeof(persisted_image_checksum)))
86 return true; 86 return true;
87 87
88 base::MD5Digest downloaded_image_checksum; 88 base::MD5Digest downloaded_image_checksum;
89 GetImageCheckSum(image, &downloaded_image_checksum); 89 GetImageCheckSum(image, &downloaded_image_checksum);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 Append(web_app::internals::GetSanitizedFileName(shortcut_name)). 136 Append(web_app::internals::GetSanitizedFileName(shortcut_name)).
137 AddExtension(FILE_PATH_LITERAL(".lnk")); 137 AddExtension(FILE_PATH_LITERAL(".lnk"));
138 138
139 const int fileNamesToCheck = 10; 139 const int fileNamesToCheck = 10;
140 for (int i = 0; i < fileNamesToCheck; ++i) { 140 for (int i = 0; i < fileNamesToCheck; ++i) {
141 base::FilePath shortcut_file = base_path; 141 base::FilePath shortcut_file = base_path;
142 if (i > 0) { 142 if (i > 0) {
143 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( 143 shortcut_file = shortcut_file.InsertBeforeExtensionASCII(
144 base::StringPrintf(" (%d)", i)); 144 base::StringPrintf(" (%d)", i));
145 } 145 }
146 if (file_util::PathExists(shortcut_file) && 146 if (base::PathExists(shortcut_file) &&
147 IsAppShortcutForProfile(shortcut_file, profile_path)) { 147 IsAppShortcutForProfile(shortcut_file, profile_path)) {
148 shortcut_paths.push_back(shortcut_file); 148 shortcut_paths.push_back(shortcut_file);
149 } 149 }
150 } 150 }
151 } 151 }
152 152
153 return shortcut_paths; 153 return shortcut_paths;
154 } 154 }
155 155
156 // Creates application shortcuts in a given set of paths. 156 // Creates application shortcuts in a given set of paths.
157 // |shortcut_paths| is a list of directories in which shortcuts should be 157 // |shortcut_paths| is a list of directories in which shortcuts should be
158 // created. If |creation_policy| is DONT_CREATE_DUPLICATE_SHORTCUTS and there is 158 // created. If |creation_policy| is DONT_CREATE_DUPLICATE_SHORTCUTS and there is
159 // an existing shortcut to this app for this profile, does nothing (succeeding). 159 // an existing shortcut to this app for this profile, does nothing (succeeding).
160 // Returns true on success, false on failure. 160 // Returns true on success, false on failure.
161 // Must be called on the FILE thread. 161 // Must be called on the FILE thread.
162 bool CreateShortcutsInPaths( 162 bool CreateShortcutsInPaths(
163 const base::FilePath& web_app_path, 163 const base::FilePath& web_app_path,
164 const ShellIntegration::ShortcutInfo& shortcut_info, 164 const ShellIntegration::ShortcutInfo& shortcut_info,
165 const std::vector<base::FilePath>& shortcut_paths, 165 const std::vector<base::FilePath>& shortcut_paths,
166 web_app::ShortcutCreationPolicy creation_policy, 166 web_app::ShortcutCreationPolicy creation_policy,
167 std::vector<base::FilePath>* out_filenames) { 167 std::vector<base::FilePath>* out_filenames) {
168 // Ensure web_app_path exists. 168 // Ensure web_app_path exists.
169 if (!file_util::PathExists(web_app_path) && 169 if (!base::PathExists(web_app_path) &&
170 !file_util::CreateDirectory(web_app_path)) { 170 !file_util::CreateDirectory(web_app_path)) {
171 return false; 171 return false;
172 } 172 }
173 173
174 // Generates file name to use with persisted ico and shortcut file. 174 // Generates file name to use with persisted ico and shortcut file.
175 base::FilePath file_name = 175 base::FilePath file_name =
176 web_app::internals::GetSanitizedFileName(shortcut_info.title); 176 web_app::internals::GetSanitizedFileName(shortcut_info.title);
177 177
178 // Creates an ico file to use with shortcut. 178 // Creates an ico file to use with shortcut.
179 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( 179 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 236 }
237 } 237 }
238 base::win::ShortcutProperties shortcut_properties; 238 base::win::ShortcutProperties shortcut_properties;
239 shortcut_properties.set_target(chrome_exe); 239 shortcut_properties.set_target(chrome_exe);
240 shortcut_properties.set_working_dir(working_dir); 240 shortcut_properties.set_working_dir(working_dir);
241 shortcut_properties.set_arguments(wide_switches); 241 shortcut_properties.set_arguments(wide_switches);
242 shortcut_properties.set_description(description); 242 shortcut_properties.set_description(description);
243 shortcut_properties.set_icon(icon_file, 0); 243 shortcut_properties.set_icon(icon_file, 0);
244 shortcut_properties.set_app_id(app_id); 244 shortcut_properties.set_app_id(app_id);
245 shortcut_properties.set_dual_mode(false); 245 shortcut_properties.set_dual_mode(false);
246 if (!file_util::PathExists(shortcut_file.DirName()) && 246 if (!base::PathExists(shortcut_file.DirName()) &&
247 !file_util::CreateDirectory(shortcut_file.DirName())) { 247 !file_util::CreateDirectory(shortcut_file.DirName())) {
248 NOTREACHED(); 248 NOTREACHED();
249 return false; 249 return false;
250 } 250 }
251 success = base::win::CreateOrUpdateShortcutLink( 251 success = base::win::CreateOrUpdateShortcutLink(
252 shortcut_file, shortcut_properties, 252 shortcut_file, shortcut_properties,
253 base::win::SHORTCUT_CREATE_ALWAYS) && success; 253 base::win::SHORTCUT_CREATE_ALWAYS) && success;
254 if (out_filenames) 254 if (out_filenames)
255 out_filenames->push_back(shortcut_file); 255 out_filenames->push_back(shortcut_file);
256 } 256 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). 437 base::FilePath shortcut_to_pin = web_app_path.Append(file_name).
438 AddExtension(installer::kLnkExt); 438 AddExtension(installer::kLnkExt);
439 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); 439 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str());
440 } 440 }
441 } 441 }
442 442
443 // If an icon file exists, and is out of date, replace it with the new icon 443 // If an icon file exists, and is out of date, replace it with the new icon
444 // and let the shell know the icon has been modified. 444 // and let the shell know the icon has been modified.
445 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( 445 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension(
446 FILE_PATH_LITERAL(".ico")); 446 FILE_PATH_LITERAL(".ico"));
447 if (file_util::PathExists(icon_file)) { 447 if (base::PathExists(icon_file)) {
448 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); 448 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon);
449 } 449 }
450 } 450 }
451 451
452 void DeletePlatformShortcuts( 452 void DeletePlatformShortcuts(
453 const base::FilePath& web_app_path, 453 const base::FilePath& web_app_path,
454 const ShellIntegration::ShortcutInfo& shortcut_info) { 454 const ShellIntegration::ShortcutInfo& shortcut_info) {
455 GetShortcutLocationsAndDeleteShortcuts( 455 GetShortcutLocationsAndDeleteShortcuts(
456 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, 456 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL,
457 NULL); 457 NULL);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 path = path.Append(locations[i].subdir); 524 path = path.Append(locations[i].subdir);
525 shortcut_paths.push_back(path); 525 shortcut_paths.push_back(path);
526 } 526 }
527 } 527 }
528 return shortcut_paths; 528 return shortcut_paths;
529 } 529 }
530 530
531 } // namespace internals 531 } // namespace internals
532 532
533 } // namespace web_app 533 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_mac_unittest.mm ('k') | chrome/common/chrome_content_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698