summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer/importer.h
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-06 16:28:57 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-06 16:28:57 +0000
commitf6061aeddb0c01a9c80aabf769b04c96a31f066f (patch)
tree85760537cc584c6ead179fa788047c10da618a0a /chrome/browser/importer/importer.h
parent5b137dcbe79a56673fbed5f23d3a2480270fce13 (diff)
downloadchromium_src-f6061aeddb0c01a9c80aabf769b04c96a31f066f.zip
chromium_src-f6061aeddb0c01a9c80aabf769b04c96a31f066f.tar.gz
chromium_src-f6061aeddb0c01a9c80aabf769b04c96a31f066f.tar.bz2
(please review thoroughly since this touches many moving parts).
Refactor ImporterHost as preparation for OOPprofile import. ImporterHost currently requires substantial infrastructure in order to run which we don't need or can't have in a utility process. This change splits ImporterHost into a couple of subclasses so that the profile import process can remain light weight and doesn't need to initialize Profile, etc. ImporterList: Manages the list of importers, this class will allow the utility process to locate and instantiate an importer without initializing the world. ImprterBridge/InProcessImporterBridge: Provides an abstract interface for the importers to interact with the rest of the App. The idea is to stick the IPC boundary in using this interface. There may still be some rough spots in the separation (e.g. Firefox locking and surrounding UI) but I'll sort those out in a followup CL that makes the OOP stuff work. For now I'm trying to keep these CLs as small as I can. BUG=14458 TEST=Profile import should continue to work on Windows/Linux & Mac. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=27996 Review URL: http://codereview.chromium.org/242091 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28117 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer/importer.h')
-rw-r--r--chrome/browser/importer/importer.h102
1 files changed, 26 insertions, 76 deletions
diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h
index 1b8499e..4b8739e 100644
--- a/chrome/browser/importer/importer.h
+++ b/chrome/browser/importer/importer.h
@@ -15,10 +15,12 @@
#include "base/ref_counted.h"
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
#include "chrome/browser/history/history_types.h"
+#include "chrome/browser/importer/importer_list.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_registrar.h"
#include "googleurl/src/gurl.h"
+class ImporterBridge;
class MessageLoop;
class TemplateURL;
@@ -28,22 +30,6 @@ namespace webkit_glue {
struct PasswordForm;
}
-// An enumeration of the type of browsers that we support to import
-// settings and data from them.
-enum ProfileType {
-#if defined(OS_WIN)
- MS_IE,
-#endif
- FIREFOX2,
- FIREFOX3,
-#if defined(OS_MACOSX)
- SAFARI,
-#endif
- GOOGLE_TOOLBAR5,
- // Identifies a 'bookmarks.html' file.
- BOOKMARKS_HTML
-};
-
// An enumeration of the type of data we want to import.
enum ImportItem {
NONE = 0x0000,
@@ -56,20 +42,20 @@ enum ImportItem {
ALL = 0x003f
};
-typedef struct {
+struct ProfileInfo {
std::wstring description;
ProfileType browser_type;
std::wstring source_path;
std::wstring app_path;
uint16 services_supported; // bitmap of ImportItem
-} ProfileInfo;
+};
class FirefoxProfileLock;
class Importer;
// ProfileWriter encapsulates profile for writing entries into it.
// This object must be invoked on UI thread.
-class ProfileWriter : public base::RefCounted<ProfileWriter> {
+class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> {
public:
// Used to identify how the bookmarks are added.
enum BookmarkOptions {
@@ -165,7 +151,7 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> {
// This class hosts the importers. It enumerates profiles from other
// browsers dynamically, and controls the process of importing. When
// the import process is done, ImporterHost deletes itself.
-class ImporterHost : public base::RefCounted<ImporterHost>,
+class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>,
public BookmarkModelObserver,
public NotificationObserver {
public:
@@ -264,45 +250,35 @@ class ImporterHost : public base::RefCounted<ImporterHost>,
void ImportItemEnded(ImportItem item);
void ImportEnded();
- Importer* CreateImporterByType(ProfileType type);
-
- // Returns the number of different browser profiles you can import from.
- int GetAvailableProfileCount();
+ int GetAvailableProfileCount() {
+ return importer_list_.GetAvailableProfileCount();
+ }
- // Returns the name of the profile at the 'index' slot. The profiles are
+ // Returns the name of the profile at the 'index' slot. The profiles are
// ordered such that the profile at index 0 is the likely default browser.
- std::wstring GetSourceProfileNameAt(int index) const;
+ std::wstring GetSourceProfileNameAt(int index) const {
+ return importer_list_.GetSourceProfileNameAt(index);
+ }
// Returns the ProfileInfo at the specified index. The ProfileInfo should be
// passed to StartImportSettings().
- const ProfileInfo& GetSourceProfileInfoAt(int index) const;
+ const ProfileInfo& GetSourceProfileInfoAt(int index) const {
+ return importer_list_.GetSourceProfileInfoAt(index);
+ }
+
+ // Returns the ProfileInfo with the given browser type.
+ const ProfileInfo& GetSourceProfileInfoForBrowserType(int browser_type)
+ const {
+ return importer_list_.GetSourceProfileInfoForBrowserType(browser_type);
+ }
- // Returns the ProfileInfo with the given browser type
- const ProfileInfo& GetSourceProfileInfoForBrowserType(int browser_type) const;
private:
// If we're not waiting on any model to finish loading, invokes the task_.
void InvokeTaskIfDone();
- // Detects the installed browsers and their associated profiles, then
- // stores their information in a list. It returns the list of description
- // of all profiles.
- void DetectSourceProfiles();
-
- // Helper methods for detecting available profiles.
-#if defined(OS_WIN)
- void DetectIEProfiles();
-#endif
- void DetectFirefoxProfiles();
- void DetectGoogleToolbarProfiles();
-#if defined(OS_MACOSX)
- void DetectSafariProfiles();
-#endif
-
NotificationRegistrar registrar_;
-
- // The list of profiles with the default one first.
- std::vector<ProfileInfo*> source_profiles_;
+ ImporterList importer_list_;
Observer* observer_;
scoped_refptr<ProfileWriter> writer_;
@@ -335,10 +311,8 @@ class ImporterHost : public base::RefCounted<ImporterHost>,
};
// The base class of all importers.
-class Importer : public base::RefCounted<Importer> {
+class Importer : public base::RefCountedThreadSafe<Importer> {
public:
- virtual ~Importer() { }
-
// All importers should implement this method by adding their
// import logic. And it will be run in file thread by ImporterHost.
//
@@ -347,9 +321,7 @@ class Importer : public base::RefCounted<Importer> {
// stuff have been finished.
virtual void StartImport(ProfileInfo profile_info,
uint16 items,
- ProfileWriter* writer,
- MessageLoop* delegate_loop,
- ImporterHost* host) = 0;
+ ImporterBridge* bridge) = 0;
// Cancels the import process.
virtual void Cancel() { cancelled_ = true; }
@@ -363,20 +335,6 @@ class Importer : public base::RefCounted<Importer> {
protected:
Importer();
- // Notifies the coordinator that the collection of data for the specified
- // item has begun.
- void NotifyItemStarted(ImportItem item);
-
- // Notifies the coordinator that the collection of data for the specified
- // item has completed.
- void NotifyItemEnded(ImportItem item);
-
- // Notifies the coordinator that the import operation has begun.
- void NotifyStarted();
-
- // Notifies the coordinator that the entire import operation has completed.
- void NotifyEnded();
-
// 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.
@@ -385,15 +343,7 @@ class Importer : public base::RefCounted<Importer> {
bool import_to_bookmark_bar() const { return import_to_bookmark_bar_; }
- // The importer should know the main thread so that ProfileWriter
- // will be invoked in thread instead.
- MessageLoop* main_loop_;
-
- // The message loop in which the importer operates.
- MessageLoop* delagate_loop_;
-
- // The coordinator host for this importer.
- ImporterHost* importer_host_;
+ scoped_refptr<ImporterBridge> bridge_;
private:
// True if the caller cancels the import process.