summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 15:41:22 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 15:41:22 +0000
commitc3ff93835df3f8c5a82c777ed9b50832756e656a (patch)
tree5bff4255d7bae6f187ddb01552213b2b36ba2a48
parentcde880b147c6e3cab8c19ba5541a2bb32dc1127f (diff)
downloadchromium_src-c3ff93835df3f8c5a82c777ed9b50832756e656a.zip
chromium_src-c3ff93835df3f8c5a82c777ed9b50832756e656a.tar.gz
chromium_src-c3ff93835df3f8c5a82c777ed9b50832756e656a.tar.bz2
importer: Pull out Importer util function into its own file.
BUG=None TEST=None R=mirandac@chromium.org Review URL: http://codereview.chromium.org/7401007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92854 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/importer/firefox2_importer.cc6
-rw-r--r--chrome/browser/importer/firefox3_importer.cc3
-rw-r--r--chrome/browser/importer/importer.cc36
-rw-r--r--chrome/browser/importer/importer.h9
-rw-r--r--chrome/browser/importer/importer_util.cc38
-rw-r--r--chrome/browser/importer/importer_util.h23
-rw-r--r--chrome/browser/importer/safari_importer.mm3
-rw-r--r--chrome/chrome_browser.gypi2
8 files changed, 73 insertions, 47 deletions
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc
index f929b01..6b18a5b 100644
--- a/chrome/browser/importer/firefox2_importer.cc
+++ b/chrome/browser/importer/firefox2_importer.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/importer/firefox_importer_utils.h"
#include "chrome/browser/importer/importer_bridge.h"
+#include "chrome/browser/importer/importer_util.h"
#include "chrome/browser/importer/mork_reader.h"
#include "chrome/browser/importer/nss_decryptor.h"
#include "chrome/browser/search_engines/template_url.h"
@@ -660,8 +661,9 @@ void Firefox2Importer::DataURLToFaviconUsage(
return;
history::ImportedFaviconUsage usage;
- if (!ReencodeFavicon(reinterpret_cast<const unsigned char*>(&data[0]),
- data.size(), &usage.png_data))
+ if (!importer::ReencodeFavicon(
+ reinterpret_cast<const unsigned char*>(&data[0]),
+ data.size(), &usage.png_data))
return; // Unable to decode.
// We need to make up a URL for the favicon. We use a version of the page's
diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc
index 1b12c97..fbccd93 100644
--- a/chrome/browser/importer/firefox3_importer.cc
+++ b/chrome/browser/importer/firefox3_importer.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/importer/firefox2_importer.h"
#include "chrome/browser/importer/firefox_importer_utils.h"
#include "chrome/browser/importer/importer_bridge.h"
+#include "chrome/browser/importer/importer_util.h"
#include "chrome/browser/importer/nss_decryptor.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/common/time_format.h"
@@ -569,7 +570,7 @@ void Firefox3Importer::LoadFavicons(
if (data.empty())
continue; // Data definitely invalid.
- if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data))
+ if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data))
continue; // Unable to decode.
usage.urls = i->second;
diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc
index 68a8fe9..a1133a5 100644
--- a/chrome/browser/importer/importer.cc
+++ b/chrome/browser/importer/importer.cc
@@ -5,43 +5,11 @@
#include "chrome/browser/importer/importer.h"
#include "chrome/browser/importer/importer_bridge.h"
-#include "chrome/browser/importer/importer_data_types.h"
-#include "skia/ext/image_operations.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/gfx/codec/png_codec.h"
-#include "ui/gfx/favicon_size.h"
-#include "webkit/glue/image_decoder.h"
void Importer::Cancel() {
cancelled_ = true;
}
-Importer::Importer() : cancelled_(false) {
-}
-
-Importer::~Importer() {
-}
+Importer::Importer() : cancelled_(false) {}
-// static
-bool Importer::ReencodeFavicon(const unsigned char* src_data,
- size_t src_len,
- std::vector<unsigned char>* png_data) {
- // Decode the favicon using WebKit's image decoder.
- webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize));
- SkBitmap decoded = decoder.Decode(src_data, src_len);
- if (decoded.empty())
- return false; // Unable to decode.
-
- if (decoded.width() != kFaviconSize || decoded.height() != kFaviconSize) {
- // The bitmap is not the correct size, re-sample.
- int new_width = decoded.width();
- int new_height = decoded.height();
- calc_favicon_target_size(&new_width, &new_height);
- decoded = skia::ImageOperations::Resize(
- decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height);
- }
-
- // Encode our bitmap as a PNG.
- gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data);
- return true;
-}
+Importer::~Importer() {}
diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h
index b4a5b6e..d43b1b7 100644
--- a/chrome/browser/importer/importer.h
+++ b/chrome/browser/importer/importer.h
@@ -9,8 +9,6 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
-#include <vector>
-
class ImporterBridge;
namespace importer {
@@ -39,13 +37,6 @@ class Importer : public base::RefCountedThreadSafe<Importer> {
Importer();
virtual ~Importer();
- // Given raw image data, decodes the icon, re-sampling to the correct size as
- // necessary, and re-encodes as PNG data in the given output vector. Returns
- // true on success.
- static bool ReencodeFavicon(const unsigned char* src_data,
- size_t src_len,
- std::vector<unsigned char>* png_data);
-
scoped_refptr<ImporterBridge> bridge_;
private:
diff --git a/chrome/browser/importer/importer_util.cc b/chrome/browser/importer/importer_util.cc
new file mode 100644
index 0000000..a5484c0
--- /dev/null
+++ b/chrome/browser/importer/importer_util.cc
@@ -0,0 +1,38 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/importer/importer_util.h"
+
+#include "skia/ext/image_operations.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/favicon_size.h"
+#include "webkit/glue/image_decoder.h"
+
+namespace importer {
+
+bool ReencodeFavicon(const unsigned char* src_data,
+ size_t src_len,
+ std::vector<unsigned char>* png_data) {
+ // Decode the favicon using WebKit's image decoder.
+ webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize));
+ SkBitmap decoded = decoder.Decode(src_data, src_len);
+ if (decoded.empty())
+ return false; // Unable to decode.
+
+ if (decoded.width() != kFaviconSize || decoded.height() != kFaviconSize) {
+ // The bitmap is not the correct size, re-sample.
+ int new_width = decoded.width();
+ int new_height = decoded.height();
+ calc_favicon_target_size(&new_width, &new_height);
+ decoded = skia::ImageOperations::Resize(
+ decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height);
+ }
+
+ // Encode our bitmap as a PNG.
+ gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data);
+ return true;
+}
+
+} // namespace importer
diff --git a/chrome/browser/importer/importer_util.h b/chrome/browser/importer/importer_util.h
new file mode 100644
index 0000000..9c76efe
--- /dev/null
+++ b/chrome/browser/importer/importer_util.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_IMPORTER_IMPORTER_UTIL_H_
+#define CHROME_BROWSER_IMPORTER_IMPORTER_UTIL_H_
+#pragma once
+
+#include <cstddef>
+#include <vector>
+
+namespace importer {
+
+// Given raw image data, decodes the icon, re-sampling to the correct size as
+// necessary, and re-encodes as PNG data in the given output vector. Returns
+// true on success.
+bool ReencodeFavicon(const unsigned char* src_data,
+ size_t src_len,
+ std::vector<unsigned char>* png_data);
+
+} // namespace importer
+
+#endif // CHROME_BROWSER_IMPORTER_IMPORTER_UTIL_H_
diff --git a/chrome/browser/importer/safari_importer.mm b/chrome/browser/importer/safari_importer.mm
index bdd0309..f4bbfd1 100644
--- a/chrome/browser/importer/safari_importer.mm
+++ b/chrome/browser/importer/safari_importer.mm
@@ -19,6 +19,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/importer/importer_bridge.h"
+#include "chrome/browser/importer/importer_util.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
@@ -179,7 +180,7 @@ void SafariImporter::LoadFaviconData(
if (data.empty())
continue; // Data definitely invalid.
- if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data))
+ if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data))
continue; // Unable to decode.
usage.urls = i->second;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 29c8863..685e0df 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1287,6 +1287,8 @@
'browser/importer/importer_progress_observer.h',
'browser/importer/importer_type.cc',
'browser/importer/importer_type.h',
+ 'browser/importer/importer_util.cc',
+ 'browser/importer/importer_util.h',
'browser/importer/in_process_importer_bridge.cc',
'browser/importer/in_process_importer_bridge.h',
'browser/importer/mork_reader.cc',