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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc
diff --git a/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc b/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a03bd0333088b5cfcf5e605f2e09a3f12b62f0f
--- /dev/null
+++ b/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc
@@ -0,0 +1,165 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h"
+
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/memory/scoped_vector.h"
+#include "base/metrics/histogram.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
+#include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace {
+
+base::DictionaryValue* BuildSubTreeFromTemplateURL(
+ const TemplateURL* template_url) {
+ base::DictionaryValue* tree = new base::DictionaryValue;
+ tree->SetString("search_url", template_url->url());
+ tree->SetString("search_terms_replacement_key",
+ template_url->search_terms_replacement_key());
+ tree->SetString("suggest_url", template_url->suggestions_url());
+ tree->SetString("instant_url", template_url->instant_url());
+ tree->SetString("image_url", template_url->image_url());
+ tree->SetString("new_tab_url", template_url->new_tab_url());
+ tree->SetString("search_url_post_params",
+ template_url->search_url_post_params());
+ tree->SetString("suggest_url_post_params",
+ template_url->suggestions_url_post_params());
+ tree->SetString("instant_url_post_params",
+ template_url->instant_url_post_params());
+ tree->SetString("image_url_post_params",
+ template_url->image_url_post_params());
+ tree->SetString("icon_url", template_url->favicon_url().spec());
+ tree->SetString("name", template_url->short_name());
+ tree->SetString("keyword", template_url->keyword());
+ // For consistency with Prefs.
+ tree->SetString("encodings",
+ JoinString(template_url->input_encodings(), ';'));
+ tree->SetString("prepopulate_id",
+ base::IntToString(template_url->prepopulate_id()));
+ base::ListValue* alternate_urls = new base::ListValue;
+ alternate_urls->AppendStrings(template_url->alternate_urls());
+ tree->Set("alternate_urls", alternate_urls);
+ return tree;
+}
+
+} // namespace
+
+// AutomaticProfileResetterDelegateImpl --------------------------------------
+
+AutomaticProfileResetterDelegateImpl::AutomaticProfileResetterDelegateImpl(
+ Profile* profile)
+ : profile_(profile) {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ if (template_url_service) {
+ template_url_service->AddObserver(this);
+ // Needed so that |template_url_service_ready_event_| will be signaled even
+ // when TemplateURLService is already initialized when we are constructed.
+ OnTemplateURLServiceChanged();
+ }
+}
+
+AutomaticProfileResetterDelegateImpl::~AutomaticProfileResetterDelegateImpl() {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ if (template_url_service) {
+ template_url_service->RemoveObserver(this);
+ }
+}
+
+void AutomaticProfileResetterDelegateImpl::LoadTemplateURLServiceIfNeeded() {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ DCHECK(template_url_service);
+ template_url_service->Load(); // Safe to call even if it has loaded already.
+}
+
+void AutomaticProfileResetterDelegateImpl::WaitOnTemplateURLService(
+ const base::Closure& ready_callback) {
+ DCHECK(!ready_callback.is_null());
+ template_url_service_ready_event_.Post(FROM_HERE, ready_callback);
+}
+
+base::DictionaryValue*
+AutomaticProfileResetterDelegateImpl::GetDefaultSearchProviderDetails() const {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ DCHECK(template_url_service);
+ DCHECK(template_url_service->loaded());
+
+ TemplateURL* default_search_provider =
+ template_url_service->GetDefaultSearchProvider();
+
+ // Having a NULL default search provider is due to either:
+ // 1.) default search providers being disabled by policy,
+ // 2.) directly tampering the Preferences and/or the SQLite DBs.
+ // In this state, Omnibox non-keyword search functionality is disabled.
+ // Unfortunately, we cannot really tell apart the two underlying causes.
+ if (default_search_provider)
+ return BuildSubTreeFromTemplateURL(default_search_provider);
+ else
+ return NULL;
+}
+
+bool AutomaticProfileResetterDelegateImpl::IsDefaultSearchProviderManaged()
+ const {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ DCHECK(template_url_service);
+ DCHECK(template_url_service->loaded());
+ return template_url_service->is_default_search_managed();
+}
+
+base::ListValue*
+AutomaticProfileResetterDelegateImpl::GetPrepopulatedSearchProvidersDetails()
+ const {
+ ScopedVector<TemplateURL> engines;
+ size_t default_search_index;
battre 2013/10/11 15:05:33 please initialize to 0.
engedy 2013/10/11 16:42:16 Done.
+ engines = TemplateURLPrepopulateData::GetPrepopulatedEngines(
+ profile_, &default_search_index);
+ base::ListValue* engines_details_list = new base::ListValue;
+ for (ScopedVector<TemplateURL>::const_iterator it = engines.begin();
+ it != engines.end();
+ ++it) {
+ engines_details_list->Append(BuildSubTreeFromTemplateURL(*it));
+ }
+ return engines_details_list;
+}
+
+void AutomaticProfileResetterDelegateImpl::ShowPrompt() {
+ // TODO(engedy): Call the UI from here once we have it.
+}
+
+void AutomaticProfileResetterDelegateImpl::ReportStatistics(
+ uint32 satisfied_criteria_mask,
+ uint32 combined_status_mask) {
+ UMA_HISTOGRAM_ENUMERATION(
+ "AutomaticProfileReset.SatisfiedCriteriaMask",
+ satisfied_criteria_mask,
+ AutomaticProfileResetter::kSatisfiedCriteriaMaskMaximumValue);
+ UMA_HISTOGRAM_ENUMERATION(
+ "AutomaticProfileReset.CombinedStatusMask",
+ combined_status_mask,
+ AutomaticProfileResetter::kCombinedStatusMaskMaximumValue);
+}
+
+void AutomaticProfileResetterDelegateImpl::OnTemplateURLServiceChanged() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ DCHECK(template_url_service);
+ if (template_url_service->loaded() &&
+ !template_url_service_ready_event_.is_signaled()) {
+ template_url_service_ready_event_.Signal();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698