summaryrefslogtreecommitdiffstats
path: root/chrome_frame/ready_mode/internal/registry_ready_mode_state.h
blob: 87076d97918224279d25dc74ac5edf43ceb17ff1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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_FRAME_READY_MODE_INTERNAL_REGISTRY_READY_MODE_STATE_H_
#define CHROME_FRAME_READY_MODE_INTERNAL_REGISTRY_READY_MODE_STATE_H_
#pragma once

#include <string>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "chrome_frame/ready_mode/internal/ready_mode_state.h"

// Defines the possible Ready Mode states.
enum ReadyModeStatus {
  // Chrome Frame is permanently disabled and should be uninstalled.
  READY_MODE_PERMANENTLY_DECLINED,
  // Chrome Frame is temporarily disabled.
  READY_MODE_TEMPORARILY_DECLINED,
  // Chrome Frame is disabled, but should be enabled by calling
  // ExpireTemporaryDecline().
  READY_MODE_TEMPORARY_DECLINE_EXPIRED,
  // Chrome Frame is enabled, but not permanently (the user should be prompted).
  READY_MODE_ACTIVE,
  // Chrome Frame is permanently enabled.
  READY_MODE_ACCEPTED
};

// Implements ReadyModeState, reading state from the Registry and delegating
// to the installer to effect state changes.
//
// If the current process is running at high integrity the installer is
// launched directly. Otherwise, it is launched by invoking a helper exe
// (chrome_launcher) at medium integrity (thanks to an elevation policy) that,
// in turn, delegates to Omaha's ProcessLauncher to reach high integrity.
class RegistryReadyModeState : public ReadyModeState {
 public:
  // Receives notification when the Ready Mode state changes in response to a
  // user interaction. Does not receive notification when a temporary decline of
  // Ready Mode expires.
  class Observer {
   public:
    virtual ~Observer() {}
    // Indicates that a state change has occurred, passing the new status.
    virtual void OnStateChange(ReadyModeStatus status) = 0;
  };

  // Constructs an instance backed by the specified key (pre-existing under
  // HKCU or HKLM). The provided duration indicates how long, after a temporary
  // decline, Ready Mode re-activates.
  //
  // Takes ownership of the Observer instance, which may be null if the client
  // does not need to be notified of changes.
  RegistryReadyModeState(const std::wstring& key_name,
                         base::TimeDelta temporary_decline_duration,
                         Observer* observer);
  virtual ~RegistryReadyModeState();

  // Returns the current Ready Mode status.
  ReadyModeStatus GetStatus();

  // Transitions from temporarily declined to active Ready Mode.
  void ExpireTemporaryDecline();

  // ReadyModeState implementation
  virtual void TemporarilyDeclineChromeFrame();
  virtual void PermanentlyDeclineChromeFrame();
  virtual void AcceptChromeFrame();

 protected:
  // Allows dependency replacement via derivation for tests.
  virtual base::Time GetNow();

 private:
  // Sends the result of GetStatus() to our observer.
  void NotifyObserver();
  // Retrieves state from the registry. Returns true upon success.
  bool GetStateFromRegistry(int64* value, bool* exists);
  // Refreshes the process state after mutating installation state.
  void RefreshStateAndNotify();

  base::TimeDelta temporary_decline_duration_;
  std::wstring key_name_;
  scoped_ptr<Observer> observer_;

  DISALLOW_COPY_AND_ASSIGN(RegistryReadyModeState);
};

#endif  // CHROME_FRAME_READY_MODE_INTERNAL_REGISTRY_READY_MODE_STATE_H_