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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_FRAME_READY_MODE_INTERNAL_REGISTRY_READY_MODE_STATE_H_ 6 #define CHROME_FRAME_READY_MODE_INTERNAL_REGISTRY_READY_MODE_STATE_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/time/time.h" 13 #include "chrome_frame/ready_mode/internal/ready_mode_state.h" 14 15 // Defines the possible Ready Mode states. 16 enum ReadyModeStatus { 17 // Chrome Frame is permanently disabled and should be uninstalled. 18 READY_MODE_PERMANENTLY_DECLINED, 19 // Chrome Frame is temporarily disabled. 20 READY_MODE_TEMPORARILY_DECLINED, 21 // Chrome Frame is disabled, but should be enabled by calling 22 // ExpireTemporaryDecline(). 23 READY_MODE_TEMPORARY_DECLINE_EXPIRED, 24 // Chrome Frame is enabled, but not permanently (the user should be prompted). 25 READY_MODE_ACTIVE, 26 // Chrome Frame is permanently enabled. 27 READY_MODE_ACCEPTED 28 }; 29 30 // Implements ReadyModeState, reading state from the Registry and delegating 31 // to the installer to effect state changes. 32 // 33 // If the current process is running at high integrity the installer is 34 // launched directly. Otherwise, it is launched by invoking a helper exe 35 // (chrome_launcher) at medium integrity (thanks to an elevation policy) that, 36 // in turn, delegates to Omaha's ProcessLauncher to reach high integrity. 37 class RegistryReadyModeState : public ReadyModeState { 38 public: 39 // Receives notification when the Ready Mode state changes in response to a 40 // user interaction. Does not receive notification when a temporary decline of 41 // Ready Mode expires. 42 class Observer { 43 public: 44 virtual ~Observer() {} 45 // Indicates that a state change has occurred, passing the new status. 46 virtual void OnStateChange(ReadyModeStatus status) = 0; 47 }; 48 49 // Constructs an instance backed by the specified key (pre-existing under 50 // HKCU or HKLM). The provided duration indicates how long, after a temporary 51 // decline, Ready Mode re-activates. 52 // 53 // Takes ownership of the Observer instance, which may be null if the client 54 // does not need to be notified of changes. 55 RegistryReadyModeState(const std::wstring& key_name, 56 base::TimeDelta temporary_decline_duration, 57 Observer* observer); 58 virtual ~RegistryReadyModeState(); 59 60 // Returns the current Ready Mode status. 61 ReadyModeStatus GetStatus(); 62 63 // Transitions from temporarily declined to active Ready Mode. 64 void ExpireTemporaryDecline(); 65 66 // ReadyModeState implementation 67 virtual void TemporarilyDeclineChromeFrame(); 68 virtual void PermanentlyDeclineChromeFrame(); 69 virtual void AcceptChromeFrame(); 70 71 protected: 72 // Allows dependency replacement via derivation for tests. 73 virtual base::Time GetNow(); 74 75 private: 76 // Sends the result of GetStatus() to our observer. 77 void NotifyObserver(); 78 // Retrieves state from the registry. Returns true upon success. 79 bool GetStateFromRegistry(int64* value, bool* exists); 80 // Refreshes the process state after mutating installation state. 81 void RefreshStateAndNotify(); 82 83 base::TimeDelta temporary_decline_duration_; 84 std::wstring key_name_; 85 scoped_ptr<Observer> observer_; 86 87 DISALLOW_COPY_AND_ASSIGN(RegistryReadyModeState); 88 }; 89 90 #endif // CHROME_FRAME_READY_MODE_INTERNAL_REGISTRY_READY_MODE_STATE_H_ 91