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

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

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 (c) 2011 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_H_
6 #define CHROME_BROWSER_PROTECTOR_PROTECTOR_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/string16.h"
16
17 class GURL;
18 class KeywordTable;
19 class TemplateURLService;
20
21 namespace protector {
22
23 class Protector;
24 class SettingsChangeGlobalError;
25
26 // Base class for setting change tracked by Protector.
27 class SettingChange : public base::RefCountedThreadSafe<SettingChange> {
Ivan Korotkov 2011/10/19 20:24:37 Please split all these classes into separate files
whywhat 2011/10/20 20:50:10 Done.
28 public:
29 // IDs of changes Protector currently tracks.
30 enum Type {
31 // Default search engine has been changed.
32 kSearchEngineChanged,
33
34 // Home page has been changed.
35 kHomePageChanged,
36 };
37
38 explicit SettingChange(Type type) : type_(type) {}
39
40 Type type() const { return type_; }
41
42 // Returns the old setting presentation to be shown to user.
43 // Returns empty string if the old setting is unavailable.
44 virtual const string16& GetOldSetting() const = 0;
45
46 // Returns the new setting presentation to be shown to user.
47 virtual const string16& GetNewSetting() const = 0;
48
49 // Persists new setting if needed.
50 virtual void Accept(Protector* protector) {}
51
52 // Restores old setting value if needed.
53 virtual void Revert(Protector* protector) {}
54
55 protected:
56 virtual ~SettingChange() {}
57
58 private:
59 friend class base::RefCountedThreadSafe<SettingChange>;
60
61 // Type of the change. Used for strings lookup by UI.
62 Type type_;
63
64 DISALLOW_COPY_AND_ASSIGN(SettingChange);
65 };
66
67 class DefaultSearchProviderChange : public SettingChange {
Ivan Korotkov 2011/10/19 20:24:37 This is a pure implementation, so it can be declar
whywhat 2011/10/20 20:50:10 Done.
68 public:
69 DefaultSearchProviderChange(
70 KeywordTable* table,
71 int64 old_id,
72 int64 new_id);
73
74 // SettingChange overrides:
75 virtual const string16& GetOldSetting() const OVERRIDE;
76 virtual const string16& GetNewSetting() const OVERRIDE;
77 virtual void Accept(Protector* protector) OVERRIDE;
78 virtual void Revert(Protector* protector) OVERRIDE;
79
80 private:
81 ~DefaultSearchProviderChange();
82
83 // ID of the new default search provider to be accepted.
84 int64 new_id_;
85
86 // Short name of the old default search provider.
87 string16 old_name_;
88
89 // Short name of the new default search provider.
90 string16 new_name_;
91
92 DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange);
93 };
94
95 // Accumulates search engine changes and shows them altogether to user.
96 class Protector : public base::RefCountedThreadSafe<Protector> {
97 public:
98 typedef std::vector<scoped_refptr<SettingChange> > ChangesVector;
99
100 Protector();
101
102 // Add info about single setting change to the list of changes to notify
103 // about. Does nothing if we're showing changes already.
104 void AddChange(scoped_refptr<SettingChange> change);
105
106 // Shows error bubble to user about settings changes. The result is either
107 // accept or decline of the change.
108 void NotifyUser();
109
110 // Callback for the case when user accepts the change.
111 void OnChangesAccepted();
112
113 // Callback for the case when user declines the change.
114 void OnChangesDeclined();
115
116 // Opens a tab with specified URL.
117 void OpenTab(const GURL& url);
118
119 // Returns TemplateURLService.
120 TemplateURLService* GetTemplateURLService();
121
122 private:
123 friend class base::RefCountedThreadSafe<Protector>;
124 ~Protector();
125
126 // All changes we want to show.
127 ChangesVector changes_;
128
129 // Pointer to error bubble controller. Indicates if we're showing change
130 // notification to user.
131 SettingsChangeGlobalError* error_;
132
133 DISALLOW_COPY_AND_ASSIGN(Protector);
134 };
135
136 // Shows notification about a single setting change.
137 void NotifyUserOfChange(scoped_refptr<SettingChange> change);
Ivan Korotkov 2011/10/19 20:24:37 I'd make this a static method of Protector.
whywhat 2011/10/20 20:50:10 It would be protector::Protector::NotifyUserOfChan
138
139 // Signs string value with protector's key.
140 std::string Sign(const std::string& value);
Ivan Korotkov 2011/10/19 20:24:37 Maybe give it a more descriptive name? Like 'SignS
whywhat 2011/10/20 20:50:10 Done.
141
142 } // namespace protector
143
144 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698