Home | History | Annotate | Download | only in options
      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_UI_WEBUI_OPTIONS_IMPORT_DATA_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_IMPORT_DATA_HANDLER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "chrome/browser/importer/importer_list_observer.h"
     12 #include "chrome/browser/importer/importer_progress_observer.h"
     13 #include "chrome/browser/ui/webui/options/options_ui.h"
     14 #include "chrome/common/importer/importer_data_types.h"
     15 #include "ui/shell_dialogs/select_file_dialog.h"
     16 
     17 class ExternalProcessImporterHost;
     18 class ImporterList;
     19 
     20 namespace options {
     21 
     22 // Chrome personal stuff import data overlay UI handler.
     23 class ImportDataHandler : public OptionsPageUIHandler,
     24                           public importer::ImporterListObserver,
     25                           public importer::ImporterProgressObserver,
     26                           public ui::SelectFileDialog::Listener {
     27  public:
     28   ImportDataHandler();
     29   virtual ~ImportDataHandler();
     30 
     31   // OptionsPageUIHandler:
     32   virtual void GetLocalizedValues(
     33       base::DictionaryValue* localized_strings) OVERRIDE;
     34   virtual void InitializeHandler() OVERRIDE;
     35   virtual void InitializePage() OVERRIDE;
     36 
     37   // content::WebUIMessageHandler:
     38   virtual void RegisterMessages() OVERRIDE;
     39 
     40  private:
     41   void StartImport(const importer::SourceProfile& source_profile,
     42                    uint16 imported_items);
     43 
     44   void ImportData(const base::ListValue* args);
     45 
     46   // importer::ImporterListObserver:
     47   virtual void OnSourceProfilesLoaded() OVERRIDE;
     48 
     49   // importer::ImporterProgressObserver:
     50   virtual void ImportStarted() OVERRIDE;
     51   virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE;
     52   virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE;
     53   virtual void ImportEnded() OVERRIDE;
     54 
     55   // ui::SelectFileDialog::Listener:
     56   virtual void FileSelected(const base::FilePath& path,
     57                             int index,
     58                             void* params) OVERRIDE;
     59 
     60   // Opens a file selection dialog to choose the bookmarks HTML file.
     61   void HandleChooseBookmarksFile(const base::ListValue* args);
     62 
     63   scoped_refptr<ImporterList> importer_list_;
     64 
     65   // If non-null it means importing is in progress. ImporterHost takes care
     66   // of deleting itself when import is complete.
     67   ExternalProcessImporterHost* importer_host_;  // weak
     68 
     69   bool import_did_succeed_;
     70 
     71   scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
     72 
     73   DISALLOW_COPY_AND_ASSIGN(ImportDataHandler);
     74 };
     75 
     76 }  // namespace options
     77 
     78 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_IMPORT_DATA_HANDLER_H_
     79