Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/ui/webui/options/import_data_handler.cc

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "chrome/browser/ui/webui/options/import_data_handler.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h"
14 #include "base/string_number_conversions.h"
15 #include "base/string_util.h"
16 #include "base/threading/thread_restrictions.h"
17 #include "base/utf_string_conversions.h"
18 #include "base/values.h"
19 #include "chrome/browser/importer/external_process_importer_host.h"
20 #include "chrome/browser/importer/importer_host.h"
21 #include "chrome/browser/importer/importer_list.h"
22 #include "chrome/browser/profiles/profile.h"
23 #include "content/public/browser/web_ui.h"
24 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h"
27
28 ImportDataHandler::ImportDataHandler() : importer_host_(NULL),
29 import_did_succeed_(false) {
30 }
31
32 ImportDataHandler::~ImportDataHandler() {
33 if (importer_list_)
34 importer_list_->SetObserver(NULL);
35
36 if (importer_host_)
37 importer_host_->SetObserver(NULL);
38 }
39
40 void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
41 DCHECK(localized_strings);
42
43 static OptionsStringResource resources[] = {
44 { "importFromLabel", IDS_IMPORT_FROM_LABEL },
45 { "importLoading", IDS_IMPORT_LOADING_PROFILES },
46 { "importDescription", IDS_IMPORT_ITEMS_LABEL },
47 { "importHistory", IDS_IMPORT_HISTORY_CHKBOX },
48 { "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX },
49 { "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX },
50 { "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX },
51 { "importCommit", IDS_IMPORT_COMMIT },
52 { "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND },
53 { "importSucceeded", IDS_IMPORT_SUCCEEDED },
54 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS },
55 };
56
57 RegisterStrings(localized_strings, resources, arraysize(resources));
58 RegisterTitle(localized_strings, "importDataOverlay",
59 IDS_IMPORT_SETTINGS_TITLE);
60 }
61
62 void ImportDataHandler::InitializeHandler() {
63 Profile* profile = Profile::FromWebUI(web_ui());
64 importer_list_ = new ImporterList(profile->GetRequestContext());
65 importer_list_->DetectSourceProfiles(this);
66 }
67
68 void ImportDataHandler::RegisterMessages() {
69 web_ui()->RegisterMessageCallback("importData",
70 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this)));
71 }
72
73 void ImportDataHandler::ImportData(const ListValue* args) {
74 std::string string_value;
75
76 int browser_index;
77 if (!args->GetString(0, &string_value) ||
78 !base::StringToInt(string_value, &browser_index)) {
79 NOTREACHED();
80 return;
81 }
82
83 uint16 selected_items = importer::NONE;
84 if (args->GetString(1, &string_value) && string_value == "true") {
85 selected_items |= importer::HISTORY;
86 }
87 if (args->GetString(2, &string_value) && string_value == "true") {
88 selected_items |= importer::FAVORITES;
89 }
90 if (args->GetString(3, &string_value) && string_value == "true") {
91 selected_items |= importer::PASSWORDS;
92 }
93 if (args->GetString(4, &string_value) && string_value == "true") {
94 selected_items |= importer::SEARCH_ENGINES;
95 }
96
97 const importer::SourceProfile& source_profile =
98 importer_list_->GetSourceProfileAt(browser_index);
99 uint16 supported_items = source_profile.services_supported;
100
101 uint16 import_services = (selected_items & supported_items);
102 if (import_services) {
103 base::FundamentalValue state(true);
104 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
105 state);
106 import_did_succeed_ = false;
107
108 // TODO(csilv): Out-of-process import has only been qualified on MacOS X,
109 // so we will only use it on that platform since it is required. Remove this
110 // conditional logic once oop import is qualified for Linux/Windows.
111 // http://crbug.com/22142
112 #if defined(OS_MACOSX)
113 importer_host_ = new ExternalProcessImporterHost;
114 #else
115 importer_host_ = new ImporterHost;
116 #endif
117 importer_host_->SetObserver(this);
118 Profile* profile = Profile::FromWebUI(web_ui());
119 importer_host_->StartImportSettings(source_profile, profile,
120 import_services,
121 new ProfileWriter(profile), false);
122 } else {
123 LOG(WARNING) << "There were no settings to import from '"
124 << source_profile.importer_name << "'.";
125 }
126 }
127
128 void ImportDataHandler::OnSourceProfilesLoaded() {
129 ListValue browser_profiles;
130 for (size_t i = 0; i < importer_list_->count(); ++i) {
131 const importer::SourceProfile& source_profile =
132 importer_list_->GetSourceProfileAt(i);
133 uint16 browser_services = source_profile.services_supported;
134
135 DictionaryValue* browser_profile = new DictionaryValue();
136 browser_profile->SetString("name", source_profile.importer_name);
137 browser_profile->SetInteger("index", i);
138 browser_profile->SetBoolean("history",
139 (browser_services & importer::HISTORY) != 0);
140 browser_profile->SetBoolean("favorites",
141 (browser_services & importer::FAVORITES) != 0);
142 browser_profile->SetBoolean("passwords",
143 (browser_services & importer::PASSWORDS) != 0);
144 browser_profile->SetBoolean("search",
145 (browser_services & importer::SEARCH_ENGINES) != 0);
146
147 browser_profiles.Append(browser_profile);
148 }
149
150 web_ui()->CallJavascriptFunction("ImportDataOverlay.updateSupportedBrowsers",
151 browser_profiles);
152 }
153
154 void ImportDataHandler::ImportStarted() {
155 }
156
157 void ImportDataHandler::ImportItemStarted(importer::ImportItem item) {
158 // TODO(csilv): show progress detail in the web view.
159 }
160
161 void ImportDataHandler::ImportItemEnded(importer::ImportItem item) {
162 // TODO(csilv): show progress detail in the web view.
163 import_did_succeed_ = true;
164 }
165
166 void ImportDataHandler::ImportEnded() {
167 importer_host_->SetObserver(NULL);
168 importer_host_ = NULL;
169
170 if (import_did_succeed_) {
171 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess");
172 } else {
173 base::FundamentalValue state(false);
174 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
175 state);
176 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss");
177 }
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698