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

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

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

Powered by Google App Engine
This is Rietveld 408576698