| 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 #include "chrome/browser/ui/webui/options/import_data_handler.h" | 5 #include "chrome/browser/ui/webui/options/import_data_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/importer/external_process_importer_host.h" | 20 #include "chrome/browser/importer/external_process_importer_host.h" |
| 21 #include "chrome/browser/importer/importer_host.h" | |
| 22 #include "chrome/browser/importer/importer_list.h" | 21 #include "chrome/browser/importer/importer_list.h" |
| 23 #include "chrome/browser/importer/importer_type.h" | 22 #include "chrome/browser/importer/importer_type.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
| 27 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 30 | 29 |
| 31 namespace options { | 30 namespace options { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 58 { "importSucceeded", IDS_IMPORT_SUCCEEDED }, | 57 { "importSucceeded", IDS_IMPORT_SUCCEEDED }, |
| 59 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS }, | 58 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS }, |
| 60 }; | 59 }; |
| 61 | 60 |
| 62 RegisterStrings(localized_strings, resources, arraysize(resources)); | 61 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 63 RegisterTitle(localized_strings, "importDataOverlay", | 62 RegisterTitle(localized_strings, "importDataOverlay", |
| 64 IDS_IMPORT_SETTINGS_TITLE); | 63 IDS_IMPORT_SETTINGS_TITLE); |
| 65 } | 64 } |
| 66 | 65 |
| 67 void ImportDataHandler::InitializeHandler() { | 66 void ImportDataHandler::InitializeHandler() { |
| 68 Profile* profile = Profile::FromWebUI(web_ui()); | 67 importer_list_ = new ImporterList(); |
| 69 importer_list_ = new ImporterList(profile->GetRequestContext()); | |
| 70 importer_list_->DetectSourceProfiles( | 68 importer_list_->DetectSourceProfiles( |
| 71 g_browser_process->GetApplicationLocale(), this); | 69 g_browser_process->GetApplicationLocale(), this); |
| 72 } | 70 } |
| 73 | 71 |
| 74 void ImportDataHandler::RegisterMessages() { | 72 void ImportDataHandler::RegisterMessages() { |
| 75 web_ui()->RegisterMessageCallback("importData", | 73 web_ui()->RegisterMessageCallback("importData", |
| 76 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); | 74 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); |
| 77 } | 75 } |
| 78 | 76 |
| 79 void ImportDataHandler::ImportData(const ListValue* args) { | 77 void ImportDataHandler::ImportData(const ListValue* args) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 importer_list_->GetSourceProfileAt(browser_index); | 102 importer_list_->GetSourceProfileAt(browser_index); |
| 105 uint16 supported_items = source_profile.services_supported; | 103 uint16 supported_items = source_profile.services_supported; |
| 106 | 104 |
| 107 uint16 import_services = (selected_items & supported_items); | 105 uint16 import_services = (selected_items & supported_items); |
| 108 if (import_services) { | 106 if (import_services) { |
| 109 base::FundamentalValue state(true); | 107 base::FundamentalValue state(true); |
| 110 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | 108 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", |
| 111 state); | 109 state); |
| 112 import_did_succeed_ = false; | 110 import_did_succeed_ = false; |
| 113 | 111 |
| 114 // The Google Toolbar importer doesn't work for the out-of-process import. | 112 importer_host_ = new ExternalProcessImporterHost(); |
| 115 // This is the only entry point for this importer (it is never used on first | |
| 116 // run). See discussion on http://crbug.com/219419 for details. | |
| 117 if (source_profile.importer_type == importer::TYPE_GOOGLE_TOOLBAR5) | |
| 118 importer_host_ = new ImporterHost; | |
| 119 else | |
| 120 importer_host_ = new ExternalProcessImporterHost; | |
| 121 importer_host_->SetObserver(this); | 113 importer_host_->SetObserver(this); |
| 122 importer_host_->set_browser( | |
| 123 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); | |
| 124 Profile* profile = Profile::FromWebUI(web_ui()); | 114 Profile* profile = Profile::FromWebUI(web_ui()); |
| 125 importer_host_->StartImportSettings(source_profile, profile, | 115 importer_host_->StartImportSettings(source_profile, profile, |
| 126 import_services, | 116 import_services, |
| 127 new ProfileWriter(profile)); | 117 new ProfileWriter(profile)); |
| 128 | 118 |
| 129 importer::LogImporterUseToMetrics("ImportDataHandler", | 119 importer::LogImporterUseToMetrics("ImportDataHandler", |
| 130 source_profile.importer_type); | 120 source_profile.importer_type); |
| 131 } else { | 121 } else { |
| 132 LOG(WARNING) << "There were no settings to import from '" | 122 LOG(WARNING) << "There were no settings to import from '" |
| 133 << source_profile.importer_name << "'."; | 123 << source_profile.importer_name << "'."; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); | 177 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); |
| 188 } else { | 178 } else { |
| 189 base::FundamentalValue state(false); | 179 base::FundamentalValue state(false); |
| 190 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | 180 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", |
| 191 state); | 181 state); |
| 192 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); | 182 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); |
| 193 } | 183 } |
| 194 } | 184 } |
| 195 | 185 |
| 196 } // namespace options | 186 } // namespace options |
| OLD | NEW |