OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ |
6 #define CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ | 6 #define CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
| 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop_helpers.h" | 15 #include "base/message_loop_helpers.h" |
15 #include "chrome/browser/profiles/profile_keyed_service.h" | 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
16 #include "chrome/browser/protector/base_setting_change.h" | 17 #include "chrome/browser/protector/base_setting_change.h" |
17 #include "chrome/browser/protector/settings_change_global_error_delegate.h" | 18 #include "chrome/browser/protector/settings_change_global_error_delegate.h" |
18 | 19 |
19 class GURL; | 20 class GURL; |
20 class PrefService; | 21 class PrefService; |
21 class Profile; | 22 class Profile; |
22 class TemplateURLService; | 23 class TemplateURLService; |
23 | 24 |
24 namespace protector { | 25 namespace protector { |
25 | 26 |
| 27 class ProtectedPrefsWatcher; |
26 class SettingsChangeGlobalError; | 28 class SettingsChangeGlobalError; |
27 | 29 |
28 // Presents a SettingChange to user and handles possible user actions. | 30 // Presents a SettingChange to user and handles possible user actions. |
29 class ProtectorService : public ProfileKeyedService, | 31 class ProtectorService : public ProfileKeyedService, |
30 public SettingsChangeGlobalErrorDelegate { | 32 public SettingsChangeGlobalErrorDelegate { |
31 public: | 33 public: |
32 explicit ProtectorService(Profile* profile); | 34 explicit ProtectorService(Profile* profile); |
33 virtual ~ProtectorService(); | 35 virtual ~ProtectorService(); |
34 | 36 |
35 // Shows global error about the specified change. Owns |change|. May be called | 37 // Shows global error about the specified change. Owns |change|. May be called |
(...skipping 22 matching lines...) Expand all Loading... |
58 | 60 |
59 // Returns the most recent change instance or NULL if there are no changes. | 61 // Returns the most recent change instance or NULL if there are no changes. |
60 BaseSettingChange* GetLastChange(); | 62 BaseSettingChange* GetLastChange(); |
61 | 63 |
62 // Returns the Profile instance for this service. | 64 // Returns the Profile instance for this service. |
63 Profile* profile() { return profile_; } | 65 Profile* profile() { return profile_; } |
64 | 66 |
65 private: | 67 private: |
66 friend class ProtectorServiceTest; | 68 friend class ProtectorServiceTest; |
67 | 69 |
68 // Pair of error and corresponding change instance. | 70 // Pair of error and corresponding change instance. linked_ptr is used because |
| 71 // Item instances are stored in a std::vector and must be copyable. |
69 struct Item { | 72 struct Item { |
70 Item(); | 73 Item(); |
71 ~Item(); | 74 ~Item(); |
72 linked_ptr<BaseSettingChange> change; | 75 linked_ptr<BaseSettingChange> change; |
73 linked_ptr<SettingsChangeGlobalError> error; | 76 linked_ptr<SettingsChangeGlobalError> error; |
74 }; | 77 }; |
75 | 78 |
76 // Matches Item by |change| field. | 79 // Matches Item by |change| field. |
77 class MatchItemByChange { | 80 class MatchItemByChange { |
78 public: | 81 public: |
(...skipping 27 matching lines...) Expand all Loading... |
106 virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE; | 109 virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE; |
107 virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE; | 110 virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE; |
108 | 111 |
109 // Pointers to error bubble controllers and corresponding changes in the order | 112 // Pointers to error bubble controllers and corresponding changes in the order |
110 // added. | 113 // added. |
111 std::vector<Item> items_; | 114 std::vector<Item> items_; |
112 | 115 |
113 // Profile which settings we are protecting. | 116 // Profile which settings we are protecting. |
114 Profile* profile_; | 117 Profile* profile_; |
115 | 118 |
| 119 // Observes changes to protected prefs and updates the backup. |
| 120 scoped_ptr<ProtectedPrefsWatcher> prefs_watcher_; |
| 121 |
116 DISALLOW_COPY_AND_ASSIGN(ProtectorService); | 122 DISALLOW_COPY_AND_ASSIGN(ProtectorService); |
117 }; | 123 }; |
118 | 124 |
119 // Signs string value with protector's key. | 125 // Signs string value with protector's key. |
120 std::string SignSetting(const std::string& value); | 126 std::string SignSetting(const std::string& value); |
121 | 127 |
122 // Returns true if the signature is valid for the specified key. | 128 // Returns true if the signature is valid for the specified key. |
123 bool IsSettingValid(const std::string& value, const std::string& signature); | 129 bool IsSettingValid(const std::string& value, const std::string& signature); |
124 | 130 |
125 // Whether the Protector feature is enabled. | 131 // Whether the Protector feature is enabled. |
126 bool IsEnabled(); | 132 bool IsEnabled(); |
127 | 133 |
128 } // namespace protector | 134 } // namespace protector |
129 | 135 |
130 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ | 136 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ |
OLD | NEW |