Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome_frame/ready_mode/internal/registry_ready_mode_state.cc

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" 5 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "base/task.h" 8 #include "base/task.h"
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 #include "chrome_frame/ready_mode/internal/installation_state.h" 10 #include "chrome_frame/ready_mode/internal/installation_state.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return READY_MODE_ACTIVE; 65 return READY_MODE_ACTIVE;
66 66
67 return READY_MODE_TEMPORARILY_DECLINED; 67 return READY_MODE_TEMPORARILY_DECLINED;
68 } 68 }
69 69
70 bool RegistryReadyModeState::GetValue(int64* value, bool* exists) { 70 bool RegistryReadyModeState::GetValue(int64* value, bool* exists) {
71 *exists = false; 71 *exists = false;
72 *value = 0; 72 *value = 0;
73 73
74 base::win::RegKey config_key; 74 base::win::RegKey config_key;
75 if (!config_key.Open(HKEY_CURRENT_USER, key_name_.c_str(), KEY_QUERY_VALUE)) { 75 LONG result = config_key.Open(HKEY_CURRENT_USER, key_name_.c_str(),
76 DLOG(ERROR) << "Failed to open registry key " << key_name_; 76 KEY_QUERY_VALUE);
77 if (result != ERROR_SUCCESS) {
78 DLOG(ERROR) << "Failed to open registry key: " << key_name_ <<
79 " Error: " << result;
77 return false; 80 return false;
78 } 81 }
79 82
80 if (!config_key.ValueExists(kReadyModeStateValue)) 83 if (!config_key.ValueExists(kReadyModeStateValue))
81 return true; 84 return true;
82 85
83 int64 temp; 86 result = config_key.ReadValueInt64(kReadyModeStateValue, value);
84 DWORD value_size = sizeof(temp); 87 if (result != ERROR_SUCCESS) {
85 DWORD type = 0; 88 DLOG(ERROR) << "Failed to open registry key: " << key_name_ <<
86 if (!config_key.ReadValue(kReadyModeStateValue, &temp, &value_size, &type)) { 89 " Error: " << result;
87 DLOG(ERROR) << "Failed to open registry key " << key_name_;
88 return false; 90 return false;
89 } 91 }
90 92
91 if (value_size != sizeof(temp) || type != REG_QWORD) {
92 DLOG(ERROR) << "Unexpected state found under registry key " << key_name_
93 << " and value " << kReadyModeStateValue;
94 config_key.DeleteValue(kReadyModeStateValue);
95 return true;
96 }
97
98 *value = temp;
99 *exists = true; 93 *exists = true;
100 return true; 94 return true;
101 } 95 }
102 96
103 bool RegistryReadyModeState::StoreValue(int64 value) { 97 bool RegistryReadyModeState::StoreValue(const int64& value) {
104 base::win::RegKey config_key; 98 base::win::RegKey config_key;
105 if (config_key.Open(HKEY_CURRENT_USER, key_name_.c_str(), KEY_SET_VALUE) && 99 LONG result = config_key.Open(HKEY_CURRENT_USER, key_name_.c_str(),
106 config_key.WriteValue(kReadyModeStateValue, &value, sizeof(value), 100 KEY_SET_VALUE);
107 REG_QWORD)) { 101 if (result == ERROR_SUCCESS) {
108 return true; 102 result = config_key.WriteValue(kReadyModeStateValue, &value, sizeof(value),
103 REG_QWORD);
109 } 104 }
110 105
111 DLOG(ERROR) << "Failed to open or write to registry key " << key_name_ 106 if (result != ERROR_SUCCESS) {
112 << " and value " << kReadyModeStateValue; 107 DLOG(ERROR) << "Failed to open or write to registry key " << key_name_
108 << " and value " << kReadyModeStateValue << " Error: "
109 << result;
110 return false;
111 }
robertshield 2011/01/12 15:01:34 More nitty whining: I found the original code easi
113 112
114 return false; 113 return true;
115 } 114 }
116 115
117 void RegistryReadyModeState::TemporarilyDeclineChromeFrame() { 116 void RegistryReadyModeState::TemporarilyDeclineChromeFrame() {
118 int64 value = GetNow().ToInternalValue(); 117 int64 value = GetNow().ToInternalValue();
119 118
120 if (StoreValue(value)) 119 if (StoreValue(value))
121 observer_->OnStateChange(); 120 observer_->OnStateChange();
122 } 121 }
123 122
124 void RegistryReadyModeState::PermanentlyDeclineChromeFrame() { 123 void RegistryReadyModeState::PermanentlyDeclineChromeFrame() {
125 bool success = false; 124 bool success = false;
126 125
127 // Either change, by itself, will deactivate Ready Mode, though we prefer to 126 // Either change, by itself, will deactivate Ready Mode, though we prefer to
128 // also unregister, in order to free up resources. 127 // also unregister, in order to free up resources.
129 128
130 if (StoreValue(0)) 129 if (StoreValue(0))
131 success = true; 130 success = true;
132 131
133 if (installation_state_->UnregisterProduct()) 132 if (installation_state_->UnregisterProduct())
134 success = true; 133 success = true;
135 134
136 if (success) 135 if (success)
137 observer_->OnStateChange(); 136 observer_->OnStateChange();
138 } 137 }
139 138
140 void RegistryReadyModeState::AcceptChromeFrame() { 139 void RegistryReadyModeState::AcceptChromeFrame() {
141 if (installation_state_->InstallProduct()) 140 if (installation_state_->InstallProduct())
142 observer_->OnStateChange(); 141 observer_->OnStateChange();
143 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698