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

Side by Side Diff: chrome/browser/protector/protector_service.h

Issue 11493003: Remove the protector service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix implicit ExtensionSystem -> TemplateURLService dependency Created 8 years 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 (c) 2012 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_PROTECTOR_PROTECTOR_SERVICE_H_
6 #define CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/sequenced_task_runner_helpers.h"
15 #include "chrome/browser/profiles/profile_keyed_service.h"
16 #include "chrome/browser/protector/base_setting_change.h"
17 #include "chrome/browser/protector/settings_change_global_error_delegate.h"
18
19 class GURL;
20 class PrefService;
21 class Profile;
22 class TemplateURLService;
23
24 namespace protector {
25
26 class ProtectedPrefsWatcher;
27 class SettingsChangeGlobalError;
28
29 // Presents a SettingChange to user and handles possible user actions.
30 class ProtectorService : public ProfileKeyedService,
31 public SettingsChangeGlobalErrorDelegate {
32 public:
33 explicit ProtectorService(Profile* profile);
34 virtual ~ProtectorService();
35
36 // Shows global error about the specified change. Owns |change|. May be called
37 // multiple times in which case subsequent bubbles will be displayed.
38 virtual void ShowChange(BaseSettingChange* change);
39
40 // Returns |true| if a change is currently active (shown by a ShowChange call
41 // and not yet applied or discarded).
42 virtual bool IsShowingChange() const;
43
44 // Removes corresponding global error (including the bubbble if one is shown)
45 // and deletes the change instance (without calling Apply or Discard on it).
46 virtual void DismissChange(BaseSettingChange* change);
47
48 // Persists |change| and removes corresponding global error. |browser| is the
49 // Browser instance from which the user action originates.
50 virtual void ApplyChange(BaseSettingChange* change, Browser* browser);
51
52 // Discards |change| and removes corresponding global error. |browser| is the
53 // Browser instance from which the user action originates.
54 virtual void DiscardChange(BaseSettingChange* change, Browser* browser);
55
56 // Opens a tab with specified URL in the browser window we've shown error
57 // bubble for.
58 virtual void OpenTab(const GURL& url, Browser* browser);
59
60 // Returns the ProtectedPrefsWatcher instance for access to protected prefs
61 // backup.
62 ProtectedPrefsWatcher* GetPrefsWatcher();
63
64 // Stops observing pref changes and updating the backup. Should be used in
65 // tests only.
66 void StopWatchingPrefsForTesting();
67
68 // Returns the most recent change instance or NULL if there are no changes.
69 BaseSettingChange* GetLastChange();
70
71 // Returns the Profile instance for this service.
72 Profile* profile() { return profile_; }
73
74 private:
75 friend class ProtectorServiceTest;
76
77 // Each item consists of an error and corresponding change instance.
78 // linked_ptr is used because Item instances are stored in a std::vector and
79 // must be copyable.
80 struct Item {
81 Item();
82 ~Item();
83 linked_ptr<BaseSettingChange> change;
84 linked_ptr<SettingsChangeGlobalError> error;
85 // When true, this means |change| was merged with another instance and
86 // |error| is in process of being removed from GlobalErrorService.
87 bool was_merged;
88 // Meaningful only when |was_merged| is true. In that case, true means that
89 // the new merged GlobalError instance will be immediately shown.
90 bool show_when_merged;
91 };
92
93 typedef std::vector<Item> Items;
94
95 // Matches Item by |change| field.
96 class MatchItemByChange {
97 public:
98 explicit MatchItemByChange(const BaseSettingChange* other);
99
100 bool operator()(const Item& item);
101
102 private:
103 const BaseSettingChange* other_;
104 };
105
106 // Matches Item by |error| field.
107 class MatchItemByError {
108 public:
109 explicit MatchItemByError(const SettingsChangeGlobalError* other);
110
111 bool operator()(const Item& item);
112
113 private:
114 const SettingsChangeGlobalError* other_;
115 };
116
117 // Returns an Item instance whose change can be merged with |change|, if any.
118 // Otherwise returns |NULL|. Provided that the merge strategy is transitive,
119 // there can be only one such instance.
120 Item* FindItemToMergeWith(const BaseSettingChange* change);
121
122 // ProfileKeyedService implementation.
123 virtual void Shutdown() OVERRIDE;
124
125 // SettingsChangeGlobalErrorDelegate implementation.
126 virtual void OnApplyChange(SettingsChangeGlobalError* error,
127 Browser* browser) OVERRIDE;
128 virtual void OnDiscardChange(SettingsChangeGlobalError* error,
129 Browser* browser) OVERRIDE;
130 virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE;
131 virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE;
132
133 // Pointers to error bubble controllers and corresponding changes in the order
134 // added.
135 Items items_;
136
137 // Profile which settings we are protecting.
138 Profile* profile_;
139
140 // True if there is a change that has been shown and not yet accepted or
141 // discarded by user.
142 bool has_active_change_;
143
144 // Observes changes to protected prefs and updates the backup.
145 scoped_ptr<ProtectedPrefsWatcher> prefs_watcher_;
146
147 DISALLOW_COPY_AND_ASSIGN(ProtectorService);
148 };
149
150 } // namespace protector
151
152 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/protector/protected_prefs_watcher_unittest.cc ('k') | chrome/browser/protector/protector_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698