| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ |
| 6 #define CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ | 6 #define CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "chrome/browser/protector/setting_change.h" | 13 #include "chrome/browser/protector/setting_change.h" |
| 14 #include "chrome/browser/protector/settings_change_global_error_delegate.h" | 14 #include "chrome/browser/protector/settings_change_global_error_delegate.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 class Profile; | 17 class Profile; |
| 18 class TemplateURLService; | 18 class TemplateURLService; |
| 19 | 19 |
| 20 namespace protector { | 20 namespace protector { |
| 21 | 21 |
| 22 class SettingsChangeGlobalError; | 22 class SettingsChangeGlobalError; |
| 23 | 23 |
| 24 // Presents a SettingChange to user and handles possible user actions. | 24 // Accumulates settings changes and shows them altogether to user. |
| 25 // Deletes itself after a user action is taken or timeout expires. | 25 // Deletes itself when changes are shown to the user and some action is taken |
| 26 // or timeout expires. |
| 26 class Protector : public SettingsChangeGlobalErrorDelegate { | 27 class Protector : public SettingsChangeGlobalErrorDelegate { |
| 27 public: | 28 public: |
| 28 explicit Protector(Profile* profile); | 29 explicit Protector(Profile* profile); |
| 29 | 30 |
| 30 // Opens a tab with specified URL in the browser window we've shown error | 31 // Opens a tab with specified URL in the browser window we've shown error |
| 31 // bubble for. | 32 // bubble for. |
| 32 void OpenTab(const GURL& url); | 33 void OpenTab(const GURL& url); |
| 33 | 34 |
| 34 // Returns TemplateURLService for the profile we've shown error bubble | 35 // Returns TemplateURLService for the profile we've shown error bubble |
| 35 // for. | 36 // for. |
| 36 TemplateURLService* GetTemplateURLService(); | 37 TemplateURLService* GetTemplateURLService(); |
| 37 | 38 |
| 38 // Shows global error about the specified change. Ownership of the change | 39 // Shows global error about the specified change. Ownership of the change |
| 39 // is passed to the GlobalError object. | 40 // is passed to the error object. |
| 40 void ShowChange(SettingChange* change); | 41 void ShowChange(SettingChange* change); |
| 41 | 42 |
| 42 // SettingsChangeGlobalErrorDelegate implementation. | 43 // SettingsChangeGlobalErrorDelegate implementation. |
| 43 virtual void OnApplyChange() OVERRIDE; | 44 virtual void OnApplyChanges() OVERRIDE; |
| 44 virtual void OnDiscardChange() OVERRIDE; | 45 virtual void OnDiscardChanges() OVERRIDE; |
| 45 virtual void OnDecisionTimeout() OVERRIDE; | 46 virtual void OnDecisionTimeout() OVERRIDE; |
| 46 virtual void OnRemovedFromProfile() OVERRIDE; | 47 virtual void OnRemovedFromProfile() OVERRIDE; |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 friend class DeleteTask<Protector>; | 50 friend class DeleteTask<Protector>; |
| 50 | 51 |
| 51 // The object can only be allocated and destroyed on heap. | 52 // The object can only be allocated and destroyed on heap. |
| 52 virtual ~Protector(); | 53 virtual ~Protector(); |
| 53 | 54 |
| 54 // Performs the initial action on settings change and shows it. This is run | 55 // Common handler for error delegate handlers. Calls the specified method |
| 55 // asynchronously on UI thread because |ShowChange| may be called in the | 56 // on each change we showed error for. |
| 56 // middle of some operations on settings that have changed. | 57 void OnChangesAction(SettingChangeAction action); |
| 57 void InitAndShowChange(SettingChange* change); | |
| 58 | 58 |
| 59 // Pointer to error bubble controller. Indicates if we're showing change | 59 // Pointer to error bubble controller. Indicates if we're showing change |
| 60 // notification to user. Owns itself. | 60 // notification to user. Owns itself. |
| 61 scoped_ptr<SettingsChangeGlobalError> error_; | 61 scoped_ptr<SettingsChangeGlobalError> error_; |
| 62 | 62 |
| 63 // Profile which settings we are protecting. | 63 // Profile which settings we are protecting. |
| 64 Profile* profile_; | 64 Profile* profile_; |
| 65 | 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(Protector); | 66 DISALLOW_COPY_AND_ASSIGN(Protector); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 // Signs string value with protector's key. | 69 // Signs string value with protector's key. |
| 70 std::string SignSetting(const std::string& value); | 70 std::string SignSetting(const std::string& value); |
| 71 | 71 |
| 72 // Returns true if the signature is valid for the specified key. | 72 // Returns true if the signature is valid for the specified key. |
| 73 bool IsSettingValid(const std::string& value, const std::string& signature); | 73 bool IsSettingValid(const std::string& value, const std::string& signature); |
| 74 | 74 |
| 75 } // namespace protector | 75 } // namespace protector |
| 76 | 76 |
| 77 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ | 77 #endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_H_ |
| OLD | NEW |