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

Unified Diff: remoting/host/elevated_controller_win.cc

Issue 10103010: [Chromoting] Implement UpdateConfig() for the Windows host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix syntax. Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/elevated_controller_win.cc
diff --git a/remoting/host/elevated_controller_win.cc b/remoting/host/elevated_controller_win.cc
index e5b655e6439a262484ce1fee3f2527a01293b040..1b419ef462d7d31305972ed904272ff02de5f043 100644
--- a/remoting/host/elevated_controller_win.cc
+++ b/remoting/host/elevated_controller_win.cc
@@ -44,6 +44,9 @@ const size_t kMaxConfigFileSize = 1024 * 1024;
const char kHostId[] = "host_id";
const char kXmppLogin[] = "xmpp_login";
+// The configuration keys that cannot be specified in UpdateConfig().
+const char* kReadonlyKeys[] = { kHostId, kXmppLogin };
Sergey Ulanov 2012/04/17 05:42:18 nit: const char* const kReadonlyKeys[]
simonmorris 2012/04/17 15:55:47 Done.
+
// Reads and parses the configuration file up to |kMaxConfigFileSize| in
// size.
HRESULT ReadConfig(const FilePath& filename,
@@ -327,7 +330,38 @@ STDMETHODIMP ElevatedControllerWin::StopDaemon() {
}
STDMETHODIMP ElevatedControllerWin::UpdateConfig(BSTR config) {
- return E_NOTIMPL;
+ // Parse the config.
+ std::string config_str = UTF16ToUTF8(
+ string16(static_cast<char16*>(config), ::SysStringLen(config)));
+ scoped_ptr<base::Value> config_value(base::JSONReader::Read(config_str));
+ if (!config_value.get()) {
+ return E_FAIL;
+ }
+ base::DictionaryValue* config_dict = NULL;
+ if (!config_value->GetAsDictionary(&config_dict)) {
+ return E_FAIL;
+ }
+ // Check for bad keys.
+ for (int i = 0; i < arraysize(kReadonlyKeys); ++i) {
+ if (config_dict->HasKey(kReadonlyKeys[i])) {
Sergey Ulanov 2012/04/17 05:42:18 Not sure if this is really necessary to verify thi
alexeypa (please no reviews) 2012/04/17 05:51:54 Yes, pretty much. This check has to be on the more
+ return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED);
+ }
+ }
+ // Get the old config.
+ FilePath config_dir = remoting::GetConfigDir();
+ scoped_ptr<base::DictionaryValue> config_old;
+ HRESULT hr = ReadConfig(config_dir.Append(kConfigFileName), &config_old);
+ if (FAILED(hr)) {
+ return hr;
+ }
+ // Merge items from the given config into the old config.
+ config_old->MergeDictionary(config_dict);
+ // Write the updated config.
+ std::string config_updated_str;
+ base::JSONWriter::Write(config_old.get(), &config_updated_str);
+ return WriteConfig(config_dir.Append(kConfigFileName),
+ config_updated_str.c_str(),
+ config_updated_str.size());
}
HRESULT ElevatedControllerWin::OpenService(ScopedScHandle* service_out) {

Powered by Google App Engine
This is Rietveld 408576698