| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_ | 5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_ |
| 6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_ | 6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | 13 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
| 14 #include "chrome/browser/importer/importer_progress_observer.h" | 14 #include "chrome/browser/importer/importer_progress_observer.h" |
| 15 #include "chrome/browser/importer/profile_writer.h" | 15 #include "chrome/browser/importer/profile_writer.h" |
| 16 #include "chrome/browser/search_engines/template_url_service.h" |
| 16 #include "chrome/common/importer/importer_data_types.h" | 17 #include "chrome/common/importer/importer_data_types.h" |
| 17 #include "content/public/browser/notification_observer.h" | |
| 18 #include "content/public/browser/notification_registrar.h" | |
| 19 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 20 | 19 |
| 21 class ExternalProcessImporterClient; | 20 class ExternalProcessImporterClient; |
| 22 class FirefoxProfileLock; | 21 class FirefoxProfileLock; |
| 23 class Importer; | 22 class Importer; |
| 24 class Profile; | 23 class Profile; |
| 25 | 24 |
| 26 namespace importer { | 25 namespace importer { |
| 27 struct SourceProfile; | 26 struct SourceProfile; |
| 28 } | 27 } |
| 29 | 28 |
| 30 // This class manages the import process. It creates the in-process half of the | 29 // This class manages the import process. It creates the in-process half of the |
| 31 // importer bridge and the external process importer client. | 30 // importer bridge and the external process importer client. |
| 32 class ExternalProcessImporterHost : public BaseBookmarkModelObserver, | 31 class ExternalProcessImporterHost : public BaseBookmarkModelObserver { |
| 33 public content::NotificationObserver { | |
| 34 public: | 32 public: |
| 35 ExternalProcessImporterHost(); | 33 ExternalProcessImporterHost(); |
| 36 | 34 |
| 37 void Cancel(); | 35 void Cancel(); |
| 38 | 36 |
| 39 // Starts the process of importing the settings and data depending on what the | 37 // Starts the process of importing the settings and data depending on what the |
| 40 // user selected. | 38 // user selected. |
| 41 // |source_profile| - importer profile to import. | 39 // |source_profile| - importer profile to import. |
| 42 // |target_profile| - profile to import into. | 40 // |target_profile| - profile to import into. |
| 43 // |items| - specifies which data to import (bitmask of importer::ImportItem). | 41 // |items| - specifies which data to import (bitmask of importer::ImportItem). |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // or template model are not yet loaded. If load is not detected, this method | 77 // or template model are not yet loaded. If load is not detected, this method |
| 80 // will be called when the loading observer sees that model loading is | 78 // will be called when the loading observer sees that model loading is |
| 81 // complete. | 79 // complete. |
| 82 virtual void LaunchImportIfReady(); | 80 virtual void LaunchImportIfReady(); |
| 83 | 81 |
| 84 // BaseBookmarkModelObserver: | 82 // BaseBookmarkModelObserver: |
| 85 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; | 83 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; |
| 86 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; | 84 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; |
| 87 virtual void BookmarkModelChanged() OVERRIDE; | 85 virtual void BookmarkModelChanged() OVERRIDE; |
| 88 | 86 |
| 89 // content::NotificationObserver: | |
| 90 // Called when TemplateURLService has been loaded. | 87 // Called when TemplateURLService has been loaded. |
| 91 virtual void Observe(int type, | 88 void OnTemplateURLServiceLoaded(); |
| 92 const content::NotificationSource& source, | |
| 93 const content::NotificationDetails& details) OVERRIDE; | |
| 94 | 89 |
| 95 // ShowWarningDialog() asks user to close the application that is owning the | 90 // ShowWarningDialog() asks user to close the application that is owning the |
| 96 // lock. They can retry or skip the importing process. | 91 // lock. They can retry or skip the importing process. |
| 97 // This method should not be called if the importer is in headless mode. | 92 // This method should not be called if the importer is in headless mode. |
| 98 void ShowWarningDialog(); | 93 void ShowWarningDialog(); |
| 99 | 94 |
| 100 // This is called when when user ends the lock dialog by clicking on either | 95 // This is called when when user ends the lock dialog by clicking on either |
| 101 // the "Skip" or "Continue" buttons. |is_continue| is true when user clicked | 96 // the "Skip" or "Continue" buttons. |is_continue| is true when user clicked |
| 102 // the "Continue" button. | 97 // the "Continue" button. |
| 103 void OnImportLockDialogEnd(bool is_continue); | 98 void OnImportLockDialogEnd(bool is_continue); |
| 104 | 99 |
| 105 // Make sure that Firefox isn't running, if import browser is Firefox. Show | 100 // Make sure that Firefox isn't running, if import browser is Firefox. Show |
| 106 // to the user a dialog that notifies that is necessary to close Firefox | 101 // to the user a dialog that notifies that is necessary to close Firefox |
| 107 // prior to continue. | 102 // prior to continue. |
| 108 // |source_profile| - importer profile to import. | 103 // |source_profile| - importer profile to import. |
| 109 // Returns false iff import should be aborted. | 104 // Returns false iff import should be aborted. |
| 110 bool CheckForFirefoxLock(const importer::SourceProfile& source_profile); | 105 bool CheckForFirefoxLock(const importer::SourceProfile& source_profile); |
| 111 | 106 |
| 112 // Make sure BookmarkModel and TemplateURLService are loaded before import | 107 // Make sure BookmarkModel and TemplateURLService are loaded before import |
| 113 // process starts, if bookmarks and/or search engines are among the items | 108 // process starts, if bookmarks and/or search engines are among the items |
| 114 // which are to be imported. | 109 // which are to be imported. |
| 115 void CheckForLoadedModels(uint16 items); | 110 void CheckForLoadedModels(uint16 items); |
| 116 | 111 |
| 117 // Vends weak pointers for the importer to call us back. | |
| 118 base::WeakPtrFactory<ExternalProcessImporterHost> weak_ptr_factory_; | |
| 119 | |
| 120 // True if UI is not to be shown. | 112 // True if UI is not to be shown. |
| 121 bool headless_; | 113 bool headless_; |
| 122 | 114 |
| 123 // Parent window that we pass to the import lock dialog (i.e, the Firefox | 115 // Parent window that we pass to the import lock dialog (i.e, the Firefox |
| 124 // warning dialog). | 116 // warning dialog). |
| 125 gfx::NativeWindow parent_window_; | 117 gfx::NativeWindow parent_window_; |
| 126 | 118 |
| 127 // The observer that we need to notify about changes in the import process. | 119 // The observer that we need to notify about changes in the import process. |
| 128 importer::ImporterProgressObserver* observer_; | 120 importer::ImporterProgressObserver* observer_; |
| 129 | 121 |
| 130 // Firefox profile lock. | 122 // Firefox profile lock. |
| 131 scoped_ptr<FirefoxProfileLock> firefox_lock_; | 123 scoped_ptr<FirefoxProfileLock> firefox_lock_; |
| 132 | 124 |
| 133 // Profile we're importing from. | 125 // Profile we're importing from. |
| 134 Profile* profile_; | 126 Profile* profile_; |
| 135 | 127 |
| 136 // True if we're waiting for the model to finish loading. | 128 // True if we're waiting for the model to finish loading. |
| 137 bool waiting_for_bookmarkbar_model_; | 129 bool waiting_for_bookmarkbar_model_; |
| 138 | 130 |
| 131 // May contain a Subscription waiting for the TemplateURLService to finish |
| 132 // loading. |
| 133 scoped_ptr<TemplateURLService::Subscription> template_service_subscription_; |
| 134 |
| 139 // Have we installed a listener on the bookmark model? | 135 // Have we installed a listener on the bookmark model? |
| 140 bool installed_bookmark_observer_; | 136 bool installed_bookmark_observer_; |
| 141 | 137 |
| 142 // True if source profile is readable. | 138 // True if source profile is readable. |
| 143 bool is_source_readable_; | 139 bool is_source_readable_; |
| 144 | 140 |
| 145 // Receives notification when the TemplateURLService has loaded. | |
| 146 content::NotificationRegistrar registrar_; | |
| 147 | |
| 148 // Writes data from the importer back to the profile. | 141 // Writes data from the importer back to the profile. |
| 149 scoped_refptr<ProfileWriter> writer_; | 142 scoped_refptr<ProfileWriter> writer_; |
| 150 | 143 |
| 151 // Used to pass notifications from the browser side to the external process. | 144 // Used to pass notifications from the browser side to the external process. |
| 152 ExternalProcessImporterClient* client_; | 145 ExternalProcessImporterClient* client_; |
| 153 | 146 |
| 154 // Information about a profile needed for importing. | 147 // Information about a profile needed for importing. |
| 155 importer::SourceProfile source_profile_; | 148 importer::SourceProfile source_profile_; |
| 156 | 149 |
| 157 // Bitmask of items to be imported (see importer::ImportItem enum). | 150 // Bitmask of items to be imported (see importer::ImportItem enum). |
| 158 uint16 items_; | 151 uint16 items_; |
| 159 | 152 |
| 160 // True if the import process has been cancelled. | 153 // True if the import process has been cancelled. |
| 161 bool cancelled_; | 154 bool cancelled_; |
| 162 | 155 |
| 163 // True if the import process has been launched. This prevents race | 156 // True if the import process has been launched. This prevents race |
| 164 // conditions on import cancel. | 157 // conditions on import cancel. |
| 165 bool import_process_launched_; | 158 bool import_process_launched_; |
| 166 | 159 |
| 160 // Vends weak pointers for the importer to call us back. |
| 161 base::WeakPtrFactory<ExternalProcessImporterHost> weak_ptr_factory_; |
| 162 |
| 167 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterHost); | 163 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterHost); |
| 168 }; | 164 }; |
| 169 | 165 |
| 170 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_ | 166 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_HOST_H_ |
| OLD | NEW |