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/message_loop/message_loop.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" |
10 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
11 #include "components/search_engines/search_engines_pref_names.h" | 13 #include "components/search_engines/search_engines_pref_names.h" |
12 #include "components/search_engines/template_url_prepopulate_data.h" | 14 #include "components/search_engines/template_url_prepopulate_data.h" |
13 #include "components/search_engines/template_url_service.h" | 15 #include "components/search_engines/template_url_service.h" |
14 #include "components/search_engines/template_url_service_observer.h" | 16 #include "components/search_engines/template_url_service_observer.h" |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 // Id of the google id in template_url_prepopulate_data.cc. | 20 // Id of the google id in template_url_prepopulate_data.cc. |
19 static const int kGoogleEnginePrepopulatedId = 1; | 21 static const int kGoogleEnginePrepopulatedId = 1; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 service_->AddObserver(this); | 70 service_->AddObserver(this); |
69 service_->Load(); | 71 service_->Load(); |
70 } | 72 } |
71 | 73 |
72 ~LoadedObserver() override { service_->RemoveObserver(this); } | 74 ~LoadedObserver() override { service_->RemoveObserver(this); } |
73 | 75 |
74 void OnTemplateURLServiceChanged() override { | 76 void OnTemplateURLServiceChanged() override { |
75 service_->RemoveObserver(this); | 77 service_->RemoveObserver(this); |
76 UpdateSearchEngine(service_); | 78 UpdateSearchEngine(service_); |
77 // Only delete this class when this callback is finished. | 79 // Only delete this class when this callback is finished. |
78 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 80 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
79 } | 81 } |
80 | 82 |
81 private: | 83 private: |
82 TemplateURLService* service_; | 84 TemplateURLService* service_; |
83 }; | 85 }; |
84 | 86 |
85 } // namespace | 87 } // namespace |
86 | 88 |
87 namespace search_engines { | 89 namespace search_engines { |
88 | 90 |
(...skipping 17 matching lines...) Expand all Loading... |
106 // removed then the engines can be updated again. | 108 // removed then the engines can be updated again. |
107 if (!service || service->is_default_search_managed()) | 109 if (!service || service->is_default_search_managed()) |
108 return; | 110 return; |
109 if (service->loaded()) | 111 if (service->loaded()) |
110 UpdateSearchEngine(service); | 112 UpdateSearchEngine(service); |
111 else | 113 else |
112 new LoadedObserver(service); // The observer manages its own lifetime. | 114 new LoadedObserver(service); // The observer manages its own lifetime. |
113 } | 115 } |
114 | 116 |
115 } // namespace search_engines | 117 } // namespace search_engines |
OLD | NEW |