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

Side by Side Diff: chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc

Issue 27030002: Added collecting of data to be fed to the JTL interpreter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by vasilii@. Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h"
6
7 #include "base/callback.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h"
13 #include "base/values.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
17 #include "chrome/browser/search_engines/template_url_service.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/notification_service.h"
21
22 #if defined(OS_WIN)
23 #include "chrome/browser/enumerate_modules_model_win.h"
24 #include "chrome/browser/install_module_verifier_win.h"
25 #endif
26
27 namespace {
28
29 base::DictionaryValue* BuildSubTreeFromTemplateURL(
Peter Kasting 2013/10/15 01:31:28 Is there similar code to this elsewhere in the bro
engedy 2013/10/15 22:13:07 This is somewhat similar to TemplateURLService::Sa
Peter Kasting 2013/10/16 00:40:21 Hmm. I wonder if there is some way we could write
30 const TemplateURL* template_url) {
31 base::DictionaryValue* tree = new base::DictionaryValue;
32 tree->SetString("search_url", template_url->url());
33 tree->SetString("search_terms_replacement_key",
34 template_url->search_terms_replacement_key());
35 tree->SetString("suggest_url", template_url->suggestions_url());
36 tree->SetString("instant_url", template_url->instant_url());
37 tree->SetString("image_url", template_url->image_url());
38 tree->SetString("new_tab_url", template_url->new_tab_url());
39 tree->SetString("search_url_post_params",
40 template_url->search_url_post_params());
41 tree->SetString("suggest_url_post_params",
42 template_url->suggestions_url_post_params());
43 tree->SetString("instant_url_post_params",
44 template_url->instant_url_post_params());
45 tree->SetString("image_url_post_params",
46 template_url->image_url_post_params());
47 tree->SetString("icon_url", template_url->favicon_url().spec());
48 tree->SetString("name", template_url->short_name());
49 tree->SetString("keyword", template_url->keyword());
50 // For consistency with Prefs.
Peter Kasting 2013/10/15 01:31:28 Nit: This comment is vague; what is for consistenc
engedy 2013/10/15 22:13:07 Reworked this part so the comment is no longer req
51 tree->SetString("encodings",
52 JoinString(template_url->input_encodings(), ';'));
53 tree->SetString("prepopulate_id",
54 base::IntToString(template_url->prepopulate_id()));
55 base::ListValue* alternate_urls = new base::ListValue;
56 alternate_urls->AppendStrings(template_url->alternate_urls());
57 tree->Set("alternate_urls", alternate_urls);
58 return tree;
59 }
60
61 } // namespace
62
63 // AutomaticProfileResetterDelegateImpl --------------------------------------
64
65 AutomaticProfileResetterDelegateImpl::AutomaticProfileResetterDelegateImpl(
66 Profile* profile)
67 : profile_(profile) {
68 TemplateURLService* template_url_service =
69 TemplateURLServiceFactory::GetForProfile(profile_);
70 if (template_url_service) {
Peter Kasting 2013/10/15 01:31:28 Some functions in this class check whether a Templ
engedy 2013/10/15 22:13:07 I have added comments above the class declaration
71 template_url_service->AddObserver(this);
72 // Needed so that |template_url_service_ready_event_| will be signaled even
73 // when TemplateURLService had been already initialized before this point.
74 OnTemplateURLServiceChanged();
75 }
76
77 #if defined(OS_WIN)
78 module_list_.reset(EnumerateModulesModel::GetInstance()->GetModuleList());
79 #endif
80 if (module_list_) {
81 // Having a non-empty module list proves that enumeration had been already
82 // performed before this point.
83 modules_have_been_enumerated_event_.Signal();
84 }
85 registrar_.Add(this,
86 chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
87 content::NotificationService::AllSources());
88 }
89
90 AutomaticProfileResetterDelegateImpl::~AutomaticProfileResetterDelegateImpl() {
91 TemplateURLService* template_url_service =
92 TemplateURLServiceFactory::GetForProfile(profile_);
93 if (template_url_service) {
Peter Kasting 2013/10/15 01:31:28 Nit: No need for {} on one-line bodies (3 places)
engedy 2013/10/15 22:13:07 Done. In all places in automatic_profile_resetter*
94 template_url_service->RemoveObserver(this);
95 }
96 }
97
98 void AutomaticProfileResetterDelegateImpl::EnumerateLoadedModulesIfNeeded() {
99 if (!modules_have_been_enumerated_event_.is_signaled()) {
100 #if defined(OS_WIN)
101 EnumerateModulesModel::GetInstance()->ScanNow();
102 #else
103 modules_have_been_enumerated_event_.Signal();
104 #endif
105 }
106 }
107
108 void AutomaticProfileResetterDelegateImpl::
109 RequestCallbackWhenLoadedModulesAreEnumerated(
110 const base::Closure& ready_callback) const {
Peter Kasting 2013/10/15 01:31:28 Nit: Indent 4, not 8 (2 places)
engedy 2013/10/15 22:13:07 Done. In all places in automatic_profile_resetter*
111 DCHECK(!ready_callback.is_null());
112 modules_have_been_enumerated_event_.Post(FROM_HERE, ready_callback);
113 }
114
115 void AutomaticProfileResetterDelegateImpl::LoadTemplateURLServiceIfNeeded() {
116 TemplateURLService* template_url_service =
117 TemplateURLServiceFactory::GetForProfile(profile_);
118 DCHECK(template_url_service);
119 template_url_service->Load(); // Safe to call even if it has loaded already.
120 }
121
122 void AutomaticProfileResetterDelegateImpl::
123 RequestCallbackWhenTemplateURLServiceIsLoaded(
124 const base::Closure& ready_callback) const {
125 DCHECK(!ready_callback.is_null());
126 template_url_service_ready_event_.Post(FROM_HERE, ready_callback);
127 }
128
129 base::ListValue*
130 AutomaticProfileResetterDelegateImpl::GetLoadedModuleNameDigests() const {
Peter Kasting 2013/10/15 01:31:28 Nit: Indent 4 (3 places)
engedy 2013/10/15 22:13:07 Done. In all places in automatic_profile_resetter*
131 DCHECK(modules_have_been_enumerated_event_.is_signaled());
132 std::set<std::string> module_name_digests;
133 #if defined(OS_WIN)
134 if (module_list_) {
135 DLOG(INFO) << *module_list_;
136 ExtractLoadedModuleNameDigests(*module_list_, &module_name_digests);
137 }
138 #endif
139 base::ListValue* result = new base::ListValue;
140 for (std::set<std::string>::const_iterator it = module_name_digests.begin();
141 it != module_name_digests.end();
142 ++it) {
Peter Kasting 2013/10/15 01:31:28 Nit: Commonly we don't linebreak before this, but
engedy 2013/10/15 22:13:07 Done. In all places in automatic_profile_resetter*
143 result->AppendString(*it);
144 }
145 return result;
146 }
147
148 base::DictionaryValue*
149 AutomaticProfileResetterDelegateImpl::GetDefaultSearchProviderDetails() const {
150 TemplateURLService* template_url_service =
151 TemplateURLServiceFactory::GetForProfile(profile_);
152 DCHECK(template_url_service);
153 DCHECK(template_url_service->loaded());
154
155 TemplateURL* default_search_provider =
156 template_url_service->GetDefaultSearchProvider();
157
158 // Having a NULL default search provider is due to either:
159 // 1.) default search providers being disabled by policy,
160 // 2.) directly tampering the Preferences and/or the SQLite DBs.
161 // In this state, Omnibox non-keyword search functionality is disabled.
162 // Unfortunately, we cannot really tell apart the two underlying causes.
163 if (default_search_provider)
164 return BuildSubTreeFromTemplateURL(default_search_provider);
165 else
Peter Kasting 2013/10/15 01:31:28 Nit: No else after return. Consider: return de
engedy 2013/10/15 22:13:07 Done.
166 return NULL;
167 }
168
169 bool AutomaticProfileResetterDelegateImpl::IsDefaultSearchProviderManaged()
170 const {
Peter Kasting 2013/10/15 01:31:28 Nit: I'd probably break after "::" instead (2 plac
engedy 2013/10/15 22:13:07 Done. In all places in automatic_profile_resetter*
171 TemplateURLService* template_url_service =
172 TemplateURLServiceFactory::GetForProfile(profile_);
173 DCHECK(template_url_service);
174 DCHECK(template_url_service->loaded());
175 return template_url_service->is_default_search_managed();
176 }
177
178 base::ListValue*
179 AutomaticProfileResetterDelegateImpl::GetPrepopulatedSearchProvidersDetails()
180 const {
181 ScopedVector<TemplateURL> engines;
Peter Kasting 2013/10/15 01:31:28 Nit: Declare this in the statement that inits it
engedy 2013/10/15 22:13:07 Done.
182 size_t default_search_index = 0;
183 engines = TemplateURLPrepopulateData::GetPrepopulatedEngines(
184 profile_, &default_search_index);
185 base::ListValue* engines_details_list = new base::ListValue;
186 for (ScopedVector<TemplateURL>::const_iterator it = engines.begin();
187 it != engines.end();
188 ++it) {
189 engines_details_list->Append(BuildSubTreeFromTemplateURL(*it));
190 }
191 return engines_details_list;
192 }
193
194 void AutomaticProfileResetterDelegateImpl::ShowPrompt() {
195 // TODO(engedy): Call the UI from here once we have it.
196 }
197
198 void AutomaticProfileResetterDelegateImpl::OnTemplateURLServiceChanged() {
199 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
200 TemplateURLService* template_url_service =
201 TemplateURLServiceFactory::GetForProfile(profile_);
202 DCHECK(template_url_service);
203 if (template_url_service->loaded() &&
204 !template_url_service_ready_event_.is_signaled()) {
205 template_url_service_ready_event_.Signal();
206 }
207 }
208
209 void AutomaticProfileResetterDelegateImpl::Observe(
210 int type,
211 const content::NotificationSource& source,
212 const content::NotificationDetails& details) {
213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
214 if (type == chrome::NOTIFICATION_MODULE_LIST_ENUMERATED &&
215 !modules_have_been_enumerated_event_.is_signaled()) {
216 #if defined(OS_WIN)
217 module_list_.reset(EnumerateModulesModel::GetInstance()->GetModuleList());
218 #endif
219 modules_have_been_enumerated_event_.Signal();
220 }
221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698