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

Side by Side Diff: chrome/browser/ui/app_list/search/app_search_provider.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/app_list/search/app_search_provider.h" 5 #include "chrome/browser/ui/app_list/search/app_search_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 class AppSearchProvider::DataSource { 74 class AppSearchProvider::DataSource {
75 public: 75 public:
76 DataSource(Profile* profile, AppSearchProvider* owner) 76 DataSource(Profile* profile, AppSearchProvider* owner)
77 : profile_(profile), 77 : profile_(profile),
78 owner_(owner) {} 78 owner_(owner) {}
79 virtual ~DataSource() {} 79 virtual ~DataSource() {}
80 80
81 virtual void AddApps(Apps* apps) = 0; 81 virtual void AddApps(Apps* apps) = 0;
82 82
83 virtual scoped_ptr<AppResult> CreateResult( 83 virtual std::unique_ptr<AppResult> CreateResult(
84 const std::string& app_id, 84 const std::string& app_id,
85 AppListControllerDelegate* list_controller, 85 AppListControllerDelegate* list_controller,
86 AppListItemList* top_level_item_list, 86 AppListItemList* top_level_item_list,
87 bool is_recommended) = 0; 87 bool is_recommended) = 0;
88 88
89 protected: 89 protected:
90 Profile* profile() { return profile_; } 90 Profile* profile() { return profile_; }
91 AppSearchProvider* owner() { return owner_; } 91 AppSearchProvider* owner() { return owner_; }
92 92
93 private: 93 private:
(...skipping 17 matching lines...) Expand all
111 ~ExtensionDataSource() override {} 111 ~ExtensionDataSource() override {}
112 112
113 // AppSearchProvider::DataSource overrides: 113 // AppSearchProvider::DataSource overrides:
114 void AddApps(AppSearchProvider::Apps* apps) override { 114 void AddApps(AppSearchProvider::Apps* apps) override {
115 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 115 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
116 AddApps(apps, registry->enabled_extensions()); 116 AddApps(apps, registry->enabled_extensions());
117 AddApps(apps, registry->disabled_extensions()); 117 AddApps(apps, registry->disabled_extensions());
118 AddApps(apps, registry->terminated_extensions()); 118 AddApps(apps, registry->terminated_extensions());
119 } 119 }
120 120
121 scoped_ptr<AppResult> CreateResult( 121 std::unique_ptr<AppResult> CreateResult(
122 const std::string& app_id, 122 const std::string& app_id,
123 AppListControllerDelegate* list_controller, 123 AppListControllerDelegate* list_controller,
124 AppListItemList* top_level_item_list, 124 AppListItemList* top_level_item_list,
125 bool is_recommended) override { 125 bool is_recommended) override {
126 return scoped_ptr<AppResult>(new ExtensionAppResult(profile(), 126 return std::unique_ptr<AppResult>(new ExtensionAppResult(
127 app_id, 127 profile(), app_id, list_controller, is_recommended));
128 list_controller,
129 is_recommended));
130 } 128 }
131 129
132 // extensions::ExtensionRegistryObserver overrides: 130 // extensions::ExtensionRegistryObserver overrides:
133 void OnExtensionLoaded(content::BrowserContext* browser_context, 131 void OnExtensionLoaded(content::BrowserContext* browser_context,
134 const extensions::Extension* extension) override { 132 const extensions::Extension* extension) override {
135 owner()->RefreshAppsAndUpdateResults(false); 133 owner()->RefreshAppsAndUpdateResults(false);
136 } 134 }
137 135
138 void OnExtensionUninstalled(content::BrowserContext* browser_context, 136 void OnExtensionUninstalled(content::BrowserContext* browser_context,
139 const extensions::Extension* extension, 137 const extensions::Extension* extension,
(...skipping 12 matching lines...) Expand all
152 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, 150 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension,
153 profile())) { 151 profile())) {
154 continue; 152 continue;
155 } 153 }
156 154
157 if (profile()->IsOffTheRecord() && 155 if (profile()->IsOffTheRecord() &&
158 !extensions::util::CanLoadInIncognito(extension, profile())) { 156 !extensions::util::CanLoadInIncognito(extension, profile())) {
159 continue; 157 continue;
160 } 158 }
161 159
162 scoped_ptr<AppSearchProvider::App> app( 160 std::unique_ptr<AppSearchProvider::App> app(new AppSearchProvider::App(
163 new AppSearchProvider::App( 161 this, extension->id(), extension->short_name(),
164 this, 162 prefs->GetLastLaunchTime(extension->id())));
165 extension->id(),
166 extension->short_name(),
167 prefs->GetLastLaunchTime(extension->id())));
168 apps->push_back(std::move(app)); 163 apps->push_back(std::move(app));
169 } 164 }
170 } 165 }
171 166
172 ScopedObserver<extensions::ExtensionRegistry, 167 ScopedObserver<extensions::ExtensionRegistry,
173 extensions::ExtensionRegistryObserver> 168 extensions::ExtensionRegistryObserver>
174 extension_registry_observer_; 169 extension_registry_observer_;
175 170
176 DISALLOW_COPY_AND_ASSIGN(ExtensionDataSource); 171 DISALLOW_COPY_AND_ASSIGN(ExtensionDataSource);
177 }; 172 };
(...skipping 11 matching lines...) Expand all
189 ArcAppListPrefs::Get(profile())->RemoveObserver(this); 184 ArcAppListPrefs::Get(profile())->RemoveObserver(this);
190 } 185 }
191 186
192 // AppSearchProvider::DataSource overrides: 187 // AppSearchProvider::DataSource overrides:
193 void AddApps(AppSearchProvider::Apps* apps) override { 188 void AddApps(AppSearchProvider::Apps* apps) override {
194 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile()); 189 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile());
195 CHECK(arc_prefs); 190 CHECK(arc_prefs);
196 191
197 const std::vector<std::string> app_ids = arc_prefs->GetAppIds(); 192 const std::vector<std::string> app_ids = arc_prefs->GetAppIds();
198 for (const auto& app_id : app_ids) { 193 for (const auto& app_id : app_ids) {
199 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = arc_prefs->GetApp(app_id); 194 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
195 arc_prefs->GetApp(app_id);
200 if (!app_info) { 196 if (!app_info) {
201 NOTREACHED(); 197 NOTREACHED();
202 continue; 198 continue;
203 } 199 }
204 200
205 scoped_ptr<AppSearchProvider::App> app( 201 std::unique_ptr<AppSearchProvider::App> app(new AppSearchProvider::App(
206 new AppSearchProvider::App(this, 202 this, app_id, app_info->name, app_info->last_launch_time));
207 app_id,
208 app_info->name,
209 app_info->last_launch_time));
210 apps->push_back(std::move(app)); 203 apps->push_back(std::move(app));
211 } 204 }
212 } 205 }
213 206
214 scoped_ptr<AppResult> CreateResult( 207 std::unique_ptr<AppResult> CreateResult(
215 const std::string& app_id, 208 const std::string& app_id,
216 AppListControllerDelegate* list_controller, 209 AppListControllerDelegate* list_controller,
217 AppListItemList* top_level_item_list, 210 AppListItemList* top_level_item_list,
218 bool is_recommended) override { 211 bool is_recommended) override {
219 return scoped_ptr<AppResult>(new ArcAppResult(profile(), 212 return std::unique_ptr<AppResult>(
220 app_id, 213 new ArcAppResult(profile(), app_id, list_controller, is_recommended));
221 list_controller,
222 is_recommended));
223 } 214 }
224 215
225 // ArcAppListPrefs::Observer overrides: 216 // ArcAppListPrefs::Observer overrides:
226 void OnAppRegistered(const std::string& app_id, 217 void OnAppRegistered(const std::string& app_id,
227 const ArcAppListPrefs::AppInfo& app_info) override { 218 const ArcAppListPrefs::AppInfo& app_info) override {
228 owner()->RefreshAppsAndUpdateResults(false); 219 owner()->RefreshAppsAndUpdateResults(false);
229 } 220 }
230 221
231 void OnAppRemoved(const std::string& id) override { 222 void OnAppRemoved(const std::string& id) override {
232 owner()->RefreshAppsAndUpdateResults(true); 223 owner()->RefreshAppsAndUpdateResults(true);
233 } 224 }
234 225
235 void OnAppNameUpdated(const std::string& id, 226 void OnAppNameUpdated(const std::string& id,
236 const std::string& name) override { 227 const std::string& name) override {
237 owner()->RefreshAppsAndUpdateResults(false); 228 owner()->RefreshAppsAndUpdateResults(false);
238 } 229 }
239 230
240 private: 231 private:
241 DISALLOW_COPY_AND_ASSIGN(ArcDataSource); 232 DISALLOW_COPY_AND_ASSIGN(ArcDataSource);
242 }; 233 };
243 #endif 234 #endif
244 235
245 } // namespace 236 } // namespace
246 237
247 AppSearchProvider::AppSearchProvider(Profile* profile, 238 AppSearchProvider::AppSearchProvider(Profile* profile,
248 AppListControllerDelegate* list_controller, 239 AppListControllerDelegate* list_controller,
249 scoped_ptr<base::Clock> clock, 240 std::unique_ptr<base::Clock> clock,
250 AppListItemList* top_level_item_list) 241 AppListItemList* top_level_item_list)
251 : profile_(profile), 242 : profile_(profile),
252 list_controller_(list_controller), 243 list_controller_(list_controller),
253 top_level_item_list_(top_level_item_list), 244 top_level_item_list_(top_level_item_list),
254 clock_(std::move(clock)), 245 clock_(std::move(clock)),
255 update_results_factory_(this) { 246 update_results_factory_(this) {
256 data_sources_.push_back(scoped_ptr<DataSource>( 247 data_sources_.push_back(
257 new ExtensionDataSource(profile, this))); 248 std::unique_ptr<DataSource>(new ExtensionDataSource(profile, this)));
258 #if defined(OS_CHROMEOS) 249 #if defined(OS_CHROMEOS)
259 data_sources_.push_back(scoped_ptr<DataSource>( 250 data_sources_.push_back(
260 new ArcDataSource(profile, this))); 251 std::unique_ptr<DataSource>(new ArcDataSource(profile, this)));
261 #endif 252 #endif
262 253
263 RefreshApps(); 254 RefreshApps();
264 } 255 }
265 256
266 AppSearchProvider::~AppSearchProvider() {} 257 AppSearchProvider::~AppSearchProvider() {}
267 258
268 void AppSearchProvider::Start(bool /*is_voice_query*/, 259 void AppSearchProvider::Start(bool /*is_voice_query*/,
269 const base::string16& query) { 260 const base::string16& query) {
270 query_ = query; 261 query_ = query;
(...skipping 27 matching lines...) Expand all
298 ClearResults(); 289 ClearResults();
299 290
300 if (show_recommendations) { 291 if (show_recommendations) {
301 // Build a map of app ids to their position in the app list. 292 // Build a map of app ids to their position in the app list.
302 std::map<std::string, size_t> id_to_app_list_index; 293 std::map<std::string, size_t> id_to_app_list_index;
303 for (size_t i = 0; i < top_level_item_list_->item_count(); ++i) { 294 for (size_t i = 0; i < top_level_item_list_->item_count(); ++i) {
304 id_to_app_list_index[top_level_item_list_->item_at(i)->id()] = i; 295 id_to_app_list_index[top_level_item_list_->item_at(i)->id()] = i;
305 } 296 }
306 297
307 for (auto& app : apps_) { 298 for (auto& app : apps_) {
308 scoped_ptr<AppResult> result = app->data_source()->CreateResult( 299 std::unique_ptr<AppResult> result = app->data_source()->CreateResult(
309 app->id(), list_controller_, top_level_item_list_, true); 300 app->id(), list_controller_, top_level_item_list_, true);
310 result->set_title(app->indexed_name().text()); 301 result->set_title(app->indexed_name().text());
311 302
312 // Use the app list order to tiebreak apps that have never been launched. 303 // Use the app list order to tiebreak apps that have never been launched.
313 if (app->last_launch_time().is_null()) { 304 if (app->last_launch_time().is_null()) {
314 auto it = id_to_app_list_index.find(app->id()); 305 auto it = id_to_app_list_index.find(app->id());
315 // If it's in a folder, it won't be in |id_to_app_list_index|. Rank 306 // If it's in a folder, it won't be in |id_to_app_list_index|. Rank
316 // those as if they are at the end of the list. 307 // those as if they are at the end of the list.
317 size_t app_list_index = 308 size_t app_list_index =
318 it == id_to_app_list_index.end() ? apps_.size() : (*it).second; 309 it == id_to_app_list_index.end() ? apps_.size() : (*it).second;
319 if (app_list_index > apps_.size()) 310 if (app_list_index > apps_.size())
320 app_list_index = apps_.size(); 311 app_list_index = apps_.size();
321 312
322 result->set_relevance(kUnlaunchedAppRelevanceStepSize * 313 result->set_relevance(kUnlaunchedAppRelevanceStepSize *
323 (apps_.size() - app_list_index)); 314 (apps_.size() - app_list_index));
324 } else { 315 } else {
325 result->UpdateFromLastLaunched(clock_->Now(), app->last_launch_time()); 316 result->UpdateFromLastLaunched(clock_->Now(), app->last_launch_time());
326 } 317 }
327 Add(std::move(result)); 318 Add(std::move(result));
328 } 319 }
329 } else { 320 } else {
330 for (auto& app : apps_) { 321 for (auto& app : apps_) {
331 scoped_ptr<AppResult> result = app->data_source()->CreateResult( 322 std::unique_ptr<AppResult> result = app->data_source()->CreateResult(
332 app->id(), list_controller_, top_level_item_list_, false); 323 app->id(), list_controller_, top_level_item_list_, false);
333 TokenizedStringMatch match; 324 TokenizedStringMatch match;
334 if (!match.Calculate(query_terms, app->indexed_name())) 325 if (!match.Calculate(query_terms, app->indexed_name()))
335 continue; 326 continue;
336 327
337 result->UpdateFromMatch(app->indexed_name(), match); 328 result->UpdateFromMatch(app->indexed_name(), match);
338 Add(std::move(result)); 329 Add(std::move(result));
339 } 330 }
340 } 331 }
341 332
342 update_results_factory_.InvalidateWeakPtrs(); 333 update_results_factory_.InvalidateWeakPtrs();
343 } 334 }
344 335
345 void AppSearchProvider::RefreshAppsAndUpdateResults(bool force_inline) { 336 void AppSearchProvider::RefreshAppsAndUpdateResults(bool force_inline) {
346 RefreshApps(); 337 RefreshApps();
347 338
348 if (force_inline) { 339 if (force_inline) {
349 UpdateResults(); 340 UpdateResults();
350 } else { 341 } else {
351 if (!update_results_factory_.HasWeakPtrs()) { 342 if (!update_results_factory_.HasWeakPtrs()) {
352 base::ThreadTaskRunnerHandle::Get()->PostTask( 343 base::ThreadTaskRunnerHandle::Get()->PostTask(
353 FROM_HERE, base::Bind(&AppSearchProvider::UpdateResults, 344 FROM_HERE, base::Bind(&AppSearchProvider::UpdateResults,
354 update_results_factory_.GetWeakPtr())); 345 update_results_factory_.GetWeakPtr()));
355 } 346 }
356 } 347 }
357 } 348 }
358 349
359 } // namespace app_list 350 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698