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

Side by Side 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 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 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_
6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/search_engines/template_url_service_observer.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "extensions/common/one_shot_event.h"
15
16 class Profile;
17
18 namespace base {
19 class DictionaryValue;
20 class ListValue;
21 }
22
23 // Defines the interface for the delegate that will interact with the rest of
24 // the browser on behalf of the AutomaticProfileResetter.
25 // The primary reason for this separation is to facilitate unit testing.
26 class AutomaticProfileResetterDelegate {
27 public:
28 virtual ~AutomaticProfileResetterDelegate() {}
29
30 // Requests the module enumerator to start scanning for loaded modules now, if
31 // it has not done so already.
32 virtual void EnumerateLoadedModulesIfNeeded() = 0;
33
34 // Requests |ready_callback| to be posted on the UI thread once the module
35 // enumerator has finished scanning for loaded modules.
36 virtual void RequestCallbackWhenLoadedModulesAreEnumerated(
37 const base::Closure& ready_callback) const = 0;
38
39 // Requests the template URL service to load its database (asynchronously).
40 virtual void LoadTemplateURLServiceIfNeeded() = 0;
41
42 // Requests |ready_callback| to be posted on the UI thread once the template
43 // URL service has finished loading its database.
44 virtual void RequestCallbackWhenTemplateURLServiceIsLoaded(
45 const base::Closure& ready_callback) const = 0;
46
47 // Returns a list of loaded module name digests.
48 virtual scoped_ptr<base::ListValue> GetLoadedModuleNameDigests() const = 0;
49
50 // Returns attributes of the search engine currently set as the default (or
51 // an empty dictionary if there is none).
52 // The returned attributes correspond in meaning and format to the user
53 // preferences stored by TemplateURLService::SaveDefaultSearchProviderToPrefs,
54 // and will be named after the second path name segment of the respective
55 // preference (i.e. the part after "default_search_provider.").
56 // Note that:
57 // 1.) the "enabled" attribute will not be present, as it is not technically
58 // an attribute of a search provider,
59 // 2.) "encodings" will be a list of strings, in contrast to a semicolons
60 // 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.
61 virtual scoped_ptr<base::DictionaryValue>
62 GetDefaultSearchProviderDetails() const = 0;
63
64 // Returns whether or not the default search provider is set by policy.
65 virtual bool IsDefaultSearchProviderManaged() const = 0;
66
67 // Returns a list of dictionaries, each containing attributes for each of the
68 // pre-populated search engines, in the format described above.
69 virtual scoped_ptr<base::ListValue>
70 GetPrepopulatedSearchProvidersDetails() const = 0;
71
72 // Triggers showing the one-time profile settings reset prompt.
73 virtual void ShowPrompt() = 0;
74 };
75
76 // Implementation for AutomaticProfileResetterDelegate.
77 // To facilitate unit testing, having the TemplateURLService available is only
78 // 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
79 class AutomaticProfileResetterDelegateImpl
80 : public AutomaticProfileResetterDelegate,
81 public TemplateURLServiceObserver,
82 public content::NotificationObserver {
83 public:
84 explicit AutomaticProfileResetterDelegateImpl(Profile* profile);
85 virtual ~AutomaticProfileResetterDelegateImpl();
86
87 // AutomaticProfileResetterDelegate:
88 virtual void EnumerateLoadedModulesIfNeeded() OVERRIDE;
89 virtual void RequestCallbackWhenLoadedModulesAreEnumerated(
90 const base::Closure& ready_callback) const OVERRIDE;
91 virtual void LoadTemplateURLServiceIfNeeded() OVERRIDE;
92 virtual void RequestCallbackWhenTemplateURLServiceIsLoaded(
93 const base::Closure& ready_callback) const OVERRIDE;
94 virtual scoped_ptr<base::ListValue>
95 GetLoadedModuleNameDigests() const OVERRIDE;
96 virtual scoped_ptr<base::DictionaryValue>
97 GetDefaultSearchProviderDetails() const OVERRIDE;
98 virtual bool IsDefaultSearchProviderManaged() const OVERRIDE;
99 virtual scoped_ptr<base::ListValue>
100 GetPrepopulatedSearchProvidersDetails() const OVERRIDE;
101 virtual void ShowPrompt() OVERRIDE;
102
103 // TemplateURLServiceObserver:
104 virtual void OnTemplateURLServiceChanged() OVERRIDE;
105
106 // content::NotificationObserver:
107 virtual void Observe(int type,
108 const content::NotificationSource& source,
109 const content::NotificationDetails& details) OVERRIDE;
110
111 private:
112 Profile* profile_;
113
114 content::NotificationRegistrar registrar_;
115
116 // The list of modules found. Even when |modules_have_been_enumerated_event_|
117 // is signaled, this may still be NULL.
118 scoped_ptr<base::ListValue> module_list_;
119
120 // This event is signaled once we have proof that the modules have been
121 // (attempted to be) enumerated at least once. Such proof can be that:
122 // 1.) we requested scanning of modules ourselves,
123 // 2.) we could already retrieve a non-empty list of modules during the
124 // 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!
125 extensions::OneShotEvent modules_have_been_enumerated_event_;
126
127 // This event is signaled once the TemplateURLService has loaded. If the
128 // TemplateURLService was already loaded prior to the creation of this class,
129 // the event will be signaled during construction.
130 extensions::OneShotEvent template_url_service_ready_event_;
131
132 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl);
133 };
134
135 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698