OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ios/chrome/browser/search_engines/search_engines_util.h" | 5 #include "ios/chrome/browser/search_engines/search_engines_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
12 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
13 #include "components/search_engines/search_engines_pref_names.h" | 14 #include "components/search_engines/search_engines_pref_names.h" |
14 #include "components/search_engines/template_url_prepopulate_data.h" | 15 #include "components/search_engines/template_url_prepopulate_data.h" |
15 #include "components/search_engines/template_url_service.h" | 16 #include "components/search_engines/template_url_service.h" |
16 #include "components/search_engines/template_url_service_observer.h" | 17 #include "components/search_engines/template_url_service_observer.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
(...skipping 25 matching lines...) Expand all Loading... |
45 service->SetUserSelectedDefaultSearchProvider(engine); | 46 service->SetUserSelectedDefaultSearchProvider(engine); |
46 } | 47 } |
47 for (auto* engine : old_engines) { | 48 for (auto* engine : old_engines) { |
48 if (engine->prepopulate_id() != kGoogleEnginePrepopulatedId) | 49 if (engine->prepopulate_id() != kGoogleEnginePrepopulatedId) |
49 service->Remove(engine); | 50 service->Remove(engine); |
50 } | 51 } |
51 ScopedVector<TemplateURLData>::iterator it = new_engines.begin(); | 52 ScopedVector<TemplateURLData>::iterator it = new_engines.begin(); |
52 while (it != new_engines.end()) { | 53 while (it != new_engines.end()) { |
53 if ((*it)->prepopulate_id != kGoogleEnginePrepopulatedId) { | 54 if ((*it)->prepopulate_id != kGoogleEnginePrepopulatedId) { |
54 // service->Add takes ownership on Added TemplateURL. | 55 // service->Add takes ownership on Added TemplateURL. |
55 service->Add(new TemplateURL(**it)); | 56 service->Add(base::MakeUnique<TemplateURL>(**it)); |
56 it = new_engines.weak_erase(it); | 57 it = new_engines.weak_erase(it); |
57 } else { | 58 } else { |
58 ++it; | 59 ++it; |
59 } | 60 } |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
63 // Observer class that allows to wait for the TemplateURLService to be loaded. | 64 // Observer class that allows to wait for the TemplateURLService to be loaded. |
64 // This class will delete itself as soon as the TemplateURLService is loaded. | 65 // This class will delete itself as soon as the TemplateURLService is loaded. |
65 class LoadedObserver : public TemplateURLServiceObserver { | 66 class LoadedObserver : public TemplateURLServiceObserver { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // removed then the engines can be updated again. | 109 // removed then the engines can be updated again. |
109 if (!service || service->is_default_search_managed()) | 110 if (!service || service->is_default_search_managed()) |
110 return; | 111 return; |
111 if (service->loaded()) | 112 if (service->loaded()) |
112 UpdateSearchEngine(service); | 113 UpdateSearchEngine(service); |
113 else | 114 else |
114 new LoadedObserver(service); // The observer manages its own lifetime. | 115 new LoadedObserver(service); // The observer manages its own lifetime. |
115 } | 116 } |
116 | 117 |
117 } // namespace search_engines | 118 } // namespace search_engines |
OLD | NEW |