- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / importer / external_process_importer_host.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_
6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
14 #include "chrome/browser/importer/importer_progress_observer.h"
15 #include "chrome/browser/importer/profile_writer.h"
16 #include "chrome/browser/search_engines/template_url_service.h"
17 #include "chrome/common/importer/importer_data_types.h"
18 #include "ui/gfx/native_widget_types.h"
19
20 class ExternalProcessImporterClient;
21 class FirefoxProfileLock;
22 class Importer;
23 class Profile;
24
25 namespace importer {
26 struct SourceProfile;
27 }
28
29 // This class manages the import process. It creates the in-process half of the
30 // importer bridge and the external process importer client.
31 class ExternalProcessImporterHost : public BaseBookmarkModelObserver {
32  public:
33   ExternalProcessImporterHost();
34
35   void Cancel();
36
37   // Starts the process of importing the settings and data depending on what the
38   // user selected.
39   // |source_profile| - importer profile to import.
40   // |target_profile| - profile to import into.
41   // |items| - specifies which data to import (bitmask of importer::ImportItem).
42   // |writer| - called to actually write data back to the profile.
43   virtual void StartImportSettings(
44       const importer::SourceProfile& source_profile,
45       Profile* target_profile,
46       uint16 items,
47       ProfileWriter* writer);
48
49   // When in headless mode, the importer will not show any warning dialog if
50   // a user action is required (e.g., Firefox profile is locked and user should
51   // close Firefox to continue) and the outcome is as if the user had canceled
52   // the import operation.
53   void set_headless() { headless_ = true; }
54   bool is_headless() const { return headless_; }
55
56   void set_parent_window(gfx::NativeWindow parent_window) {
57     parent_window_ = parent_window;
58   }
59
60   void set_observer(importer::ImporterProgressObserver* observer) {
61     observer_ = observer;
62   }
63
64   // A series of functions invoked at the start, during and end of the import
65   // process. The middle functions are notifications that the a harvesting of a
66   // particular source of data (specified by |item|) is under way.
67   void NotifyImportStarted();
68   void NotifyImportItemStarted(importer::ImportItem item);
69   void NotifyImportItemEnded(importer::ImportItem item);
70   void NotifyImportEnded();
71
72  private:
73   // ExternalProcessImporterHost deletes itself in OnImportEnded().
74   virtual ~ExternalProcessImporterHost();
75
76   // Launches the utility process that starts the import task, unless bookmark
77   // or template model are not yet loaded. If load is not detected, this method
78   // will be called when the loading observer sees that model loading is
79   // complete.
80   virtual void LaunchImportIfReady();
81
82   // BaseBookmarkModelObserver:
83   virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
84   virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
85   virtual void BookmarkModelChanged() OVERRIDE;
86
87   // Called when TemplateURLService has been loaded.
88   void OnTemplateURLServiceLoaded();
89
90   // ShowWarningDialog() asks user to close the application that is owning the
91   // lock. They can retry or skip the importing process.
92   // This method should not be called if the importer is in headless mode.
93   void ShowWarningDialog();
94
95   // This is called when when user ends the lock dialog by clicking on either
96   // the "Skip" or "Continue" buttons. |is_continue| is true when user clicked
97   // the "Continue" button.
98   void OnImportLockDialogEnd(bool is_continue);
99
100   // Make sure that Firefox isn't running, if import browser is Firefox. Show
101   // to the user a dialog that notifies that is necessary to close Firefox
102   // prior to continue.
103   // |source_profile| - importer profile to import.
104   // Returns false iff import should be aborted.
105   bool CheckForFirefoxLock(const importer::SourceProfile& source_profile);
106
107   // Make sure BookmarkModel and TemplateURLService are loaded before import
108   // process starts, if bookmarks and/or search engines are among the items
109   // which are to be imported.
110   void CheckForLoadedModels(uint16 items);
111
112   // True if UI is not to be shown.
113   bool headless_;
114
115   // Parent window that we pass to the import lock dialog (i.e, the Firefox
116   // warning dialog).
117   gfx::NativeWindow parent_window_;
118
119   // The observer that we need to notify about changes in the import process.
120   importer::ImporterProgressObserver* observer_;
121
122   // Firefox profile lock.
123   scoped_ptr<FirefoxProfileLock> firefox_lock_;
124
125   // Profile we're importing from.
126   Profile* profile_;
127
128   // True if we're waiting for the model to finish loading.
129   bool waiting_for_bookmarkbar_model_;
130
131   // May contain a Subscription waiting for the TemplateURLService to finish
132   // loading.
133   scoped_ptr<TemplateURLService::Subscription> template_service_subscription_;
134
135   // Have we installed a listener on the bookmark model?
136   bool installed_bookmark_observer_;
137
138   // True if source profile is readable.
139   bool is_source_readable_;
140
141   // Writes data from the importer back to the profile.
142   scoped_refptr<ProfileWriter> writer_;
143
144   // Used to pass notifications from the browser side to the external process.
145   ExternalProcessImporterClient* client_;
146
147   // Information about a profile needed for importing.
148   importer::SourceProfile source_profile_;
149
150   // Bitmask of items to be imported (see importer::ImportItem enum).
151   uint16 items_;
152
153   // True if the import process has been cancelled.
154   bool cancelled_;
155
156   // True if the import process has been launched. This prevents race
157   // conditions on import cancel.
158   bool import_process_launched_;
159
160   // Vends weak pointers for the importer to call us back.
161   base::WeakPtrFactory<ExternalProcessImporterHost> weak_ptr_factory_;
162
163   DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterHost);
164 };
165
166 #endif  // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_