| 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 13 matching lines...) Expand all Loading... |
| 49 virtual void ApplyChange(BaseSettingChange* change, Browser* browser); | 51 virtual void ApplyChange(BaseSettingChange* change, Browser* browser); |
| 50 | 52 |
| 51 // Discards |change| and removes corresponding global error. |browser| is the | 53 // Discards |change| and removes corresponding global error. |browser| is the |
| 52 // Browser instance from which the user action originates. | 54 // Browser instance from which the user action originates. |
| 53 virtual void DiscardChange(BaseSettingChange* change, Browser* browser); | 55 virtual void DiscardChange(BaseSettingChange* change, Browser* browser); |
| 54 | 56 |
| 55 // Opens a tab with specified URL in the browser window we've shown error | 57 // Opens a tab with specified URL in the browser window we've shown error |
| 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 |
| 61 // Returns the ProtectedPrefsWatcher instance for access to protected prefs |
| 62 // backup. |
| 63 ProtectedPrefsWatcher* GetPrefsWatcher(); |
| 64 |
| 59 // Returns the most recent change instance or NULL if there are no changes. | 65 // Returns the most recent change instance or NULL if there are no changes. |
| 60 BaseSettingChange* GetLastChange(); | 66 BaseSettingChange* GetLastChange(); |
| 61 | 67 |
| 62 // Returns the Profile instance for this service. | 68 // Returns the Profile instance for this service. |
| 63 Profile* profile() { return profile_; } | 69 Profile* profile() { return profile_; } |
| 64 | 70 |
| 65 private: | 71 private: |
| 66 friend class ProtectorServiceTest; | 72 friend class ProtectorServiceTest; |
| 67 | 73 |
| 68 // Pair of error and corresponding change instance. | 74 // Pair of error and corresponding change instance. linked_ptr is used because |
| 75 // Item instances are stored in a std::vector and must be copyable. |
| 69 struct Item { | 76 struct Item { |
| 70 Item(); | 77 Item(); |
| 71 ~Item(); | 78 ~Item(); |
| 72 linked_ptr<BaseSettingChange> change; | 79 linked_ptr<BaseSettingChange> change; |
| 73 linked_ptr<SettingsChangeGlobalError> error; | 80 linked_ptr<SettingsChangeGlobalError> error; |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 // Matches Item by |change| field. | 83 // Matches Item by |change| field. |
| 77 class MatchItemByChange { | 84 class MatchItemByChange { |
| 78 public: | 85 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // added. | 117 // added. |
| 111 std::vector<Item> items_; | 118 std::vector<Item> items_; |
| 112 | 119 |
| 113 // Profile which settings we are protecting. | 120 // Profile which settings we are protecting. |
| 114 Profile* profile_; | 121 Profile* profile_; |
| 115 | 122 |
| 116 // True if there is a change that has been shown and not yet accepted or | 123 // True if there is a change that has been shown and not yet accepted or |
| 117 // discarded by user. | 124 // discarded by user. |
| 118 bool has_active_change_; | 125 bool has_active_change_; |
| 119 | 126 |
| 127 // Observes changes to protected prefs and updates the backup. |
| 128 scoped_ptr<ProtectedPrefsWatcher> prefs_watcher_; |
| 129 |
| 120 DISALLOW_COPY_AND_ASSIGN(ProtectorService); | 130 DISALLOW_COPY_AND_ASSIGN(ProtectorService); |
| 121 }; | 131 }; |
| 122 | 132 |
| 123 // Signs string value with protector's key. | 133 // Signs string value with protector's key. |
| 124 std::string SignSetting(const std::string& value); | 134 std::string SignSetting(const std::string& value); |
| 125 | 135 |
| 126 // Returns true if the signature is valid for the specified key. | 136 // Returns true if the signature is valid for the specified key. |
| 127 bool IsSettingValid(const std::string& value, const std::string& signature); | 137 bool IsSettingValid(const std::string& value, const std::string& signature); |
| 128 | 138 |
| 129 // Whether the Protector feature is enabled. | 139 // Whether the Protector feature is enabled. |
| 130 bool IsEnabled(); | 140 bool IsEnabled(); |
| 131 | 141 |
| 132 } // namespace protector | 142 } // namespace protector |
| 133 | 143 |
| 134 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ | 144 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ |
| OLD | NEW |