Index: chrome_frame/ready_mode/internal/registry_ready_mode_state.cc |
=================================================================== |
--- chrome_frame/ready_mode/internal/registry_ready_mode_state.cc (revision 0) |
+++ chrome_frame/ready_mode/internal/registry_ready_mode_state.cc (revision 0) |
@@ -0,0 +1,143 @@ |
+// Copyright (c) 2010 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. |
+ |
+#include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" |
+ |
+#include "base/time.h" |
+#include "base/task.h" |
+#include "base/win/registry.h" |
+#include "chrome_frame/ready_mode/internal/installation_state.h" |
+#include "chrome_frame/ready_mode/ready_mode_manager.h" |
+ |
+namespace { |
+ |
+const wchar_t kReadyModeStateValue[] = L"ReadyModeState"; |
+ |
+}; // namespace |
+ |
+RegistryReadyModeState::RegistryReadyModeState( |
+ const std::wstring& key_name, int temporary_decline_length_seconds, |
+ InstallationState* installation_state, Observer* observer) |
+ : key_name_(key_name), |
+ temporary_decline_length_seconds_(temporary_decline_length_seconds), |
+ installation_state_(installation_state), |
+ observer_(observer) { |
+} |
+ |
+RegistryReadyModeState::~RegistryReadyModeState() { |
+} |
+ |
+base::Time RegistryReadyModeState::GetNow() { |
+ return base::Time::Now(); |
+} |
+ |
+ReadyModeStatus RegistryReadyModeState::GetStatus() { |
+ if (installation_state_->IsProductInstalled()) |
+ return READY_MODE_ACCEPTED; |
+ |
+ if (!installation_state_->IsProductRegistered()) |
+ return READY_MODE_PERMANENTLY_DECLINED; |
+ |
+ bool exists = false; |
+ int64 value = 0; |
+ |
+ if (!GetValue(&value, &exists)) |
+ return READY_MODE_TEMPORARILY_DECLINED; |
+ |
+ if (!exists) |
+ return READY_MODE_ACTIVE; |
+ |
+ if (value == 0) |
+ return READY_MODE_PERMANENTLY_DECLINED; |
+ |
+ base::Time when_declined(base::Time::FromInternalValue(value)); |
+ int64 seconds_since_declined = (GetNow() - when_declined).InSeconds(); |
+ |
+ // If the decline duration has passed, or is further in the future than |
+ // the total timeout, consider it expired. |
+ bool expired = _abs64(seconds_since_declined) > |
amit
2010/12/09 22:41:33
nit: bool expired = (GetNow() - when_declined) > T
erikwright (departed)
2010/12/10 20:29:58
Done.
|
+ temporary_decline_length_seconds_; |
+ |
+ // To avoid a race-condition in GetValue (between ValueExists and ReadValue) |
+ // we never delete the temporary decline flag. |
+ if (expired) |
+ return READY_MODE_ACTIVE; |
+ |
+ return READY_MODE_TEMPORARILY_DECLINED; |
+} |
+ |
+bool RegistryReadyModeState::GetValue(int64* value, bool* exists) { |
+ *exists = false; |
+ *value = 0; |
+ |
+ base::win::RegKey config_key; |
+ if (!config_key.Open(HKEY_CURRENT_USER, key_name_.c_str(), KEY_ALL_ACCESS)) { |
amit
2010/12/09 22:41:33
nit: KEY_QUERY_VALUE
erikwright (departed)
2010/12/10 20:29:58
Done.
|
+ DPLOG(ERROR) << "Failed to open registry key " << key_name_; |
+ return false; |
+ } |
+ |
+ if (!config_key.ValueExists(kReadyModeStateValue)) |
+ return true; |
+ |
+ int64 temp; |
+ DWORD value_size = sizeof(temp); |
+ DWORD type = 0; |
+ if (!config_key.ReadValue(kReadyModeStateValue, &temp, &value_size, &type)) { |
+ DPLOG(ERROR) << "Failed to open registry key " << key_name_; |
+ return false; |
+ } |
+ |
+ if (value_size != sizeof(temp) || type != REG_QWORD) { |
+ DPLOG(ERROR) << "Unexpected state found under registry key " << key_name_ |
+ << " and value " << kReadyModeStateValue; |
+ config_key.DeleteValue(kReadyModeStateValue); |
+ return true; |
+ } |
+ |
+ *value = temp; |
+ *exists = true; |
+ return true; |
+} |
+ |
+bool RegistryReadyModeState::StoreValue(int64 value) { |
+ base::win::RegKey config_key; |
+ if (config_key.Open(HKEY_CURRENT_USER, key_name_.c_str(), KEY_ALL_ACCESS) && |
amit
2010/12/09 22:41:33
nit: just KEY_SET_VALUE is needed so either use ju
erikwright (departed)
2010/12/10 20:29:58
Done.
|
+ config_key.WriteValue(kReadyModeStateValue, &value, sizeof(value), |
+ REG_QWORD)) { |
+ return true; |
+ } |
+ |
+ DPLOG(ERROR) << "Failed to open or write to registry key " << key_name_ |
+ << " and value " << kReadyModeStateValue; |
+ |
+ return false; |
+} |
+ |
+void RegistryReadyModeState::TemporarilyDeclineChromeFrame() { |
+ int64 value = GetNow().ToInternalValue(); |
+ |
+ if (StoreValue(value)) |
+ observer_->OnStateChange(); |
+} |
+ |
+void RegistryReadyModeState::PermanentlyDeclineChromeFrame() { |
+ bool success = false; |
+ |
+ // Either change, by itself, will deactivate Ready Mode, though we prefer to |
+ // also unregister, in order to free up resources. |
+ |
+ if (StoreValue(0)) |
+ success = true; |
+ |
+ if (installation_state_->UnregisterProduct()) |
+ success = true; |
+ |
+ if (success) |
+ observer_->OnStateChange(); |
+} |
+ |
+void RegistryReadyModeState::AcceptChromeFrame() { |
+ if (installation_state_->InstallProduct()) |
+ observer_->OnStateChange(); |
+} |
Property changes on: chrome_frame\ready_mode\internal\registry_ready_mode_state.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |