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> |
| 10 |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
12 #include "base/message_loop_helpers.h" | 14 #include "base/message_loop_helpers.h" |
13 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
14 #include "chrome/browser/protector/base_setting_change.h" | 16 #include "chrome/browser/protector/base_setting_change.h" |
15 #include "chrome/browser/protector/settings_change_global_error_delegate.h" | 17 #include "chrome/browser/protector/settings_change_global_error_delegate.h" |
16 | 18 |
17 class GURL; | 19 class GURL; |
18 class PrefService; | 20 class PrefService; |
19 class Profile; | 21 class Profile; |
20 class TemplateURLService; | 22 class TemplateURLService; |
21 | 23 |
22 namespace protector { | 24 namespace protector { |
23 | 25 |
24 class SettingsChangeGlobalError; | 26 class SettingsChangeGlobalError; |
25 | 27 |
26 // Presents a SettingChange to user and handles possible user actions. | 28 // Presents a SettingChange to user and handles possible user actions. |
27 class ProtectorService : public ProfileKeyedService, | 29 class ProtectorService : public ProfileKeyedService, |
28 public SettingsChangeGlobalErrorDelegate { | 30 public SettingsChangeGlobalErrorDelegate { |
29 public: | 31 public: |
30 explicit ProtectorService(Profile* profile); | 32 explicit ProtectorService(Profile* profile); |
31 virtual ~ProtectorService(); | 33 virtual ~ProtectorService(); |
32 | 34 |
33 // Shows global error about the specified change. Owns |change|. | 35 // Shows global error about the specified change. Owns |change|. May be called |
34 // TODO(ivankr): handle multiple subsequent changes. | 36 // multiple times in which case subsequent bubbles will be displayed. |
35 virtual void ShowChange(BaseSettingChange* change); | 37 virtual void ShowChange(BaseSettingChange* change); |
36 | 38 |
37 // Returns |true| if a change is currently active (shown by a ShowChange call | 39 // Returns |true| if a change is currently active (shown by a ShowChange call |
38 // and not yet applied or discarded). | 40 // and not yet applied or discarded). |
39 virtual bool IsShowingChange() const; | 41 virtual bool IsShowingChange() const; |
40 | 42 |
41 // Removes global error (including the bubbble if one is shown) and deletes | 43 // Removes corresponding global error (including the bubbble if one is shown) |
42 // the change instance (without calling Apply or Discard on it). | 44 // and deletes the change instance (without calling Apply or Discard on it). |
43 virtual void DismissChange(); | 45 virtual void DismissChange(BaseSettingChange* change); |
44 | 46 |
45 // Persists the change that is currently active and removes global error. | 47 // Persists |change| and removes corresponding global error. |browser| is the |
46 // |browser| is the Browser instance from which the user action originates. | 48 // Browser instance from which the user action originates. |
47 virtual void ApplyChange(Browser* browser); | 49 virtual void ApplyChange(BaseSettingChange* change, Browser* browser); |
48 | 50 |
49 // Discards the change that is currently active and removes global error. | 51 // Discards |change| and removes corresponding global error. |browser| is the |
50 // |browser| is the Browser instance from which the user action originates. | 52 // Browser instance from which the user action originates. |
51 virtual void DiscardChange(Browser* browser); | 53 virtual void DiscardChange(BaseSettingChange* change, Browser* browser); |
52 | 54 |
53 // Opens a tab with specified URL in the browser window we've shown error | 55 // Opens a tab with specified URL in the browser window we've shown error |
54 // bubble for. | 56 // bubble for. |
55 virtual void OpenTab(const GURL& url, Browser* browser); | 57 virtual void OpenTab(const GURL& url, Browser* browser); |
56 | 58 |
57 // Returns the Profile instance we've shown error bubble for. | 59 // Returns the most recent change instance or NULL if there are no changes. |
| 60 BaseSettingChange* GetLastChange(); |
| 61 |
| 62 // Returns the Profile instance for this service. |
58 Profile* profile() { return profile_; } | 63 Profile* profile() { return profile_; } |
59 | 64 |
60 private: | 65 private: |
61 friend class ProtectorServiceTest; | 66 friend class ProtectorServiceTest; |
62 | 67 |
| 68 // Pair of error and corresponding change instance. |
| 69 struct Item { |
| 70 Item(); |
| 71 ~Item(); |
| 72 linked_ptr<BaseSettingChange> change; |
| 73 linked_ptr<SettingsChangeGlobalError> error; |
| 74 }; |
| 75 |
| 76 // Matches Item by |change| field. |
| 77 class MatchItemByChange { |
| 78 public: |
| 79 explicit MatchItemByChange(const BaseSettingChange* other); |
| 80 |
| 81 bool operator()(const Item& item); |
| 82 |
| 83 private: |
| 84 const BaseSettingChange* other_; |
| 85 }; |
| 86 |
| 87 // Matches Item by |error| field. |
| 88 class MatchItemByError { |
| 89 public: |
| 90 explicit MatchItemByError(const SettingsChangeGlobalError* other); |
| 91 |
| 92 bool operator()(const Item& item); |
| 93 |
| 94 private: |
| 95 const SettingsChangeGlobalError* other_; |
| 96 }; |
| 97 |
63 // ProfileKeyedService implementation. | 98 // ProfileKeyedService implementation. |
64 virtual void Shutdown() OVERRIDE; | 99 virtual void Shutdown() OVERRIDE; |
65 | 100 |
66 // SettingsChangeGlobalErrorDelegate implementation. | 101 // SettingsChangeGlobalErrorDelegate implementation. |
67 virtual void OnApplyChange(Browser* browser) OVERRIDE; | 102 virtual void OnApplyChange(SettingsChangeGlobalError* error, |
68 virtual void OnDiscardChange(Browser* browser) OVERRIDE; | 103 Browser* browser) OVERRIDE; |
69 virtual void OnDecisionTimeout() OVERRIDE; | 104 virtual void OnDiscardChange(SettingsChangeGlobalError* error, |
70 virtual void OnRemovedFromProfile() OVERRIDE; | 105 Browser* browser) OVERRIDE; |
| 106 virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE; |
| 107 virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE; |
71 | 108 |
72 // Pointer to error bubble controller. Indicates if we're showing change | 109 // Pointers to error bubble controllers and corresponding changes in the order |
73 // notification to user. | 110 // added. |
74 scoped_ptr<SettingsChangeGlobalError> error_; | 111 std::vector<Item> items_; |
75 | |
76 // Setting change which we're showing. | |
77 scoped_ptr<BaseSettingChange> change_; | |
78 | 112 |
79 // Profile which settings we are protecting. | 113 // Profile which settings we are protecting. |
80 Profile* profile_; | 114 Profile* profile_; |
81 | 115 |
82 DISALLOW_COPY_AND_ASSIGN(ProtectorService); | 116 DISALLOW_COPY_AND_ASSIGN(ProtectorService); |
83 }; | 117 }; |
84 | 118 |
85 // Signs string value with protector's key. | 119 // Signs string value with protector's key. |
86 std::string SignSetting(const std::string& value); | 120 std::string SignSetting(const std::string& value); |
87 | 121 |
88 // Returns true if the signature is valid for the specified key. | 122 // Returns true if the signature is valid for the specified key. |
89 bool IsSettingValid(const std::string& value, const std::string& signature); | 123 bool IsSettingValid(const std::string& value, const std::string& signature); |
90 | 124 |
91 // Whether the Protector feature is enabled. | 125 // Whether the Protector feature is enabled. |
92 bool IsEnabled(); | 126 bool IsEnabled(); |
93 | 127 |
94 } // namespace protector | 128 } // namespace protector |
95 | 129 |
96 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ | 130 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ |
OLD | NEW |