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

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

Issue 2961713002: [Cleanup] Migrate ImporterList to use the TaskScheduler API. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « chrome/browser/importer/importer_list.h ('k') | no next file » | 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/task_scheduler/post_task.h"
11 #include "base/task_scheduler/task_traits.h"
12 #include "base/threading/thread_restrictions.h"
10 #include "build/build_config.h" 13 #include "build/build_config.h"
11 #include "chrome/browser/shell_integration.h" 14 #include "chrome/browser/shell_integration.h"
12 #include "chrome/common/importer/firefox_importer_utils.h" 15 #include "chrome/common/importer/firefox_importer_utils.h"
13 #include "chrome/common/importer/importer_bridge.h" 16 #include "chrome/common/importer/importer_bridge.h"
14 #include "chrome/common/importer/importer_data_types.h" 17 #include "chrome/common/importer/importer_data_types.h"
15 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
18 20
19 #if defined(OS_MACOSX) 21 #if defined(OS_MACOSX)
20 #include <CoreFoundation/CoreFoundation.h> 22 #include <CoreFoundation/CoreFoundation.h>
21 23
22 #include "base/mac/foundation_util.h" 24 #include "base/mac/foundation_util.h"
23 #include "chrome/common/importer/safari_importer_utils.h" 25 #include "chrome/common/importer/safari_importer_utils.h"
24 #endif 26 #endif
25 27
26 #if defined(OS_WIN) 28 #if defined(OS_WIN)
27 #include "chrome/common/importer/edge_importer_utils_win.h" 29 #include "chrome/common/importer/edge_importer_utils_win.h"
28 #endif 30 #endif
29 31
30 using content::BrowserThread;
31
32 namespace { 32 namespace {
33 33
34 #if defined(OS_WIN) 34 #if defined(OS_WIN)
35 void DetectIEProfiles(std::vector<importer::SourceProfile>* profiles) { 35 void DetectIEProfiles(std::vector<importer::SourceProfile>* profiles) {
36 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 36 base::ThreadRestrictions::AssertIOAllowed();
37
37 // IE always exists and doesn't have multiple profiles. 38 // IE always exists and doesn't have multiple profiles.
38 importer::SourceProfile ie; 39 importer::SourceProfile ie;
39 ie.importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_IE); 40 ie.importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_IE);
40 ie.importer_type = importer::TYPE_IE; 41 ie.importer_type = importer::TYPE_IE;
41 ie.services_supported = importer::HISTORY | importer::FAVORITES | 42 ie.services_supported = importer::HISTORY | importer::FAVORITES |
42 importer::COOKIES | importer::PASSWORDS | 43 importer::COOKIES | importer::PASSWORDS |
43 importer::SEARCH_ENGINES; 44 importer::SEARCH_ENGINES;
44 profiles->push_back(ie); 45 profiles->push_back(ie);
45 } 46 }
46 47
(...skipping 11 matching lines...) Expand all
58 // Make the assumption on Windows 10 that Edge exists and is probably default. 59 // Make the assumption on Windows 10 that Edge exists and is probably default.
59 if (importer::EdgeImporterCanImport()) 60 if (importer::EdgeImporterCanImport())
60 DetectEdgeProfiles(profiles); 61 DetectEdgeProfiles(profiles);
61 DetectIEProfiles(profiles); 62 DetectIEProfiles(profiles);
62 } 63 }
63 64
64 #endif // defined(OS_WIN) 65 #endif // defined(OS_WIN)
65 66
66 #if defined(OS_MACOSX) 67 #if defined(OS_MACOSX)
67 void DetectSafariProfiles(std::vector<importer::SourceProfile>* profiles) { 68 void DetectSafariProfiles(std::vector<importer::SourceProfile>* profiles) {
68 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 69 base::ThreadRestrictions::AssertIOAllowed();
70
69 uint16_t items = importer::NONE; 71 uint16_t items = importer::NONE;
70 if (!SafariImporterCanImport(base::mac::GetUserLibraryPath(), &items)) 72 if (!SafariImporterCanImport(base::mac::GetUserLibraryPath(), &items))
71 return; 73 return;
72 74
73 importer::SourceProfile safari; 75 importer::SourceProfile safari;
74 safari.importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_SAFARI); 76 safari.importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_SAFARI);
75 safari.importer_type = importer::TYPE_SAFARI; 77 safari.importer_type = importer::TYPE_SAFARI;
76 safari.services_supported = items; 78 safari.services_supported = items;
77 profiles->push_back(safari); 79 profiles->push_back(safari);
78 } 80 }
79 #endif // defined(OS_MACOSX) 81 #endif // defined(OS_MACOSX)
80 82
81 // |locale|: The application locale used for lookups in Firefox's 83 // |locale|: The application locale used for lookups in Firefox's
82 // locale-specific search engines feature (see firefox_importer.cc for 84 // locale-specific search engines feature (see firefox_importer.cc for
83 // details). 85 // details).
84 void DetectFirefoxProfiles(const std::string locale, 86 void DetectFirefoxProfiles(const std::string locale,
85 std::vector<importer::SourceProfile>* profiles) { 87 std::vector<importer::SourceProfile>* profiles) {
86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 88 base::ThreadRestrictions::AssertIOAllowed();
89
87 base::FilePath profile_path = GetFirefoxProfilePath(); 90 base::FilePath profile_path = GetFirefoxProfilePath();
88 if (profile_path.empty()) 91 if (profile_path.empty())
89 return; 92 return;
90 93
91 // Detects which version of Firefox is installed. 94 // Detects which version of Firefox is installed.
92 importer::ImporterType firefox_type; 95 importer::ImporterType firefox_type;
93 base::FilePath app_path; 96 base::FilePath app_path;
94 int version = 0; 97 int version = 0;
95 #if defined(OS_WIN) 98 #if defined(OS_WIN)
96 version = GetCurrentFirefoxMajorVersionFromRegistry(); 99 version = GetCurrentFirefoxMajorVersionFromRegistry();
(...skipping 20 matching lines...) Expand all
117 firefox.services_supported = importer::HISTORY | importer::FAVORITES | 120 firefox.services_supported = importer::HISTORY | importer::FAVORITES |
118 importer::PASSWORDS | importer::SEARCH_ENGINES | 121 importer::PASSWORDS | importer::SEARCH_ENGINES |
119 importer::AUTOFILL_FORM_DATA; 122 importer::AUTOFILL_FORM_DATA;
120 firefox.locale = locale; 123 firefox.locale = locale;
121 profiles->push_back(firefox); 124 profiles->push_back(firefox);
122 } 125 }
123 126
124 std::vector<importer::SourceProfile> DetectSourceProfilesWorker( 127 std::vector<importer::SourceProfile> DetectSourceProfilesWorker(
125 const std::string& locale, 128 const std::string& locale,
126 bool include_interactive_profiles) { 129 bool include_interactive_profiles) {
127 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 130 base::ThreadRestrictions::AssertIOAllowed();
128 131
129 std::vector<importer::SourceProfile> profiles; 132 std::vector<importer::SourceProfile> profiles;
130 133
131 // The first run import will automatically take settings from the first 134 // The first run import will automatically take settings from the first
132 // profile detected, which should be the user's current default. 135 // profile detected, which should be the user's current default.
133 #if defined(OS_WIN) 136 #if defined(OS_WIN)
134 if (shell_integration::IsFirefoxDefaultBrowser()) { 137 if (shell_integration::IsFirefoxDefaultBrowser()) {
135 DetectFirefoxProfiles(locale, &profiles); 138 DetectFirefoxProfiles(locale, &profiles);
136 DetectBuiltinWindowsProfiles(&profiles); 139 DetectBuiltinWindowsProfiles(&profiles);
137 } else { 140 } else {
(...skipping 20 matching lines...) Expand all
158 profiles.push_back(bookmarks_profile); 161 profiles.push_back(bookmarks_profile);
159 } 162 }
160 163
161 return profiles; 164 return profiles;
162 } 165 }
163 166
164 } // namespace 167 } // namespace
165 168
166 ImporterList::ImporterList() 169 ImporterList::ImporterList()
167 : weak_ptr_factory_(this) { 170 : weak_ptr_factory_(this) {
168 DCHECK_CURRENTLY_ON(BrowserThread::UI);
169 } 171 }
170 172
171 ImporterList::~ImporterList() { 173 ImporterList::~ImporterList() {
172 DCHECK_CURRENTLY_ON(BrowserThread::UI); 174 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
173 } 175 }
174 176
175 void ImporterList::DetectSourceProfiles( 177 void ImporterList::DetectSourceProfiles(
176 const std::string& locale, 178 const std::string& locale,
177 bool include_interactive_profiles, 179 bool include_interactive_profiles,
178 const base::Closure& profiles_loaded_callback) { 180 const base::Closure& profiles_loaded_callback) {
179 DCHECK_CURRENTLY_ON(BrowserThread::UI); 181 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
180 BrowserThread::PostTaskAndReplyWithResult( 182 base::PostTaskWithTraitsAndReplyWithResult(
181 BrowserThread::FILE,
182 FROM_HERE, 183 FROM_HERE,
183 base::Bind(&DetectSourceProfilesWorker, 184 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
184 locale, 185 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
186 base::Bind(&DetectSourceProfilesWorker, locale,
185 include_interactive_profiles), 187 include_interactive_profiles),
186 base::Bind(&ImporterList::SourceProfilesLoaded, 188 base::Bind(&ImporterList::SourceProfilesLoaded,
187 weak_ptr_factory_.GetWeakPtr(), 189 weak_ptr_factory_.GetWeakPtr(), profiles_loaded_callback));
188 profiles_loaded_callback));
189 } 190 }
190 191
191 const importer::SourceProfile& ImporterList::GetSourceProfileAt( 192 const importer::SourceProfile& ImporterList::GetSourceProfileAt(
192 size_t index) const { 193 size_t index) const {
193 DCHECK_LT(index, count()); 194 DCHECK_LT(index, count());
194 return source_profiles_[index]; 195 return source_profiles_[index];
195 } 196 }
196 197
197 void ImporterList::SourceProfilesLoaded( 198 void ImporterList::SourceProfilesLoaded(
198 const base::Closure& profiles_loaded_callback, 199 const base::Closure& profiles_loaded_callback,
199 const std::vector<importer::SourceProfile>& profiles) { 200 const std::vector<importer::SourceProfile>& profiles) {
200 DCHECK_CURRENTLY_ON(BrowserThread::UI); 201 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
201 202
202 source_profiles_.assign(profiles.begin(), profiles.end()); 203 source_profiles_.assign(profiles.begin(), profiles.end());
203 profiles_loaded_callback.Run(); 204 profiles_loaded_callback.Run();
204 } 205 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/importer_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698