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

Unified Diff: chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h

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 all comments by pkasting@. 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.h
diff --git a/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h b/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..00ce5212c03952cb5e8bd7cb5a5a814132453e06
--- /dev/null
+++ b/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h
@@ -0,0 +1,135 @@
+// 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.
+
+#ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_
+#define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_
+
+#include "base/basictypes.h"
+#include "base/callback_forward.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/search_engines/template_url_service_observer.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "extensions/common/one_shot_event.h"
+
+class Profile;
+
+namespace base {
+class DictionaryValue;
+class ListValue;
+}
+
+// Defines the interface for the delegate that will interact with the rest of
+// the browser on behalf of the AutomaticProfileResetter.
+// The primary reason for this separation is to facilitate unit testing.
+class AutomaticProfileResetterDelegate {
+ public:
+ virtual ~AutomaticProfileResetterDelegate() {}
+
+ // Requests the module enumerator to start scanning for loaded modules now, if
+ // it has not done so already.
+ virtual void EnumerateLoadedModulesIfNeeded() = 0;
+
+ // Requests |ready_callback| to be posted on the UI thread once the module
+ // enumerator has finished scanning for loaded modules.
+ virtual void RequestCallbackWhenLoadedModulesAreEnumerated(
+ const base::Closure& ready_callback) const = 0;
+
+ // Requests the template URL service to load its database (asynchronously).
+ virtual void LoadTemplateURLServiceIfNeeded() = 0;
+
+ // Requests |ready_callback| to be posted on the UI thread once the template
+ // URL service has finished loading its database.
+ virtual void RequestCallbackWhenTemplateURLServiceIsLoaded(
+ const base::Closure& ready_callback) const = 0;
+
+ // Returns a list of loaded module name digests.
+ virtual scoped_ptr<base::ListValue> GetLoadedModuleNameDigests() const = 0;
+
+ // Returns attributes of the search engine currently set as the default (or
+ // an empty dictionary if there is none).
+ // The returned attributes correspond in meaning and format to the user
+ // preferences stored by TemplateURLService::SaveDefaultSearchProviderToPrefs,
+ // and will be named after the second path name segment of the respective
+ // preference (i.e. the part after "default_search_provider.").
+ // Note that:
+ // 1.) the "enabled" attribute will not be present, as it is not technically
+ // an attribute of a search provider,
+ // 2.) "encodings" will be a list of strings, in contrast to a semicolons
+ // separated joined string, so as to be usable for the JTL programs.
Peter Kasting 2013/10/16 00:40:21 Nit: semicolons separated joined string -> single
engedy 2013/10/16 11:13:54 Done.
+ virtual scoped_ptr<base::DictionaryValue>
+ GetDefaultSearchProviderDetails() const = 0;
+
+ // Returns whether or not the default search provider is set by policy.
+ virtual bool IsDefaultSearchProviderManaged() const = 0;
+
+ // Returns a list of dictionaries, each containing attributes for each of the
+ // pre-populated search engines, in the format described above.
+ virtual scoped_ptr<base::ListValue>
+ GetPrepopulatedSearchProvidersDetails() const = 0;
+
+ // Triggers showing the one-time profile settings reset prompt.
+ virtual void ShowPrompt() = 0;
+};
+
+// Implementation for AutomaticProfileResetterDelegate.
+// To facilitate unit testing, having the TemplateURLService available is only
+// required when using search engine related methods.
Peter Kasting 2013/10/16 00:40:21 This comment just made things more confusing. It'
engedy 2013/10/16 11:13:54 Done. I have updated the tests to take advantage o
+class AutomaticProfileResetterDelegateImpl
+ : public AutomaticProfileResetterDelegate,
+ public TemplateURLServiceObserver,
+ public content::NotificationObserver {
+ public:
+ explicit AutomaticProfileResetterDelegateImpl(Profile* profile);
+ virtual ~AutomaticProfileResetterDelegateImpl();
+
+ // AutomaticProfileResetterDelegate:
+ virtual void EnumerateLoadedModulesIfNeeded() OVERRIDE;
+ virtual void RequestCallbackWhenLoadedModulesAreEnumerated(
+ const base::Closure& ready_callback) const OVERRIDE;
+ virtual void LoadTemplateURLServiceIfNeeded() OVERRIDE;
+ virtual void RequestCallbackWhenTemplateURLServiceIsLoaded(
+ const base::Closure& ready_callback) const OVERRIDE;
+ virtual scoped_ptr<base::ListValue>
+ GetLoadedModuleNameDigests() const OVERRIDE;
+ virtual scoped_ptr<base::DictionaryValue>
+ GetDefaultSearchProviderDetails() const OVERRIDE;
+ virtual bool IsDefaultSearchProviderManaged() const OVERRIDE;
+ virtual scoped_ptr<base::ListValue>
+ GetPrepopulatedSearchProvidersDetails() const OVERRIDE;
+ virtual void ShowPrompt() OVERRIDE;
+
+ // TemplateURLServiceObserver:
+ virtual void OnTemplateURLServiceChanged() OVERRIDE;
+
+ // content::NotificationObserver:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ private:
+ Profile* profile_;
+
+ content::NotificationRegistrar registrar_;
+
+ // The list of modules found. Even when |modules_have_been_enumerated_event_|
+ // is signaled, this may still be NULL.
+ scoped_ptr<base::ListValue> module_list_;
+
+ // This event is signaled once we have proof that the modules have been
+ // (attempted to be) enumerated at least once. Such proof can be that:
+ // 1.) we requested scanning of modules ourselves,
+ // 2.) we could already retrieve a non-empty list of modules during the
+ // construction of this class.
Peter Kasting 2013/10/16 00:40:21 Nit: Hmm, how about: This event is signaled once
engedy 2013/10/16 11:13:54 Done. Great suggestion, thanks!
+ extensions::OneShotEvent modules_have_been_enumerated_event_;
+
+ // This event is signaled once the TemplateURLService has loaded. If the
+ // TemplateURLService was already loaded prior to the creation of this class,
+ // the event will be signaled during construction.
+ extensions::OneShotEvent template_url_service_ready_event_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl);
+};
+
+#endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698