diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-09 23:14:18 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-09 23:14:18 +0000 |
commit | 78a3fb08359de3a027bc8f03aeadc58c40d42e4f (patch) | |
tree | 793f243a3e730e957fbe810155beab1aa58869cf | |
parent | d7f1cc4dfa481c96dd11272d78f38d3fceeb7d08 (diff) | |
download | chromium_src-78a3fb08359de3a027bc8f03aeadc58c40d42e4f.zip chromium_src-78a3fb08359de3a027bc8f03aeadc58c40d42e4f.tar.gz chromium_src-78a3fb08359de3a027bc8f03aeadc58c40d42e4f.tar.bz2 |
importer: Pull Importer class out on its own header file.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/6648030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77543 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/importer/firefox2_importer.h | 4 | ||||
-rw-r--r-- | chrome/browser/importer/firefox3_importer.cc | 1 | ||||
-rw-r--r-- | chrome/browser/importer/firefox3_importer.h | 3 | ||||
-rw-r--r-- | chrome/browser/importer/ie_importer.h | 3 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 50 | ||||
-rw-r--r-- | chrome/browser/importer/importer.h | 79 | ||||
-rw-r--r-- | chrome/browser/importer/importer_host.cc | 44 | ||||
-rw-r--r-- | chrome/browser/importer/importer_host.h | 61 | ||||
-rw-r--r-- | chrome/browser/importer/importer_list.cc | 3 | ||||
-rw-r--r-- | chrome/browser/importer/safari_importer.h | 5 | ||||
-rw-r--r-- | chrome/browser/importer/toolbar_importer.h | 5 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
12 files changed, 148 insertions, 112 deletions
diff --git a/chrome/browser/importer/firefox2_importer.h b/chrome/browser/importer/firefox2_importer.h index eb52f42..253e585 100644 --- a/chrome/browser/importer/firefox2_importer.h +++ b/chrome/browser/importer/firefox2_importer.h @@ -12,8 +12,10 @@ #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/gtest_prod_util.h" +#include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/importer/importer_host.h" +#include "chrome/browser/importer/profile_writer.h" +#include "googleurl/src/gurl.h" class TemplateURL; diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index 75c426a..7017eab 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -22,6 +22,7 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/sqlite_utils.h" #include "chrome/common/time_format.h" +#include "content/browser/browser_thread.h" #include "grit/generated_resources.h" #include "webkit/glue/password_form.h" diff --git a/chrome/browser/importer/firefox3_importer.h b/chrome/browser/importer/firefox3_importer.h index 2202ce3..fbe2ea5 100644 --- a/chrome/browser/importer/firefox3_importer.h +++ b/chrome/browser/importer/firefox3_importer.h @@ -14,8 +14,9 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/file_path.h" +#include "chrome/browser/history/history_types.h" +#include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/importer/importer_host.h" #include "googleurl/src/gurl.h" struct sqlite3; diff --git a/chrome/browser/importer/ie_importer.h b/chrome/browser/importer/ie_importer.h index ce291b9..3963be2 100644 --- a/chrome/browser/importer/ie_importer.h +++ b/chrome/browser/importer/ie_importer.h @@ -12,7 +12,8 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" -#include "chrome/browser/importer/importer_host.h" +#include "chrome/browser/importer/importer.h" +#include "chrome/browser/importer/profile_writer.h" class IEImporter : public Importer { public: diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc new file mode 100644 index 0000000..74b2416 --- /dev/null +++ b/chrome/browser/importer/importer.cc @@ -0,0 +1,50 @@ +// 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.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() + : import_to_bookmark_bar_(false), + bookmark_bar_disabled_(false), + cancelled_(false) { +} + +Importer::~Importer() { +} + +// 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; +} diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h new file mode 100644 index 0000000..c0aebeb --- /dev/null +++ b/chrome/browser/importer/importer.h @@ -0,0 +1,79 @@ +// 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_H_ +#define CHROME_BROWSER_IMPORTER_IMPORTER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/ref_counted.h" + +#include <vector> + +class ImporterBridge; + +namespace importer { +struct ProfileInfo; +} + +// The base class of all importers. +class Importer : public base::RefCountedThreadSafe<Importer> { + public: + // All importers should implement this method by adding their + // import logic. And it will be run in file thread by ImporterHost. + // + // Since we do async import, the importer should invoke + // ImporterHost::Finished() to notify its host that import + // stuff have been finished. + virtual void StartImport(const importer::ProfileInfo& profile_info, + uint16 items, + ImporterBridge* bridge) = 0; + + // Cancels the import process. + virtual void Cancel(); + + void set_import_to_bookmark_bar(bool import_to_bookmark_bar) { + import_to_bookmark_bar_ = import_to_bookmark_bar; + } + + void set_bookmark_bar_disabled(bool bookmark_bar_disabled) { + bookmark_bar_disabled_ = bookmark_bar_disabled; + } + + bool bookmark_bar_disabled() { return bookmark_bar_disabled_; } + bool cancelled() const { return cancelled_; } + + protected: + friend class 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); + + bool import_to_bookmark_bar() const { return import_to_bookmark_bar_; } + + scoped_refptr<ImporterBridge> bridge_; + + private: + // True if the importer is created in the first run UI. + bool import_to_bookmark_bar_; + + // Whether bookmark bar is disabled (not shown) for importer. This is set + // true during first run to prevent out of process bookmark importer from + // updating bookmark bar settings. + bool bookmark_bar_disabled_; + + // True if the caller cancels the import process. + bool cancelled_; + + DISALLOW_COPY_AND_ASSIGN(Importer); +}; + +#endif // CHROME_BROWSER_IMPORTER_IMPORTER_H_ diff --git a/chrome/browser/importer/importer_host.cc b/chrome/browser/importer/importer_host.cc index 9c04299..b860d5a 100644 --- a/chrome/browser/importer/importer_host.cc +++ b/chrome/browser/importer/importer_host.cc @@ -24,11 +24,7 @@ #include "content/browser/site_instance.h" #include "content/common/notification_source.h" #include "grit/generated_resources.h" -#include "skia/ext/image_operations.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/favicon_size.h" -#include "webkit/glue/image_decoder.h" // TODO(port): Port these files. #if defined(OS_WIN) @@ -36,46 +32,6 @@ #include "views/window/window.h" #endif -using webkit_glue::PasswordForm; - -// Importer. - -void Importer::Cancel() { cancelled_ = true; } - -Importer::Importer() - : cancelled_(false), - import_to_bookmark_bar_(false), - bookmark_bar_disabled_(false) { -} - -Importer::~Importer() { -} - -// 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; -} - -// ImporterHost. - ImporterHost::ImporterHost() : profile_(NULL), observer_(NULL), diff --git a/chrome/browser/importer/importer_host.h b/chrome/browser/importer/importer_host.h index 0736514..13555bb 100644 --- a/chrome/browser/importer/importer_host.h +++ b/chrome/browser/importer/importer_host.h @@ -373,65 +373,4 @@ class ExternalProcessImporterClient DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient); }; -// The base class of all importers. -class Importer : public base::RefCountedThreadSafe<Importer> { - public: - // All importers should implement this method by adding their - // import logic. And it will be run in file thread by ImporterHost. - // - // Since we do async import, the importer should invoke - // ImporterHost::Finished() to notify its host that import - // stuff have been finished. - virtual void StartImport(const importer::ProfileInfo& profile_info, - uint16 items, - ImporterBridge* bridge) = 0; - - // Cancels the import process. - virtual void Cancel(); - - void set_import_to_bookmark_bar(bool import_to_bookmark_bar) { - import_to_bookmark_bar_ = import_to_bookmark_bar; - } - - void set_bookmark_bar_disabled(bool bookmark_bar_disabled) { - bookmark_bar_disabled_ = bookmark_bar_disabled; - } - - bool bookmark_bar_disabled() { - return bookmark_bar_disabled_; - } - - bool cancelled() const { return cancelled_; } - - protected: - friend class 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); - - bool import_to_bookmark_bar() const { return import_to_bookmark_bar_; } - - scoped_refptr<ImporterBridge> bridge_; - - private: - // True if the caller cancels the import process. - bool cancelled_; - - // True if the importer is created in the first run UI. - bool import_to_bookmark_bar_; - - // Whether bookmark bar is disabled (not shown) for importer. This is set - // true during first run to prevent out of process bookmark importer from - // updating bookmark bar settings. - bool bookmark_bar_disabled_; - - DISALLOW_COPY_AND_ASSIGN(Importer); -}; - #endif // CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc index 121ec5f..d448be6 100644 --- a/chrome/browser/importer/importer_list.cc +++ b/chrome/browser/importer/importer_list.cc @@ -6,12 +6,13 @@ #include "base/file_util.h" #include "base/stl_util-inl.h" -#include "base/values.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/importer/firefox2_importer.h" #include "chrome/browser/importer/firefox3_importer.h" #include "chrome/browser/importer/firefox_importer_utils.h" +#include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/toolbar_importer.h" #include "chrome/browser/shell_integration.h" diff --git a/chrome/browser/importer/safari_importer.h b/chrome/browser/importer/safari_importer.h index 4bbc1cc..84d10d6a 100644 --- a/chrome/browser/importer/safari_importer.h +++ b/chrome/browser/importer/safari_importer.h @@ -14,9 +14,12 @@ #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/gtest_prod_util.h" +#include "chrome/browser/history/history_types.h" +#include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/importer/importer_host.h" +#include "chrome/browser/importer/profile_writer.h" #include "chrome/common/sqlite_utils.h" +#include "googleurl/src/gurl.h" #if __OBJC__ @class NSDictionary; diff --git a/chrome/browser/importer/toolbar_importer.h b/chrome/browser/importer/toolbar_importer.h index 608fc12..5c28a71 100644 --- a/chrome/browser/importer/toolbar_importer.h +++ b/chrome/browser/importer/toolbar_importer.h @@ -16,8 +16,9 @@ #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" #include "base/string16.h" +#include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/importer/importer_host.h" +#include "chrome/browser/importer/profile_writer.h" #include "chrome/common/net/url_fetcher.h" class ImporterBridge; @@ -28,7 +29,7 @@ class XmlReader; // exposed through the ToolbarImportUtils namespace. namespace toolbar_importer_utils { bool IsGoogleGAIACookieInstalled(); -} // namespace toolbar_importer_utils +} // Toolbar5Importer is a class which exposes the functionality needed to // communicate with the Google Toolbar v5 front-end, negotiate the download of diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5469156..7370980 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1209,6 +1209,8 @@ 'browser/importer/firefox_proxy_settings.h', 'browser/importer/ie_importer.cc', 'browser/importer/ie_importer.h', + 'browser/importer/importer.cc', + 'browser/importer/importer.h', 'browser/importer/importer_bridge.cc', 'browser/importer/importer_bridge.h', 'browser/importer/importer_data_types.cc', |