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

Side by Side Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 100573002: Move directory creation functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 #import "chrome/browser/web_applications/web_app_mac.h" 5 #import "chrome/browser/web_applications/web_app_mac.h"
6 6
7 #import <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "apps/app_shim/app_shim_mac.h" 10 #include "apps/app_shim/app_shim_mac.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 ConvertSkiaToARGB(bitmap, &raw_data); 130 ConvertSkiaToARGB(bitmap, &raw_data);
131 OSErr result = SetIconFamilyData(icon_family, icon_type, raw_data.Get()); 131 OSErr result = SetIconFamilyData(icon_family, icon_type, raw_data.Get());
132 DCHECK_EQ(noErr, result); 132 DCHECK_EQ(noErr, result);
133 return result == noErr; 133 return result == noErr;
134 } 134 }
135 135
136 base::FilePath GetWritableApplicationsDirectory() { 136 base::FilePath GetWritableApplicationsDirectory() {
137 base::FilePath path; 137 base::FilePath path;
138 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) { 138 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) {
139 if (!base::DirectoryExists(path)) { 139 if (!base::DirectoryExists(path)) {
140 if (!file_util::CreateDirectory(path)) 140 if (!base::CreateDirectory(path))
141 return base::FilePath(); 141 return base::FilePath();
142 142
143 // Create a zero-byte ".localized" file to inherit localizations from OSX 143 // Create a zero-byte ".localized" file to inherit localizations from OSX
144 // for folders that have special meaning. 144 // for folders that have special meaning.
145 file_util::WriteFile(path.Append(".localized"), NULL, 0); 145 file_util::WriteFile(path.Append(".localized"), NULL, 0);
146 } 146 }
147 return base::PathIsWritable(path) ? path : base::FilePath(); 147 return base::PathIsWritable(path) ? path : base::FilePath();
148 } 148 }
149 return base::FilePath(); 149 return base::FilePath();
150 } 150 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 251
252 // Adds a localized strings file for the Chrome Apps directory using the current 252 // Adds a localized strings file for the Chrome Apps directory using the current
253 // locale. OSX will use this for the display name. 253 // locale. OSX will use this for the display name.
254 // + Chrome Apps.localized (|apps_directory|) 254 // + Chrome Apps.localized (|apps_directory|)
255 // | + .localized 255 // | + .localized
256 // | | en.strings 256 // | | en.strings
257 // | | de.strings 257 // | | de.strings
258 void UpdateAppShortcutsSubdirLocalizedName( 258 void UpdateAppShortcutsSubdirLocalizedName(
259 const base::FilePath& apps_directory) { 259 const base::FilePath& apps_directory) {
260 base::FilePath localized = apps_directory.Append(".localized"); 260 base::FilePath localized = apps_directory.Append(".localized");
261 if (!file_util::CreateDirectory(localized)) 261 if (!base::CreateDirectory(localized))
262 return; 262 return;
263 263
264 base::FilePath directory_name = apps_directory.BaseName().RemoveExtension(); 264 base::FilePath directory_name = apps_directory.BaseName().RemoveExtension();
265 string16 localized_name = web_app::GetAppShortcutsSubdirName(); 265 string16 localized_name = web_app::GetAppShortcutsSubdirName();
266 NSDictionary* strings_dict = @{ 266 NSDictionary* strings_dict = @{
267 base::mac::FilePathToNSString(directory_name) : 267 base::mac::FilePathToNSString(directory_name) :
268 base::SysUTF16ToNSString(localized_name) 268 base::SysUTF16ToNSString(localized_name)
269 }; 269 };
270 270
271 std::string locale = l10n_util::NormalizeLocale( 271 std::string locale = l10n_util::NormalizeLocale(
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 return 0; 430 return 0;
431 431
432 base::FilePath app_name = GetShortcutBasename(); 432 base::FilePath app_name = GetShortcutBasename();
433 base::FilePath staging_path = scoped_temp_dir.path().Append(app_name); 433 base::FilePath staging_path = scoped_temp_dir.path().Append(app_name);
434 if (!BuildShortcut(staging_path)) 434 if (!BuildShortcut(staging_path))
435 return 0; 435 return 0;
436 436
437 for (std::vector<base::FilePath>::const_iterator it = folders.begin(); 437 for (std::vector<base::FilePath>::const_iterator it = folders.begin();
438 it != folders.end(); ++it) { 438 it != folders.end(); ++it) {
439 const base::FilePath& dst_path = *it; 439 const base::FilePath& dst_path = *it;
440 if (!file_util::CreateDirectory(dst_path)) { 440 if (!base::CreateDirectory(dst_path)) {
441 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; 441 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed.";
442 return succeeded; 442 return succeeded;
443 } 443 }
444 444
445 if (!base::CopyDirectory(staging_path, dst_path, true)) { 445 if (!base::CopyDirectory(staging_path, dst_path, true)) {
446 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() 446 LOG(ERROR) << "Copying app to dst path: " << dst_path.value()
447 << " failed"; 447 << " failed";
448 return succeeded; 448 return succeeded;
449 } 449 }
450 450
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 616
617 return [plist writeToFile:plist_path 617 return [plist writeToFile:plist_path
618 atomically:YES]; 618 atomically:YES];
619 } 619 }
620 620
621 bool WebAppShortcutCreator::UpdateDisplayName( 621 bool WebAppShortcutCreator::UpdateDisplayName(
622 const base::FilePath& app_path) const { 622 const base::FilePath& app_path) const {
623 // OSX searches for the best language in the order of preferred languages. 623 // OSX searches for the best language in the order of preferred languages.
624 // Since we only have one localization directory, it will choose this one. 624 // Since we only have one localization directory, it will choose this one.
625 base::FilePath localized_dir = GetResourcesPath(app_path).Append("en.lproj"); 625 base::FilePath localized_dir = GetResourcesPath(app_path).Append("en.lproj");
626 if (!file_util::CreateDirectory(localized_dir)) 626 if (!base::CreateDirectory(localized_dir))
627 return false; 627 return false;
628 628
629 NSString* bundle_name = base::SysUTF16ToNSString(info_.title); 629 NSString* bundle_name = base::SysUTF16ToNSString(info_.title);
630 NSString* display_name = base::SysUTF16ToNSString(info_.title); 630 NSString* display_name = base::SysUTF16ToNSString(info_.title);
631 if (HasExistingExtensionShim(GetApplicationsDirname(), 631 if (HasExistingExtensionShim(GetApplicationsDirname(),
632 info_.extension_id, 632 info_.extension_id,
633 app_path.BaseName())) { 633 app_path.BaseName())) {
634 display_name = [bundle_name 634 display_name = [bundle_name
635 stringByAppendingString:base::SysUTF8ToNSString( 635 stringByAppendingString:base::SysUTF8ToNSString(
636 " (" + info_.profile_name + ")")]; 636 " (" + info_.profile_name + ")")];
(...skipping 26 matching lines...) Expand all
663 if (!AddGfxImageToIconFamily(icon_family.GetAsIconFamilyHandle(), *it)) 663 if (!AddGfxImageToIconFamily(icon_family.GetAsIconFamilyHandle(), *it))
664 continue; 664 continue;
665 665
666 image_added = true; 666 image_added = true;
667 } 667 }
668 668
669 if (!image_added) 669 if (!image_added)
670 return false; 670 return false;
671 671
672 base::FilePath resources_path = GetResourcesPath(app_path); 672 base::FilePath resources_path = GetResourcesPath(app_path);
673 if (!file_util::CreateDirectory(resources_path)) 673 if (!base::CreateDirectory(resources_path))
674 return false; 674 return false;
675 675
676 return icon_family.WriteDataToFile(resources_path.Append("app.icns")); 676 return icon_family.WriteDataToFile(resources_path.Append("app.icns"));
677 } 677 }
678 678
679 bool WebAppShortcutCreator::UpdateInternalBundleIdentifier() const { 679 bool WebAppShortcutCreator::UpdateInternalBundleIdentifier() const {
680 NSString* plist_path = GetPlistPath(GetInternalShortcutPath()); 680 NSString* plist_path = GetPlistPath(GetInternalShortcutPath());
681 NSMutableDictionary* plist = ReadPlist(plist_path); 681 NSMutableDictionary* plist = ReadPlist(plist_path);
682 682
683 [plist setObject:base::SysUTF8ToNSString(GetInternalBundleIdentifier()) 683 [plist setObject:base::SysUTF8ToNSString(GetInternalBundleIdentifier())
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ShellIntegration::ShortcutInfo shortcut_info = 783 ShellIntegration::ShortcutInfo shortcut_info =
784 BuildShortcutInfoFromBundle(*it); 784 BuildShortcutInfoFromBundle(*it);
785 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info); 785 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info);
786 shortcut_creator.DeleteShortcuts(); 786 shortcut_creator.DeleteShortcuts();
787 } 787 }
788 } 788 }
789 789
790 } // namespace internals 790 } // namespace internals
791 791
792 } // namespace web_app 792 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/ui/web_applications/web_app_ui.cc ('k') | chrome/browser/web_applications/web_app_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698