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

Side by Side Diff: chrome/browser/importer/importer_list.cc

Issue 1492663006: Improved handling of importer profile creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing header file Created 5 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
« no previous file with comments | « chrome/browser/importer/importer_list.h ('k') | chrome/utility/importer/importer_creator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/importer/importer_list.h" 5 #include "chrome/browser/importer/importer_list.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/shell_integration.h" 8 #include "chrome/browser/shell_integration.h"
9 #include "chrome/common/importer/firefox_importer_utils.h" 9 #include "chrome/common/importer/firefox_importer_utils.h"
10 #include "chrome/common/importer/importer_bridge.h" 10 #include "chrome/common/importer/importer_bridge.h"
(...skipping 11 matching lines...) Expand all
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 #include "chrome/common/importer/edge_importer_utils_win.h" 24 #include "chrome/common/importer/edge_importer_utils_win.h"
25 #endif 25 #endif
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 28
29 namespace { 29 namespace {
30 30
31 #if defined(OS_WIN) 31 #if defined(OS_WIN)
32 void DetectIEProfiles(std::vector<importer::SourceProfile*>* profiles) { 32 void DetectIEProfiles(std::vector<importer::SourceProfile>* profiles) {
33 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 33 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
34 // IE always exists and doesn't have multiple profiles. 34 // IE always exists and doesn't have multiple profiles.
35 importer::SourceProfile* ie = new importer::SourceProfile; 35 importer::SourceProfile ie;
36 ie->importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_IE); 36 ie.importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_IE);
37 ie->importer_type = importer::TYPE_IE; 37 ie.importer_type = importer::TYPE_IE;
38 ie->source_path.clear(); 38 ie.services_supported = importer::HISTORY | importer::FAVORITES |
39 ie->app_path.clear(); 39 importer::COOKIES | importer::PASSWORDS |
40 ie->services_supported = importer::HISTORY | importer::FAVORITES | 40 importer::SEARCH_ENGINES;
41 importer::COOKIES | importer::PASSWORDS | importer::SEARCH_ENGINES;
42 profiles->push_back(ie); 41 profiles->push_back(ie);
43 } 42 }
44 43
45 void DetectEdgeProfiles(std::vector<importer::SourceProfile*>* profiles) { 44 void DetectEdgeProfiles(std::vector<importer::SourceProfile>* profiles) {
46 importer::SourceProfile* edge = new importer::SourceProfile; 45 importer::SourceProfile edge;
47 edge->importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_EDGE); 46 edge.importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_EDGE);
48 edge->importer_type = importer::TYPE_EDGE; 47 edge.importer_type = importer::TYPE_EDGE;
49 edge->services_supported = importer::FAVORITES; 48 edge.services_supported = importer::FAVORITES;
50 edge->source_path = importer::GetEdgeDataFilePath(); 49 edge.source_path = importer::GetEdgeDataFilePath();
51 profiles->push_back(edge); 50 profiles->push_back(edge);
52 } 51 }
53 52
54 void DetectBuiltinWindowsProfiles( 53 void DetectBuiltinWindowsProfiles(
55 std::vector<importer::SourceProfile*>* profiles) { 54 std::vector<importer::SourceProfile>* profiles) {
56 // Make the assumption on Windows 10 that Edge exists and is probably default. 55 // Make the assumption on Windows 10 that Edge exists and is probably default.
57 if (importer::EdgeImporterCanImport()) 56 if (importer::EdgeImporterCanImport())
58 DetectEdgeProfiles(profiles); 57 DetectEdgeProfiles(profiles);
59 DetectIEProfiles(profiles); 58 DetectIEProfiles(profiles);
60 } 59 }
61 60
62 #endif // defined(OS_WIN) 61 #endif // defined(OS_WIN)
63 62
64 #if defined(OS_MACOSX) 63 #if defined(OS_MACOSX)
65 void DetectSafariProfiles(std::vector<importer::SourceProfile*>* profiles) { 64 void DetectSafariProfiles(std::vector<importer::SourceProfile>* profiles) {
66 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 65 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
67 uint16 items = importer::NONE; 66 uint16 items = importer::NONE;
68 if (!SafariImporterCanImport(base::mac::GetUserLibraryPath(), &items)) 67 if (!SafariImporterCanImport(base::mac::GetUserLibraryPath(), &items))
69 return; 68 return;
70 69
71 importer::SourceProfile* safari = new importer::SourceProfile; 70 importer::SourceProfile safari;
72 safari->importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_SAFARI); 71 safari.importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_SAFARI);
73 safari->importer_type = importer::TYPE_SAFARI; 72 safari.importer_type = importer::TYPE_SAFARI;
74 safari->source_path.clear(); 73 safari.services_supported = items;
75 safari->app_path.clear();
76 safari->services_supported = items;
77 profiles->push_back(safari); 74 profiles->push_back(safari);
78 } 75 }
79 #endif // defined(OS_MACOSX) 76 #endif // defined(OS_MACOSX)
80 77
81 // |locale|: The application locale used for lookups in Firefox's 78 // |locale|: The application locale used for lookups in Firefox's
82 // locale-specific search engines feature (see firefox_importer.cc for 79 // locale-specific search engines feature (see firefox_importer.cc for
83 // details). 80 // details).
84 void DetectFirefoxProfiles(const std::string locale, 81 void DetectFirefoxProfiles(const std::string locale,
85 std::vector<importer::SourceProfile*>* profiles) { 82 std::vector<importer::SourceProfile>* profiles) {
86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 83 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
87 base::FilePath profile_path = GetFirefoxProfilePath(); 84 base::FilePath profile_path = GetFirefoxProfilePath();
88 if (profile_path.empty()) 85 if (profile_path.empty())
89 return; 86 return;
90 87
91 // Detects which version of Firefox is installed. 88 // Detects which version of Firefox is installed.
92 importer::ImporterType firefox_type; 89 importer::ImporterType firefox_type;
93 base::FilePath app_path; 90 base::FilePath app_path;
94 int version = 0; 91 int version = 0;
95 #if defined(OS_WIN) 92 #if defined(OS_WIN)
96 version = GetCurrentFirefoxMajorVersionFromRegistry(); 93 version = GetCurrentFirefoxMajorVersionFromRegistry();
97 #endif 94 #endif
98 if (version < 2) 95 if (version < 2)
99 GetFirefoxVersionAndPathFromProfile(profile_path, &version, &app_path); 96 GetFirefoxVersionAndPathFromProfile(profile_path, &version, &app_path);
100 97
101 if (version >= 3) { 98 if (version >= 3) {
102 firefox_type = importer::TYPE_FIREFOX; 99 firefox_type = importer::TYPE_FIREFOX;
103 } else { 100 } else {
104 // Ignores old versions of firefox. 101 // Ignores old versions of firefox.
105 return; 102 return;
106 } 103 }
107 104
108 importer::SourceProfile* firefox = new importer::SourceProfile; 105 importer::SourceProfile firefox;
109 firefox->importer_name = GetFirefoxImporterName(app_path); 106 firefox.importer_name = GetFirefoxImporterName(app_path);
110 firefox->importer_type = firefox_type; 107 firefox.importer_type = firefox_type;
111 firefox->source_path = profile_path; 108 firefox.source_path = profile_path;
112 #if defined(OS_WIN) 109 #if defined(OS_WIN)
113 firefox->app_path = GetFirefoxInstallPathFromRegistry(); 110 firefox.app_path = GetFirefoxInstallPathFromRegistry();
114 #endif 111 #endif
115 if (firefox->app_path.empty()) 112 if (firefox.app_path.empty())
116 firefox->app_path = app_path; 113 firefox.app_path = app_path;
117 firefox->services_supported = importer::HISTORY | importer::FAVORITES | 114 firefox.services_supported = importer::HISTORY | importer::FAVORITES |
118 importer::PASSWORDS | importer::SEARCH_ENGINES | 115 importer::PASSWORDS | importer::SEARCH_ENGINES |
119 importer::AUTOFILL_FORM_DATA; 116 importer::AUTOFILL_FORM_DATA;
120 firefox->locale = locale; 117 firefox.locale = locale;
121 profiles->push_back(firefox); 118 profiles->push_back(firefox);
122 } 119 }
123 120
124 std::vector<importer::SourceProfile*> DetectSourceProfilesWorker( 121 std::vector<importer::SourceProfile> DetectSourceProfilesWorker(
125 const std::string& locale, 122 const std::string& locale,
126 bool include_interactive_profiles) { 123 bool include_interactive_profiles) {
127 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 124 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
128 125
129 std::vector<importer::SourceProfile*> profiles; 126 std::vector<importer::SourceProfile> profiles;
130 127
131 // The first run import will automatically take settings from the first 128 // The first run import will automatically take settings from the first
132 // profile detected, which should be the user's current default. 129 // profile detected, which should be the user's current default.
133 #if defined(OS_WIN) 130 #if defined(OS_WIN)
134 if (ShellIntegration::IsFirefoxDefaultBrowser()) { 131 if (ShellIntegration::IsFirefoxDefaultBrowser()) {
135 DetectFirefoxProfiles(locale, &profiles); 132 DetectFirefoxProfiles(locale, &profiles);
136 DetectBuiltinWindowsProfiles(&profiles); 133 DetectBuiltinWindowsProfiles(&profiles);
137 } else { 134 } else {
138 DetectBuiltinWindowsProfiles(&profiles); 135 DetectBuiltinWindowsProfiles(&profiles);
139 DetectFirefoxProfiles(locale, &profiles); 136 DetectFirefoxProfiles(locale, &profiles);
140 } 137 }
141 #elif defined(OS_MACOSX) 138 #elif defined(OS_MACOSX)
142 if (ShellIntegration::IsFirefoxDefaultBrowser()) { 139 if (ShellIntegration::IsFirefoxDefaultBrowser()) {
143 DetectFirefoxProfiles(locale, &profiles); 140 DetectFirefoxProfiles(locale, &profiles);
144 DetectSafariProfiles(&profiles); 141 DetectSafariProfiles(&profiles);
145 } else { 142 } else {
146 DetectSafariProfiles(&profiles); 143 DetectSafariProfiles(&profiles);
147 DetectFirefoxProfiles(locale, &profiles); 144 DetectFirefoxProfiles(locale, &profiles);
148 } 145 }
149 #else 146 #else
150 DetectFirefoxProfiles(locale, &profiles); 147 DetectFirefoxProfiles(locale, &profiles);
151 #endif 148 #endif
152 if (include_interactive_profiles) { 149 if (include_interactive_profiles) {
153 importer::SourceProfile* bookmarks_profile = new importer::SourceProfile; 150 importer::SourceProfile bookmarks_profile;
154 bookmarks_profile->importer_name = 151 bookmarks_profile.importer_name =
155 l10n_util::GetStringUTF16(IDS_IMPORT_FROM_BOOKMARKS_HTML_FILE); 152 l10n_util::GetStringUTF16(IDS_IMPORT_FROM_BOOKMARKS_HTML_FILE);
156 bookmarks_profile->importer_type = importer::TYPE_BOOKMARKS_FILE; 153 bookmarks_profile.importer_type = importer::TYPE_BOOKMARKS_FILE;
157 bookmarks_profile->services_supported = importer::FAVORITES; 154 bookmarks_profile.services_supported = importer::FAVORITES;
158 profiles.push_back(bookmarks_profile); 155 profiles.push_back(bookmarks_profile);
159 } 156 }
160 157
161 return profiles; 158 return profiles;
162 } 159 }
163 160
164 } // namespace 161 } // namespace
165 162
166 ImporterList::ImporterList() 163 ImporterList::ImporterList()
167 : weak_ptr_factory_(this) { 164 : weak_ptr_factory_(this) {
(...skipping 16 matching lines...) Expand all
184 locale, 181 locale,
185 include_interactive_profiles), 182 include_interactive_profiles),
186 base::Bind(&ImporterList::SourceProfilesLoaded, 183 base::Bind(&ImporterList::SourceProfilesLoaded,
187 weak_ptr_factory_.GetWeakPtr(), 184 weak_ptr_factory_.GetWeakPtr(),
188 profiles_loaded_callback)); 185 profiles_loaded_callback));
189 } 186 }
190 187
191 const importer::SourceProfile& ImporterList::GetSourceProfileAt( 188 const importer::SourceProfile& ImporterList::GetSourceProfileAt(
192 size_t index) const { 189 size_t index) const {
193 DCHECK_LT(index, count()); 190 DCHECK_LT(index, count());
194 return *source_profiles_[index]; 191 return source_profiles_[index];
195 } 192 }
196 193
197 void ImporterList::SourceProfilesLoaded( 194 void ImporterList::SourceProfilesLoaded(
198 const base::Closure& profiles_loaded_callback, 195 const base::Closure& profiles_loaded_callback,
199 const std::vector<importer::SourceProfile*>& profiles) { 196 const std::vector<importer::SourceProfile>& profiles) {
200 DCHECK_CURRENTLY_ON(BrowserThread::UI); 197 DCHECK_CURRENTLY_ON(BrowserThread::UI);
201 198
202 source_profiles_.assign(profiles.begin(), profiles.end()); 199 source_profiles_.assign(profiles.begin(), profiles.end());
203 profiles_loaded_callback.Run(); 200 profiles_loaded_callback.Run();
204 } 201 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/importer_list.h ('k') | chrome/utility/importer/importer_creator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698