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 20 matching lines...) Expand all Loading... |
56 // bubble for. | 58 // bubble for. |
57 virtual void OpenTab(const GURL& url, Browser* browser); | 59 virtual void OpenTab(const GURL& url, Browser* browser); |
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: |
| 68 friend class ProtectedPrefsWatcherTest; |
66 friend class ProtectorServiceTest; | 69 friend class ProtectorServiceTest; |
67 | 70 |
68 // Pair of error and corresponding change instance. | 71 // Pair of error and corresponding change instance. linked_ptr is used because |
| 72 // Item instances are stored in a std::vector and must be copyable. |
69 struct Item { | 73 struct Item { |
70 Item(); | 74 Item(); |
71 ~Item(); | 75 ~Item(); |
72 linked_ptr<BaseSettingChange> change; | 76 linked_ptr<BaseSettingChange> change; |
73 linked_ptr<SettingsChangeGlobalError> error; | 77 linked_ptr<SettingsChangeGlobalError> error; |
74 }; | 78 }; |
75 | 79 |
76 // Matches Item by |change| field. | 80 // Matches Item by |change| field. |
77 class MatchItemByChange { | 81 class MatchItemByChange { |
78 public: | 82 public: |
(...skipping 27 matching lines...) Expand all Loading... |
106 virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE; | 110 virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE; |
107 virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE; | 111 virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE; |
108 | 112 |
109 // Pointers to error bubble controllers and corresponding changes in the order | 113 // Pointers to error bubble controllers and corresponding changes in the order |
110 // added. | 114 // added. |
111 std::vector<Item> items_; | 115 std::vector<Item> items_; |
112 | 116 |
113 // Profile which settings we are protecting. | 117 // Profile which settings we are protecting. |
114 Profile* profile_; | 118 Profile* profile_; |
115 | 119 |
| 120 // Observes changes to protected prefs and updates the backup. |
| 121 scoped_ptr<ProtectedPrefsWatcher> prefs_watcher_; |
| 122 |
116 DISALLOW_COPY_AND_ASSIGN(ProtectorService); | 123 DISALLOW_COPY_AND_ASSIGN(ProtectorService); |
117 }; | 124 }; |
118 | 125 |
119 // Signs string value with protector's key. | 126 // Signs string value with protector's key. |
120 std::string SignSetting(const std::string& value); | 127 std::string SignSetting(const std::string& value); |
121 | 128 |
122 // Returns true if the signature is valid for the specified key. | 129 // Returns true if the signature is valid for the specified key. |
123 bool IsSettingValid(const std::string& value, const std::string& signature); | 130 bool IsSettingValid(const std::string& value, const std::string& signature); |
124 | 131 |
125 // Whether the Protector feature is enabled. | 132 // Whether the Protector feature is enabled. |
126 bool IsEnabled(); | 133 bool IsEnabled(); |
127 | 134 |
128 } // namespace protector | 135 } // namespace protector |
129 | 136 |
130 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ | 137 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ |
OLD | NEW |