OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #endif // defined(OS_WIN) | 9 #endif // defined(OS_WIN) |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 #if defined(TOOLKIT_VIEWS) | 93 #if defined(TOOLKIT_VIEWS) |
94 // Predicator for sorting images from largest to smallest. | 94 // Predicator for sorting images from largest to smallest. |
95 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, | 95 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, |
96 const WebApplicationInfo::IconInfo& right) { | 96 const WebApplicationInfo::IconInfo& right) { |
97 return left.width < right.width; | 97 return left.width < right.width; |
98 } | 98 } |
99 #endif | 99 #endif |
100 | 100 |
101 #if defined(OS_WIN) | 101 #if defined(OS_WIN) |
102 // Calculates image checksum using MD5. | 102 // Calculates image checksum using MD5. |
103 void GetImageCheckSum(const SkBitmap& image, MD5Digest* digest) { | 103 void GetImageCheckSum(const SkBitmap& image, base::MD5Digest* digest) { |
104 DCHECK(digest); | 104 DCHECK(digest); |
105 | 105 |
106 SkAutoLockPixels image_lock(image); | 106 SkAutoLockPixels image_lock(image); |
107 MD5Sum(image.getPixels(), image.getSize(), digest); | 107 MD5Sum(image.getPixels(), image.getSize(), digest); |
108 } | 108 } |
109 | 109 |
110 // Saves |image| as an |icon_file| with the checksum. | 110 // Saves |image| as an |icon_file| with the checksum. |
111 bool SaveIconWithCheckSum(const FilePath& icon_file, const SkBitmap& image) { | 111 bool SaveIconWithCheckSum(const FilePath& icon_file, const SkBitmap& image) { |
112 if (!IconUtil::CreateIconFileFromSkBitmap(image, icon_file)) | 112 if (!IconUtil::CreateIconFileFromSkBitmap(image, icon_file)) |
113 return false; | 113 return false; |
114 | 114 |
115 MD5Digest digest; | 115 base::MD5Digest digest; |
116 GetImageCheckSum(image, &digest); | 116 GetImageCheckSum(image, &digest); |
117 | 117 |
118 FilePath cheksum_file(icon_file.ReplaceExtension(kIconChecksumFileExt)); | 118 FilePath cheksum_file(icon_file.ReplaceExtension(kIconChecksumFileExt)); |
119 return file_util::WriteFile(cheksum_file, | 119 return file_util::WriteFile(cheksum_file, |
120 reinterpret_cast<const char*>(&digest), | 120 reinterpret_cast<const char*>(&digest), |
121 sizeof(digest)) == sizeof(digest); | 121 sizeof(digest)) == sizeof(digest); |
122 } | 122 } |
123 | 123 |
124 // Returns true if |icon_file| is missing or different from |image|. | 124 // Returns true if |icon_file| is missing or different from |image|. |
125 bool ShouldUpdateIcon(const FilePath& icon_file, const SkBitmap& image) { | 125 bool ShouldUpdateIcon(const FilePath& icon_file, const SkBitmap& image) { |
126 FilePath checksum_file(icon_file.ReplaceExtension(kIconChecksumFileExt)); | 126 FilePath checksum_file(icon_file.ReplaceExtension(kIconChecksumFileExt)); |
127 | 127 |
128 // Returns true if icon_file or checksum file is missing. | 128 // Returns true if icon_file or checksum file is missing. |
129 if (!file_util::PathExists(icon_file) || | 129 if (!file_util::PathExists(icon_file) || |
130 !file_util::PathExists(checksum_file)) | 130 !file_util::PathExists(checksum_file)) |
131 return true; | 131 return true; |
132 | 132 |
133 MD5Digest persisted_image_checksum; | 133 base::MD5Digest persisted_image_checksum; |
134 if (sizeof(persisted_image_checksum) != file_util::ReadFile(checksum_file, | 134 if (sizeof(persisted_image_checksum) != file_util::ReadFile(checksum_file, |
135 reinterpret_cast<char*>(&persisted_image_checksum), | 135 reinterpret_cast<char*>(&persisted_image_checksum), |
136 sizeof(persisted_image_checksum))) | 136 sizeof(persisted_image_checksum))) |
137 return true; | 137 return true; |
138 | 138 |
139 MD5Digest downloaded_image_checksum; | 139 base::MD5Digest downloaded_image_checksum; |
140 GetImageCheckSum(image, &downloaded_image_checksum); | 140 GetImageCheckSum(image, &downloaded_image_checksum); |
141 | 141 |
142 // Update icon if checksums are not equal. | 142 // Update icon if checksums are not equal. |
143 return memcmp(&persisted_image_checksum, &downloaded_image_checksum, | 143 return memcmp(&persisted_image_checksum, &downloaded_image_checksum, |
144 sizeof(MD5Digest)) != 0; | 144 sizeof(base::MD5Digest)) != 0; |
145 } | 145 } |
146 | 146 |
147 #endif // defined(OS_WIN) | 147 #endif // defined(OS_WIN) |
148 | 148 |
149 // Represents a task that creates web application shortcut. This runs on | 149 // Represents a task that creates web application shortcut. This runs on |
150 // file thread and schedules the callback (if any) on the calling thread | 150 // file thread and schedules the callback (if any) on the calling thread |
151 // when finished (either success or failure). | 151 // when finished (either success or failure). |
152 class CreateShortcutTask : public Task { | 152 class CreateShortcutTask : public Task { |
153 public: | 153 public: |
154 CreateShortcutTask(const FilePath& profile_path, | 154 CreateShortcutTask(const FilePath& profile_path, |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 530 |
531 #if defined(TOOLKIT_USES_GTK) | 531 #if defined(TOOLKIT_USES_GTK) |
532 std::string GetWMClassFromAppName(std::string app_name) { | 532 std::string GetWMClassFromAppName(std::string app_name) { |
533 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 533 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
534 TrimString(app_name, "_", &app_name); | 534 TrimString(app_name, "_", &app_name); |
535 return app_name; | 535 return app_name; |
536 } | 536 } |
537 #endif | 537 #endif |
538 | 538 |
539 } // namespace web_app | 539 } // namespace web_app |
OLD | NEW |