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

Unified Diff: chrome/browser/web_applications/web_app_win.cc

Issue 14839008: Move .ico hashing to icon_util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: forward declare md5 stuff Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gfx/icon_util.h » ('j') | ui/gfx/icon_util.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/web_applications/web_app_win.cc
diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc
index ff5783bd0f2511eb4c649caa24d495402a266960..9764257510415a22da0902c894dd020cf220aa52 100644
--- a/chrome/browser/web_applications/web_app_win.cc
+++ b/chrome/browser/web_applications/web_app_win.cc
@@ -9,7 +9,6 @@
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h"
-#include "base/md5.h"
#include "base/path_service.h"
#include "base/stringprintf.h"
#include "base/strings/string_piece.h"
@@ -28,71 +27,6 @@
namespace {
-const base::FilePath::CharType kIconChecksumFileExt[] =
- FILE_PATH_LITERAL(".ico.md5");
-
-// Width and height of icons exported to .ico files.
-
-// Calculates checksum of an icon family using MD5.
-// The checksum is derived from all of the icons in the family.
-void GetImageCheckSum(const gfx::ImageFamily& image, base::MD5Digest* digest) {
- DCHECK(digest);
- base::MD5Context md5_context;
- base::MD5Init(&md5_context);
-
- for (gfx::ImageFamily::const_iterator it = image.begin(); it != image.end();
- ++it) {
- SkBitmap bitmap = it->AsBitmap();
-
- SkAutoLockPixels image_lock(bitmap);
- base::StringPiece image_data(
- reinterpret_cast<const char*>(bitmap.getPixels()), bitmap.getSize());
- base::MD5Update(&md5_context, image_data);
- }
-
- base::MD5Final(digest, &md5_context);
-}
-
-// Saves |image| as an |icon_file| with the checksum.
-bool SaveIconWithCheckSum(const base::FilePath& icon_file,
- const gfx::ImageFamily& image) {
- if (!IconUtil::CreateIconFileFromImageFamily(image, icon_file))
- return false;
-
- base::MD5Digest digest;
- GetImageCheckSum(image, &digest);
-
- base::FilePath cheksum_file(icon_file.ReplaceExtension(kIconChecksumFileExt));
- return file_util::WriteFile(cheksum_file,
- reinterpret_cast<const char*>(&digest),
- sizeof(digest)) == sizeof(digest);
-}
-
-// Returns true if |icon_file| is missing or different from |image|.
-bool ShouldUpdateIcon(const base::FilePath& icon_file,
- const gfx::ImageFamily& image) {
- base::FilePath checksum_file(
- icon_file.ReplaceExtension(kIconChecksumFileExt));
-
- // Returns true if icon_file or checksum file is missing.
- if (!file_util::PathExists(icon_file) ||
- !file_util::PathExists(checksum_file))
- return true;
-
- base::MD5Digest persisted_image_checksum;
- if (sizeof(persisted_image_checksum) != file_util::ReadFile(checksum_file,
- reinterpret_cast<char*>(&persisted_image_checksum),
- sizeof(persisted_image_checksum)))
- return true;
-
- base::MD5Digest downloaded_image_checksum;
- GetImageCheckSum(image, &downloaded_image_checksum);
-
- // Update icon if checksums are not equal.
- return memcmp(&persisted_image_checksum, &downloaded_image_checksum,
- sizeof(base::MD5Digest)) != 0;
-}
-
bool ShortcutIsForProfile(const base::FilePath& shortcut_file_name,
const base::FilePath& profile_path) {
string16 cmd_line_string;
@@ -142,8 +76,8 @@ namespace internals {
// is up to date or successfully updated.
bool CheckAndSaveIcon(const base::FilePath& icon_file,
const gfx::ImageFamily& image) {
- if (ShouldUpdateIcon(icon_file, image)) {
- if (SaveIconWithCheckSum(icon_file, image)) {
+ if (IconUtil::ShouldUpdateIcon(icon_file, image)) {
+ if (IconUtil::SaveIconWithCheckSum(icon_file, image)) {
// Refresh shell's icon cache. This call is quite disruptive as user would
// see explorer rebuilding the icon cache. It would be great that we find
// a better way to achieve this.
« no previous file with comments | « no previous file | ui/gfx/icon_util.h » ('j') | ui/gfx/icon_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698