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

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

Issue 9500020: ProtectorService supports multiple change instances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test coverage. Created 8 years, 9 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
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 linked_ptr<BaseSettingChange> change;
whywhat 2012/02/29 18:55:14 Something makes me think you need a map actually.
Ivan Korotkov 2012/02/29 19:23:44 As discussed, it's not really needed because cross
71 linked_ptr<SettingsChangeGlobalError> error;
72 };
73
74 // Matches Item by |change| field.
75 class MatchItemByChange {
whywhat 2012/02/29 18:55:14 Why can't you define the classes in the cc file?
Ivan Korotkov 2012/02/29 19:23:44 Done :(
76 public:
77 explicit MatchItemByChange(const BaseSettingChange* other)
78 : other_(other) {
79 }
80
81 bool operator()(const Item& item) {
82 return other_ == item.change.get();
83 }
84
85 private:
86 const BaseSettingChange* other_;
87 };
88
89 // Matches Item by |error| field.
90 class MatchItemByError {
whywhat 2012/02/29 18:55:14 Or maybe two maps :)
Ivan Korotkov 2012/02/29 19:23:44 Same here.
91 public:
92 explicit MatchItemByError(const SettingsChangeGlobalError* other)
93 : other_(other) {
94 }
95
96 bool operator()(const Item& item) {
97 return other_ == item.error.get();
98 }
99
100 private:
101 const SettingsChangeGlobalError* other_;
102 };
103
63 // ProfileKeyedService implementation. 104 // ProfileKeyedService implementation.
64 virtual void Shutdown() OVERRIDE; 105 virtual void Shutdown() OVERRIDE;
65 106
66 // SettingsChangeGlobalErrorDelegate implementation. 107 // SettingsChangeGlobalErrorDelegate implementation.
67 virtual void OnApplyChange(Browser* browser) OVERRIDE; 108 virtual void OnApplyChange(SettingsChangeGlobalError* error,
68 virtual void OnDiscardChange(Browser* browser) OVERRIDE; 109 Browser* browser) OVERRIDE;
69 virtual void OnDecisionTimeout() OVERRIDE; 110 virtual void OnDiscardChange(SettingsChangeGlobalError* error,
70 virtual void OnRemovedFromProfile() OVERRIDE; 111 Browser* browser) OVERRIDE;
112 virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE;
113 virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE;
71 114
72 // Pointer to error bubble controller. Indicates if we're showing change 115 // Pointers to error bubble controllers and corresponding changes in the order
73 // notification to user. 116 // added.
74 scoped_ptr<SettingsChangeGlobalError> error_; 117 std::vector<Item> items_;
75
76 // Setting change which we're showing.
77 scoped_ptr<BaseSettingChange> change_;
78 118
79 // Profile which settings we are protecting. 119 // Profile which settings we are protecting.
80 Profile* profile_; 120 Profile* profile_;
81 121
82 DISALLOW_COPY_AND_ASSIGN(ProtectorService); 122 DISALLOW_COPY_AND_ASSIGN(ProtectorService);
83 }; 123 };
84 124
85 // Signs string value with protector's key. 125 // Signs string value with protector's key.
86 std::string SignSetting(const std::string& value); 126 std::string SignSetting(const std::string& value);
87 127
88 // Returns true if the signature is valid for the specified key. 128 // Returns true if the signature is valid for the specified key.
89 bool IsSettingValid(const std::string& value, const std::string& signature); 129 bool IsSettingValid(const std::string& value, const std::string& signature);
90 130
91 // Whether the Protector feature is enabled. 131 // Whether the Protector feature is enabled.
92 bool IsEnabled(); 132 bool IsEnabled();
93 133
94 } // namespace protector 134 } // namespace protector
95 135
96 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ 136 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698