Chromium Code Reviews| Index: chrome/browser/protector/protector.h |
| diff --git a/chrome/browser/protector/protector.h b/chrome/browser/protector/protector.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3a9d845f60aa2a17dd5e19fb6f4adad3702097c1 |
| --- /dev/null |
| +++ b/chrome/browser/protector/protector.h |
| @@ -0,0 +1,144 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ |
| +#define CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ |
| +#pragma once |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/string16.h" |
| + |
| +class GURL; |
| +class KeywordTable; |
| +class TemplateURLService; |
| + |
| +namespace protector { |
| + |
| +class Protector; |
| +class SettingsChangeGlobalError; |
| + |
| +// Base class for setting change tracked by Protector. |
| +class SettingChange : public base::RefCountedThreadSafe<SettingChange> { |
|
Ivan Korotkov
2011/10/19 20:24:37
Please split all these classes into separate files
whywhat
2011/10/20 20:50:10
Done.
|
| + public: |
| + // IDs of changes Protector currently tracks. |
| + enum Type { |
| + // Default search engine has been changed. |
| + kSearchEngineChanged, |
| + |
| + // Home page has been changed. |
| + kHomePageChanged, |
| + }; |
| + |
| + explicit SettingChange(Type type) : type_(type) {} |
| + |
| + Type type() const { return type_; } |
| + |
| + // Returns the old setting presentation to be shown to user. |
| + // Returns empty string if the old setting is unavailable. |
| + virtual const string16& GetOldSetting() const = 0; |
| + |
| + // Returns the new setting presentation to be shown to user. |
| + virtual const string16& GetNewSetting() const = 0; |
| + |
| + // Persists new setting if needed. |
| + virtual void Accept(Protector* protector) {} |
| + |
| + // Restores old setting value if needed. |
| + virtual void Revert(Protector* protector) {} |
| + |
| + protected: |
| + virtual ~SettingChange() {} |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<SettingChange>; |
| + |
| + // Type of the change. Used for strings lookup by UI. |
| + Type type_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SettingChange); |
| +}; |
| + |
| +class DefaultSearchProviderChange : public SettingChange { |
|
Ivan Korotkov
2011/10/19 20:24:37
This is a pure implementation, so it can be declar
whywhat
2011/10/20 20:50:10
Done.
|
| + public: |
| + DefaultSearchProviderChange( |
| + KeywordTable* table, |
| + int64 old_id, |
| + int64 new_id); |
| + |
| + // SettingChange overrides: |
| + virtual const string16& GetOldSetting() const OVERRIDE; |
| + virtual const string16& GetNewSetting() const OVERRIDE; |
| + virtual void Accept(Protector* protector) OVERRIDE; |
| + virtual void Revert(Protector* protector) OVERRIDE; |
| + |
| + private: |
| + ~DefaultSearchProviderChange(); |
| + |
| + // ID of the new default search provider to be accepted. |
| + int64 new_id_; |
| + |
| + // Short name of the old default search provider. |
| + string16 old_name_; |
| + |
| + // Short name of the new default search provider. |
| + string16 new_name_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange); |
| +}; |
| + |
| +// Accumulates search engine changes and shows them altogether to user. |
| +class Protector : public base::RefCountedThreadSafe<Protector> { |
| + public: |
| + typedef std::vector<scoped_refptr<SettingChange> > ChangesVector; |
| + |
| + Protector(); |
| + |
| + // Add info about single setting change to the list of changes to notify |
| + // about. Does nothing if we're showing changes already. |
| + void AddChange(scoped_refptr<SettingChange> change); |
| + |
| + // Shows error bubble to user about settings changes. The result is either |
| + // accept or decline of the change. |
| + void NotifyUser(); |
| + |
| + // Callback for the case when user accepts the change. |
| + void OnChangesAccepted(); |
| + |
| + // Callback for the case when user declines the change. |
| + void OnChangesDeclined(); |
| + |
| + // Opens a tab with specified URL. |
| + void OpenTab(const GURL& url); |
| + |
| + // Returns TemplateURLService. |
| + TemplateURLService* GetTemplateURLService(); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<Protector>; |
| + ~Protector(); |
| + |
| + // All changes we want to show. |
| + ChangesVector changes_; |
| + |
| + // Pointer to error bubble controller. Indicates if we're showing change |
| + // notification to user. |
| + SettingsChangeGlobalError* error_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Protector); |
| +}; |
| + |
| +// Shows notification about a single setting change. |
| +void NotifyUserOfChange(scoped_refptr<SettingChange> change); |
|
Ivan Korotkov
2011/10/19 20:24:37
I'd make this a static method of Protector.
whywhat
2011/10/20 20:50:10
It would be protector::Protector::NotifyUserOfChan
|
| + |
| +// Signs string value with protector's key. |
| +std::string Sign(const std::string& value); |
|
Ivan Korotkov
2011/10/19 20:24:37
Maybe give it a more descriptive name? Like 'SignS
whywhat
2011/10/20 20:50:10
Done.
|
| + |
| +} // namespace protector |
| + |
| +#endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ |