| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/options2/import_data_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/import_data_handler2.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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/importer/importer_list.h" | 21 #include "chrome/browser/importer/importer_list.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "content/public/browser/web_ui.h" | 23 #include "content/public/browser/web_ui.h" |
| 24 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
| 25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 | 27 |
| 28 namespace options2 { | 28 namespace options2 { |
| 29 | 29 |
| 30 ImportDataHandler::ImportDataHandler() : importer_host_(NULL), | 30 ImportDataHandler::ImportDataHandler() : importer_host_(NULL), |
| 31 import_did_succeed_(false) { | 31 import_did_succeed_(false), |
| 32 profiles_loaded_(false) { |
| 32 } | 33 } |
| 33 | 34 |
| 34 ImportDataHandler::~ImportDataHandler() { | 35 ImportDataHandler::~ImportDataHandler() { |
| 35 if (importer_list_) | 36 if (importer_list_) |
| 36 importer_list_->SetObserver(NULL); | 37 importer_list_->SetObserver(NULL); |
| 37 | 38 |
| 38 if (importer_host_) | 39 if (importer_host_) |
| 39 importer_host_->SetObserver(NULL); | 40 importer_host_->SetObserver(NULL); |
| 40 } | 41 } |
| 41 | 42 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 RegisterStrings(localized_strings, resources, arraysize(resources)); | 60 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 60 RegisterTitle(localized_strings, "importDataOverlay", | 61 RegisterTitle(localized_strings, "importDataOverlay", |
| 61 IDS_IMPORT_SETTINGS_TITLE); | 62 IDS_IMPORT_SETTINGS_TITLE); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void ImportDataHandler::Initialize() { | 65 void ImportDataHandler::Initialize() { |
| 65 Profile* profile = Profile::FromWebUI(web_ui()); | 66 Profile* profile = Profile::FromWebUI(web_ui()); |
| 66 importer_list_ = new ImporterList(profile->GetRequestContext()); | 67 importer_list_ = new ImporterList(profile->GetRequestContext()); |
| 68 profiles_loaded_ = false; |
| 67 importer_list_->DetectSourceProfiles(this); | 69 importer_list_->DetectSourceProfiles(this); |
| 68 } | 70 } |
| 69 | 71 |
| 70 void ImportDataHandler::RegisterMessages() { | 72 void ImportDataHandler::RegisterMessages() { |
| 71 web_ui()->RegisterMessageCallback("importData", | 73 web_ui()->RegisterMessageCallback("importData", |
| 72 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); | 74 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void ImportDataHandler::ImportData(const ListValue* args) { | 77 void ImportDataHandler::ImportData(const ListValue* args) { |
| 76 std::string string_value; | 78 std::string string_value; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 importer_host_->StartImportSettings(source_profile, profile, | 123 importer_host_->StartImportSettings(source_profile, profile, |
| 122 import_services, | 124 import_services, |
| 123 new ProfileWriter(profile), false); | 125 new ProfileWriter(profile), false); |
| 124 } else { | 126 } else { |
| 125 LOG(WARNING) << "There were no settings to import from '" | 127 LOG(WARNING) << "There were no settings to import from '" |
| 126 << source_profile.importer_name << "'."; | 128 << source_profile.importer_name << "'."; |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 | 131 |
| 130 void ImportDataHandler::OnSourceProfilesLoaded() { | 132 void ImportDataHandler::OnSourceProfilesLoaded() { |
| 133 profiles_loaded_ = true; |
| 134 SendPageValues(); |
| 135 } |
| 136 |
| 137 void ImportDataHandler::SendPageValues() { |
| 138 if (!profiles_loaded_) |
| 139 return; |
| 140 |
| 131 ListValue browser_profiles; | 141 ListValue browser_profiles; |
| 132 for (size_t i = 0; i < importer_list_->count(); ++i) { | 142 for (size_t i = 0; i < importer_list_->count(); ++i) { |
| 133 const importer::SourceProfile& source_profile = | 143 const importer::SourceProfile& source_profile = |
| 134 importer_list_->GetSourceProfileAt(i); | 144 importer_list_->GetSourceProfileAt(i); |
| 135 uint16 browser_services = source_profile.services_supported; | 145 uint16 browser_services = source_profile.services_supported; |
| 136 | 146 |
| 137 DictionaryValue* browser_profile = new DictionaryValue(); | 147 DictionaryValue* browser_profile = new DictionaryValue(); |
| 138 browser_profile->SetString("name", source_profile.importer_name); | 148 browser_profile->SetString("name", source_profile.importer_name); |
| 139 browser_profile->SetInteger("index", i); | 149 browser_profile->SetInteger("index", i); |
| 140 browser_profile->SetBoolean("history", | 150 browser_profile->SetBoolean("history", |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); | 183 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); |
| 174 } else { | 184 } else { |
| 175 base::FundamentalValue state(false); | 185 base::FundamentalValue state(false); |
| 176 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | 186 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", |
| 177 state); | 187 state); |
| 178 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); | 188 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); |
| 179 } | 189 } |
| 180 } | 190 } |
| 181 | 191 |
| 182 } // namespace options2 | 192 } // namespace options2 |
| OLD | NEW |