Index: chrome/browser/protector/protector_service.h |
diff --git a/chrome/browser/protector/protector_service.h b/chrome/browser/protector/protector_service.h |
index aae385c4b8c8cc9398849973f2e2da419ff8b348..033bc232bc79307788cf7f41382cf4a8b1cab923 100644 |
--- a/chrome/browser/protector/protector_service.h |
+++ b/chrome/browser/protector/protector_service.h |
@@ -6,9 +6,11 @@ |
#define CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_ |
#pragma once |
+#include <vector> |
+ |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
-#include "base/memory/scoped_ptr.h" |
+#include "base/memory/linked_ptr.h" |
#include "base/message_loop_helpers.h" |
#include "chrome/browser/profiles/profile_keyed_service.h" |
#include "chrome/browser/protector/base_setting_change.h" |
@@ -30,51 +32,89 @@ class ProtectorService : public ProfileKeyedService, |
explicit ProtectorService(Profile* profile); |
virtual ~ProtectorService(); |
- // Shows global error about the specified change. Owns |change|. |
- // TODO(ivankr): handle multiple subsequent changes. |
+ // Shows global error about the specified change. Owns |change|. May be called |
+ // multiple times in which case subsequent bubbles will be displayed. |
virtual void ShowChange(BaseSettingChange* change); |
// Returns |true| if a change is currently active (shown by a ShowChange call |
// and not yet applied or discarded). |
virtual bool IsShowingChange() const; |
- // Removes global error (including the bubbble if one is shown) and deletes |
- // the change instance (without calling Apply or Discard on it). |
- virtual void DismissChange(); |
+ // Removes corresponding global error (including the bubbble if one is shown) |
+ // and deletes the change instance (without calling Apply or Discard on it). |
+ virtual void DismissChange(BaseSettingChange* change); |
- // Persists the change that is currently active and removes global error. |
- // |browser| is the Browser instance from which the user action originates. |
- virtual void ApplyChange(Browser* browser); |
+ // Persists |change| and removes corresponding global error. |browser| is the |
+ // Browser instance from which the user action originates. |
+ virtual void ApplyChange(BaseSettingChange* change, Browser* browser); |
- // Discards the change that is currently active and removes global error. |
- // |browser| is the Browser instance from which the user action originates. |
- virtual void DiscardChange(Browser* browser); |
+ // Discards |change| and removes corresponding global error. |browser| is the |
+ // Browser instance from which the user action originates. |
+ virtual void DiscardChange(BaseSettingChange* change, Browser* browser); |
// Opens a tab with specified URL in the browser window we've shown error |
// bubble for. |
virtual void OpenTab(const GURL& url, Browser* browser); |
- // Returns the Profile instance we've shown error bubble for. |
+ // Returns the most recent change instance or NULL if there are no changes. |
+ BaseSettingChange* GetLastChange(); |
+ |
+ // Returns the Profile instance for this service. |
Profile* profile() { return profile_; } |
private: |
friend class ProtectorServiceTest; |
+ // Pair of error and corresponding change instance. |
+ struct Item { |
+ 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
|
+ linked_ptr<SettingsChangeGlobalError> error; |
+ }; |
+ |
+ // Matches Item by |change| field. |
+ 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 :(
|
+ public: |
+ explicit MatchItemByChange(const BaseSettingChange* other) |
+ : other_(other) { |
+ } |
+ |
+ bool operator()(const Item& item) { |
+ return other_ == item.change.get(); |
+ } |
+ |
+ private: |
+ const BaseSettingChange* other_; |
+ }; |
+ |
+ // Matches Item by |error| field. |
+ class MatchItemByError { |
whywhat
2012/02/29 18:55:14
Or maybe two maps :)
Ivan Korotkov
2012/02/29 19:23:44
Same here.
|
+ public: |
+ explicit MatchItemByError(const SettingsChangeGlobalError* other) |
+ : other_(other) { |
+ } |
+ |
+ bool operator()(const Item& item) { |
+ return other_ == item.error.get(); |
+ } |
+ |
+ private: |
+ const SettingsChangeGlobalError* other_; |
+ }; |
+ |
// ProfileKeyedService implementation. |
virtual void Shutdown() OVERRIDE; |
// SettingsChangeGlobalErrorDelegate implementation. |
- virtual void OnApplyChange(Browser* browser) OVERRIDE; |
- virtual void OnDiscardChange(Browser* browser) OVERRIDE; |
- virtual void OnDecisionTimeout() OVERRIDE; |
- virtual void OnRemovedFromProfile() OVERRIDE; |
- |
- // Pointer to error bubble controller. Indicates if we're showing change |
- // notification to user. |
- scoped_ptr<SettingsChangeGlobalError> error_; |
- |
- // Setting change which we're showing. |
- scoped_ptr<BaseSettingChange> change_; |
+ virtual void OnApplyChange(SettingsChangeGlobalError* error, |
+ Browser* browser) OVERRIDE; |
+ virtual void OnDiscardChange(SettingsChangeGlobalError* error, |
+ Browser* browser) OVERRIDE; |
+ virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE; |
+ virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE; |
+ |
+ // Pointers to error bubble controllers and corresponding changes in the order |
+ // added. |
+ std::vector<Item> items_; |
// Profile which settings we are protecting. |
Profile* profile_; |