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

Unified Diff: remoting/host/plugin/daemon_controller_win.cc

Issue 10191007: [Chromoting] Let the Windows daemon controller read the unprivileged part of the config without ele… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. 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
« no previous file with comments | « remoting/host/elevated_controller_win.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/plugin/daemon_controller_win.cc
diff --git a/remoting/host/plugin/daemon_controller_win.cc b/remoting/host/plugin/daemon_controller_win.cc
index cb9bebfd83660fdcb58fcf90d224d334e21ad95b..678b695629c18124c8affcf9c7ff782832697494 100644
--- a/remoting/host/plugin/daemon_controller_win.cc
+++ b/remoting/host/plugin/daemon_controller_win.cc
@@ -24,6 +24,7 @@
#include "base/win/scoped_comptr.h"
#include "remoting/base/scoped_sc_handle_win.h"
#include "remoting/host/branding.h"
+#include "remoting/host/daemon_controller_common_win.h"
#include "remoting/host/plugin/daemon_installer_win.h"
// MIDL-generated declarations and definitions.
@@ -310,35 +311,53 @@ DWORD DaemonControllerWin::OpenService(ScopedScHandle* service_out) {
void DaemonControllerWin::DoGetConfig(const GetConfigCallback& callback) {
DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread());
- IDaemonControl* control = NULL;
- HRESULT hr = worker_thread_.ActivateElevatedController(&control);
- if (FAILED(hr)) {
- callback.Run(scoped_ptr<base::DictionaryValue>());
+ scoped_ptr<base::DictionaryValue> dictionary_null(NULL);
+ // Get the name of the configuration file.
+ FilePath dir = remoting::GetConfigDir();
+ FilePath filename = dir.Append(kUnprivilegedConfigFileName);
+
+ // Read raw data from the configuration file.
+ base::win::ScopedHandle file(
+ CreateFileW(filename.value().c_str(),
+ GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_SEQUENTIAL_SCAN,
+ NULL));
+
+ if (!file.IsValid()) {
+ DWORD error = GetLastError();
+ LOG_GETLASTERROR(ERROR)
+ << "Failed to open '" << filename.value() << "'";
+ callback.Run(dictionary_null.Pass());
return;
}
- // Get the host configuration.
- ScopedBstr host_config;
- hr = control->GetConfig(host_config.Receive());
- if (FAILED(hr)) {
- callback.Run(scoped_ptr<base::DictionaryValue>());
+ scoped_array<char> buffer(new char[kMaxConfigFileSize]);
+ DWORD size = kMaxConfigFileSize;
+ if (!::ReadFile(file, &buffer[0], size, &size, NULL)) {
+ DWORD error = GetLastError();
+ LOG_GETLASTERROR(ERROR)
+ << "Failed to read '" << filename.value() << "'";
+ callback.Run(dictionary_null.Pass());
return;
}
- string16 file_content(static_cast<BSTR>(host_config), host_config.Length());
-
- // Parse the string into a dictionary.
- scoped_ptr<base::Value> config(
- base::JSONReader::Read(UTF16ToUTF8(file_content),
- base::JSON_ALLOW_TRAILING_COMMAS));
+ // Parse the JSON configuration, expecting it to contain a dictionary.
+ std::string file_content(buffer.get(), size);
+ scoped_ptr<base::Value> value(
+ base::JSONReader::Read(file_content, base::JSON_ALLOW_TRAILING_COMMAS));
- base::DictionaryValue* dictionary;
- if (config.get() == NULL || !config->GetAsDictionary(&dictionary)) {
- callback.Run(scoped_ptr<base::DictionaryValue>());
+ base::DictionaryValue* dictionary = NULL;
+ if (value.get() == NULL || !value->GetAsDictionary(&dictionary)) {
+ LOG(ERROR) << "Failed to read '" << filename.value() << "'";
+ callback.Run(dictionary_null.Pass());
return;
}
+ // Release value, because dictionary points to the same object.
+ value.release();
- config.release();
callback.Run(scoped_ptr<base::DictionaryValue>(dictionary));
}
@@ -356,7 +375,7 @@ void DaemonControllerWin::DoInstallAsNeededAndStart(
return;
}
- // Otherwise, install it if it's COM registration entry is missing.
+ // Otherwise, install it if its COM registration entry is missing.
if (hr == CO_E_CLASSSTRING) {
scoped_ptr<DaemonInstallerWin> installer = DaemonInstallerWin::Create(
base::Bind(&DaemonControllerWin::OnInstallationComplete,
« no previous file with comments | « remoting/host/elevated_controller_win.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698