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

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

Issue 9693032: [uber page] Split up initialization of handlers from initialization of webui pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cros compile fix, still issues 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
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 14 matching lines...) Expand all
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 } 32 }
33 33
34 ImportDataHandler::~ImportDataHandler() { 34 ImportDataHandler::~ImportDataHandler() {
35 if (importer_list_) 35 if (importer_list_.get())
36 importer_list_->SetObserver(NULL); 36 importer_list_->SetObserver(NULL);
37 37
38 if (importer_host_) 38 if (importer_host_)
39 importer_host_->SetObserver(NULL); 39 importer_host_->SetObserver(NULL);
40 } 40 }
41 41
42 void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) { 42 void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
43 DCHECK(localized_strings); 43 DCHECK(localized_strings);
44 44
45 static OptionsStringResource resources[] = { 45 static OptionsStringResource resources[] = {
46 { "importFromLabel", IDS_IMPORT_FROM_LABEL }, 46 { "importFromLabel", IDS_IMPORT_FROM_LABEL },
47 { "importLoading", IDS_IMPORT_LOADING_PROFILES }, 47 { "importLoading", IDS_IMPORT_LOADING_PROFILES },
48 { "importDescription", IDS_IMPORT_ITEMS_LABEL }, 48 { "importDescription", IDS_IMPORT_ITEMS_LABEL },
49 { "importHistory", IDS_IMPORT_HISTORY_CHKBOX }, 49 { "importHistory", IDS_IMPORT_HISTORY_CHKBOX },
50 { "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX }, 50 { "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX },
51 { "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX }, 51 { "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX },
52 { "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX }, 52 { "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX },
53 { "importCommit", IDS_IMPORT_COMMIT }, 53 { "importCommit", IDS_IMPORT_COMMIT },
54 { "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND }, 54 { "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND },
55 { "importSucceeded", IDS_IMPORT_SUCCEEDED }, 55 { "importSucceeded", IDS_IMPORT_SUCCEEDED },
56 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS }, 56 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS },
57 }; 57 };
58 58
59 RegisterStrings(localized_strings, resources, arraysize(resources)); 59 RegisterStrings(localized_strings, resources, arraysize(resources));
60 RegisterTitle(localized_strings, "importDataOverlay", 60 RegisterTitle(localized_strings, "importDataOverlay",
61 IDS_IMPORT_SETTINGS_TITLE); 61 IDS_IMPORT_SETTINGS_TITLE);
62 } 62 }
63 63
64 void ImportDataHandler::Initialize() { 64 void ImportDataHandler::InitializeHandler() {
65 Profile* profile = Profile::FromWebUI(web_ui()); 65 Profile* profile = Profile::FromWebUI(web_ui());
66 importer_list_ = new ImporterList(profile->GetRequestContext()); 66 importer_list_ = new ImporterList(profile->GetRequestContext());
67 importer_list_->DetectSourceProfiles(this); 67 importer_list_->DetectSourceProfiles(this);
68 } 68 }
69 69
70 void ImportDataHandler::RegisterMessages() { 70 void ImportDataHandler::RegisterMessages() {
71 web_ui()->RegisterMessageCallback("importData", 71 web_ui()->RegisterMessageCallback("importData",
72 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); 72 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this)));
73 } 73 }
74 74
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 importer_host_->StartImportSettings(source_profile, profile, 121 importer_host_->StartImportSettings(source_profile, profile,
122 import_services, 122 import_services,
123 new ProfileWriter(profile), false); 123 new ProfileWriter(profile), false);
124 } else { 124 } else {
125 LOG(WARNING) << "There were no settings to import from '" 125 LOG(WARNING) << "There were no settings to import from '"
126 << source_profile.importer_name << "'."; 126 << source_profile.importer_name << "'.";
127 } 127 }
128 } 128 }
129 129
130 void ImportDataHandler::OnSourceProfilesLoaded() { 130 void ImportDataHandler::OnSourceProfilesLoaded() {
131 InitializePage();
132 }
133
134 void ImportDataHandler::InitializePage() {
135 if (!importer_list_->source_profiles_loaded())
136 return;
137
131 ListValue browser_profiles; 138 ListValue browser_profiles;
132 for (size_t i = 0; i < importer_list_->count(); ++i) { 139 for (size_t i = 0; i < importer_list_->count(); ++i) {
133 const importer::SourceProfile& source_profile = 140 const importer::SourceProfile& source_profile =
134 importer_list_->GetSourceProfileAt(i); 141 importer_list_->GetSourceProfileAt(i);
135 uint16 browser_services = source_profile.services_supported; 142 uint16 browser_services = source_profile.services_supported;
136 143
137 DictionaryValue* browser_profile = new DictionaryValue(); 144 DictionaryValue* browser_profile = new DictionaryValue();
138 browser_profile->SetString("name", source_profile.importer_name); 145 browser_profile->SetString("name", source_profile.importer_name);
139 browser_profile->SetInteger("index", i); 146 browser_profile->SetInteger("index", i);
140 browser_profile->SetBoolean("history", 147 browser_profile->SetBoolean("history",
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); 180 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess");
174 } else { 181 } else {
175 base::FundamentalValue state(false); 182 base::FundamentalValue state(false);
176 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", 183 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
177 state); 184 state);
178 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); 185 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss");
179 } 186 }
180 } 187 }
181 188
182 } // namespace options2 189 } // namespace options2
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698