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" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 void ImportDataHandler::RegisterMessages() { | 79 void ImportDataHandler::RegisterMessages() { |
80 web_ui()->RegisterMessageCallback( | 80 web_ui()->RegisterMessageCallback( |
81 "importData", | 81 "importData", |
82 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); | 82 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); |
83 web_ui()->RegisterMessageCallback( | 83 web_ui()->RegisterMessageCallback( |
84 "chooseBookmarksFile", | 84 "chooseBookmarksFile", |
85 base::Bind(&ImportDataHandler::HandleChooseBookmarksFile, | 85 base::Bind(&ImportDataHandler::HandleChooseBookmarksFile, |
86 base::Unretained(this))); | 86 base::Unretained(this))); |
87 } | 87 } |
88 | 88 |
89 void ImportDataHandler::StartImport( | |
90 const importer::SourceProfile& source_profile, | |
91 uint16 imported_items) { | |
92 if (!imported_items) | |
93 return; | |
94 | |
95 // If another import is already ongoing, let it finish silently. | |
96 if (importer_host_) | |
97 importer_host_->set_observer(NULL); | |
98 | |
99 base::FundamentalValue importing(true); | |
100 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | |
101 importing); | |
102 import_did_succeed_ = false; | |
103 | |
104 importer_host_ = new ExternalProcessImporterHost(); | |
105 importer_host_->set_observer(this); | |
106 Profile* profile = Profile::FromWebUI(web_ui()); | |
107 importer_host_->StartImportSettings(source_profile, profile, | |
108 imported_items, | |
109 new ProfileWriter(profile)); | |
110 | |
111 importer::LogImporterUseToMetrics("ImportDataHandler", | |
112 source_profile.importer_type); | |
113 } | |
114 | |
89 void ImportDataHandler::ImportData(const ListValue* args) { | 115 void ImportDataHandler::ImportData(const ListValue* args) { |
90 std::string string_value; | 116 std::string string_value; |
91 | 117 |
92 int browser_index; | 118 int browser_index; |
93 if (!args->GetString(0, &string_value) || | 119 if (!args->GetString(0, &string_value) || |
94 !base::StringToInt(string_value, &browser_index)) { | 120 !base::StringToInt(string_value, &browser_index)) { |
95 NOTREACHED(); | 121 NOTREACHED(); |
96 return; | 122 return; |
97 } | 123 } |
98 | 124 |
99 uint16 selected_items = importer::NONE; | 125 uint16 selected_items = importer::NONE; |
100 if (args->GetString(1, &string_value) && string_value == "true") { | 126 if (args->GetString(1, &string_value) && string_value == "true") { |
101 selected_items |= importer::HISTORY; | 127 selected_items |= importer::HISTORY; |
102 } | 128 } |
103 if (args->GetString(2, &string_value) && string_value == "true") { | 129 if (args->GetString(2, &string_value) && string_value == "true") { |
104 selected_items |= importer::FAVORITES; | 130 selected_items |= importer::FAVORITES; |
105 } | 131 } |
106 if (args->GetString(3, &string_value) && string_value == "true") { | 132 if (args->GetString(3, &string_value) && string_value == "true") { |
107 selected_items |= importer::PASSWORDS; | 133 selected_items |= importer::PASSWORDS; |
108 } | 134 } |
109 if (args->GetString(4, &string_value) && string_value == "true") { | 135 if (args->GetString(4, &string_value) && string_value == "true") { |
110 selected_items |= importer::SEARCH_ENGINES; | 136 selected_items |= importer::SEARCH_ENGINES; |
111 } | 137 } |
112 | 138 |
113 const importer::SourceProfile& source_profile = | 139 const importer::SourceProfile& source_profile = |
114 importer_list_->GetSourceProfileAt(browser_index); | 140 importer_list_->GetSourceProfileAt(browser_index); |
115 uint16 supported_items = source_profile.services_supported; | 141 uint16 supported_items = source_profile.services_supported; |
116 | 142 |
117 uint16 import_services = (selected_items & supported_items); | 143 uint16 imported_items = (selected_items & supported_items); |
118 if (import_services) { | 144 if (imported_items) { |
119 base::FundamentalValue state(true); | 145 StartImport(source_profile, imported_items); |
120 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | |
121 state); | |
122 import_did_succeed_ = false; | |
123 | |
124 importer_host_ = new ExternalProcessImporterHost(); | |
125 importer_host_->set_observer(this); | |
126 Profile* profile = Profile::FromWebUI(web_ui()); | |
127 importer_host_->StartImportSettings(source_profile, profile, | |
128 import_services, | |
129 new ProfileWriter(profile)); | |
130 | |
131 importer::LogImporterUseToMetrics("ImportDataHandler", | |
132 source_profile.importer_type); | |
133 } else { | 146 } else { |
134 LOG(WARNING) << "There were no settings to import from '" | 147 LOG(WARNING) << "There were no settings to import from '" |
135 << source_profile.importer_name << "'."; | 148 << source_profile.importer_name << "'."; |
136 } | 149 } |
137 } | 150 } |
138 | 151 |
139 void ImportDataHandler::OnSourceProfilesLoaded() { | 152 void ImportDataHandler::OnSourceProfilesLoaded() { |
140 InitializePage(); | 153 InitializePage(); |
141 } | 154 } |
142 | 155 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); | 209 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); |
197 } else { | 210 } else { |
198 base::FundamentalValue state(false); | 211 base::FundamentalValue state(false); |
199 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | 212 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", |
200 state); | 213 state); |
201 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); | 214 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); |
202 } | 215 } |
203 } | 216 } |
204 | 217 |
205 void ImportDataHandler::FileSelected(const base::FilePath& path, | 218 void ImportDataHandler::FileSelected(const base::FilePath& path, |
206 int index, | 219 int /* index */, |
207 void* params) { | 220 void* /* params */) { |
Evan Stade
2013/09/17 23:20:10
nit: int /*index*/
(no spaces around var name)
gab
2013/09/18 14:32:35
Done.
| |
208 base::FundamentalValue importing(true); | |
209 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | |
210 importing); | |
211 import_did_succeed_ = false; | |
212 | |
213 importer_host_ = new ExternalProcessImporterHost(); | |
214 importer_host_->set_observer(this); | |
215 | 221 |
216 importer::SourceProfile source_profile; | 222 importer::SourceProfile source_profile; |
217 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | 223 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
218 source_profile.source_path = path; | 224 source_profile.source_path = path; |
219 | 225 |
220 Profile* profile = Profile::FromWebUI(web_ui()); | 226 StartImport(source_profile, importer::FAVORITES); |
221 | |
222 importer_host_->StartImportSettings( | |
223 source_profile, profile, importer::FAVORITES, new ProfileWriter(profile)); | |
224 } | 227 } |
225 | 228 |
226 void ImportDataHandler::HandleChooseBookmarksFile(const base::ListValue* args) { | 229 void ImportDataHandler::HandleChooseBookmarksFile(const base::ListValue* args) { |
227 DCHECK(args && args->empty()); | 230 DCHECK(args && args->empty()); |
228 select_file_dialog_ = ui::SelectFileDialog::Create( | 231 select_file_dialog_ = ui::SelectFileDialog::Create( |
229 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 232 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
230 | 233 |
231 ui::SelectFileDialog::FileTypeInfo file_type_info; | 234 ui::SelectFileDialog::FileTypeInfo file_type_info; |
232 file_type_info.extensions.resize(1); | 235 file_type_info.extensions.resize(1); |
233 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); | 236 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); |
234 | 237 |
235 Browser* browser = | 238 Browser* browser = |
236 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 239 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
237 | 240 |
238 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, | 241 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, |
239 base::string16(), | 242 base::string16(), |
240 base::FilePath(), | 243 base::FilePath(), |
241 &file_type_info, | 244 &file_type_info, |
242 0, | 245 0, |
243 base::FilePath::StringType(), | 246 base::FilePath::StringType(), |
244 browser->window()->GetNativeWindow(), | 247 browser->window()->GetNativeWindow(), |
245 NULL); | 248 NULL); |
246 } | 249 } |
247 | 250 |
248 } // namespace options | 251 } // namespace options |
OLD | NEW |