| Index: remoting/host/setup/daemon_controller_delegate_mac.mm
|
| diff --git a/remoting/host/setup/daemon_controller_delegate_mac.mm b/remoting/host/setup/daemon_controller_delegate_mac.mm
|
| index 9821f868a347791b1834ff5c5c1adf9f97ef9bbd..c2cedaa7f76e63272ce753c2b995efc3ff40cb46 100644
|
| --- a/remoting/host/setup/daemon_controller_delegate_mac.mm
|
| +++ b/remoting/host/setup/daemon_controller_delegate_mac.mm
|
| @@ -23,6 +23,7 @@
|
| #include "base/mac/mac_util.h"
|
| #include "base/mac/scoped_launch_data.h"
|
| #include "base/time/time.h"
|
| +#include "base/tracked_objects.h"
|
| #include "base/values.h"
|
| #include "remoting/host/constants_mac.h"
|
| #include "remoting/host/host_config.h"
|
| @@ -68,29 +69,36 @@ scoped_ptr<base::DictionaryValue> DaemonControllerDelegateMac::GetConfig() {
|
| void DaemonControllerDelegateMac::SetConfigAndStart(
|
| scoped_ptr<base::DictionaryValue> config,
|
| bool consent,
|
| - const DaemonController::CompletionCallback& done) {
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| config->SetBoolean(kUsageStatsConsentConfigPath, consent);
|
| - ShowPreferencePane(HostConfigToJson(*config), done);
|
| + ShowPreferencePane(HostConfigToJson(*config), on_done, on_error);
|
| }
|
|
|
| void DaemonControllerDelegateMac::UpdateConfig(
|
| scoped_ptr<base::DictionaryValue> config,
|
| - const DaemonController::CompletionCallback& done) {
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| base::FilePath config_file_path(kHostConfigFilePath);
|
| scoped_ptr<base::DictionaryValue> host_config(
|
| HostConfigFromJsonFile(config_file_path));
|
| if (!host_config) {
|
| - done.Run(DaemonController::RESULT_FAILED);
|
| + std::ostringstream error_message;
|
| + error_message << "Reading config from " << config_file_path.value()
|
| + << " failed";
|
| + LOG(ERROR) << error_message;
|
| + on_error.Run(error_message.str(), FROM_HERE);
|
| return;
|
| }
|
|
|
| host_config->MergeDictionary(config.get());
|
| - ShowPreferencePane(HostConfigToJson(*host_config), done);
|
| + ShowPreferencePane(HostConfigToJson(*host_config), on_done, on_error);
|
| }
|
|
|
| void DaemonControllerDelegateMac::Stop(
|
| - const DaemonController::CompletionCallback& done) {
|
| - ShowPreferencePane("", done);
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| + ShowPreferencePane("", on_done, on_error);
|
| }
|
|
|
| DaemonController::UsageStatsConsent
|
| @@ -113,11 +121,10 @@ DaemonControllerDelegateMac::GetUsageStatsConsent() {
|
|
|
| void DaemonControllerDelegateMac::ShowPreferencePane(
|
| const std::string& config_data,
|
| - const DaemonController::CompletionCallback& done) {
|
| - if (DoShowPreferencePane(config_data)) {
|
| - RegisterForPreferencePaneNotifications(done);
|
| - } else {
|
| - done.Run(DaemonController::RESULT_FAILED);
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| + if (DoShowPreferencePane(config_data, on_error)) {
|
| + RegisterForPreferencePaneNotifications(on_done, on_error);
|
| }
|
| }
|
|
|
| @@ -127,11 +134,14 @@ void DaemonControllerDelegateMac::ShowPreferencePane(
|
| // bounces the invocation to the correct thread, so it doesn't matter
|
| // which thread CompletionCallbacks are called on.
|
| void DaemonControllerDelegateMac::RegisterForPreferencePaneNotifications(
|
| - const DaemonController::CompletionCallback& done) {
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| // We can only have one callback registered at a time. This is enforced by the
|
| // UX flow of the web-app.
|
| - DCHECK(current_callback_.is_null());
|
| - current_callback_ = done;
|
| + DCHECK(on_done_.is_null());
|
| + DCHECK(on_error_.is_null());
|
| + on_done_ = on_done;
|
| + on_error_ = on_error;
|
|
|
| CFNotificationCenterAddObserver(
|
| CFNotificationCenterGetDistributedCenter(),
|
| @@ -164,40 +174,52 @@ void DaemonControllerDelegateMac::DeregisterForPreferencePaneNotifications() {
|
|
|
| void DaemonControllerDelegateMac::PreferencePaneCallbackDelegate(
|
| CFStringRef name) {
|
| - DaemonController::AsyncResult result = DaemonController::RESULT_FAILED;
|
| - if (CFStringCompare(name, CFSTR(UPDATE_SUCCEEDED_NOTIFICATION_NAME), 0) ==
|
| - kCFCompareEqualTo) {
|
| - result = DaemonController::RESULT_OK;
|
| - } else if (CFStringCompare(name, CFSTR(UPDATE_FAILED_NOTIFICATION_NAME), 0) ==
|
| - kCFCompareEqualTo) {
|
| - result = DaemonController::RESULT_FAILED;
|
| + bool success =
|
| + CFStringCompare(name, CFSTR(UPDATE_SUCCEEDED_NOTIFICATION_NAME), 0) ==
|
| + kCFCompareEqualTo;
|
| + bool failure =
|
| + CFStringCompare(name, CFSTR(UPDATE_FAILED_NOTIFICATION_NAME), 0) ==
|
| + kCFCompareEqualTo;
|
| + if (success) {
|
| + on_error_.Reset();
|
| + base::ResetAndReturn(&on_done_).Run();
|
| + } else if (failure) {
|
| + on_done_.Reset();
|
| + std::string error_message =
|
| + "Received failure notification from Preference Pane";
|
| + LOG(ERROR) << error_message;
|
| + base::ResetAndReturn(&on_error_).Run(error_message, FROM_HERE);
|
| } else {
|
| LOG(WARNING) << "Ignoring unexpected notification: " << name;
|
| return;
|
| }
|
|
|
| DeregisterForPreferencePaneNotifications();
|
| -
|
| - DCHECK(!current_callback_.is_null());
|
| - base::ResetAndReturn(¤t_callback_).Run(result);
|
| }
|
|
|
| // static
|
| bool DaemonControllerDelegateMac::DoShowPreferencePane(
|
| - const std::string& config_data) {
|
| + const std::string& config_data,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| if (!config_data.empty()) {
|
| base::FilePath config_path;
|
| if (!base::GetTempDir(&config_path)) {
|
| - LOG(ERROR) << "Failed to get filename for saving configuration data.";
|
| + std::string error_message =
|
| + "Failed to get filename for saving configuration data.";
|
| + LOG(ERROR) << error_message;
|
| + on_error.Run(error_message, FROM_HERE);
|
| return false;
|
| }
|
| - config_path = config_path.Append(kHostConfigFileName);
|
|
|
| + config_path = config_path.Append(kHostConfigFileName);
|
| int written = base::WriteFile(config_path, config_data.data(),
|
| config_data.size());
|
| if (written != static_cast<int>(config_data.size())) {
|
| - LOG(ERROR) << "Failed to save configuration data to: "
|
| - << config_path.value();
|
| + std::ostringstream error_message;
|
| + error_message << "Failed to save configuration data to: "
|
| + << config_path.value();
|
| + LOG(ERROR) << error_message;
|
| + on_error.Run(error_message.str(), FROM_HERE);
|
| return false;
|
| }
|
| }
|
| @@ -206,20 +228,30 @@ bool DaemonControllerDelegateMac::DoShowPreferencePane(
|
| // TODO(lambroslambrou): Use NSPreferencePanesDirectory once we start
|
| // building against SDK 10.6.
|
| if (!base::mac::GetLocalDirectory(NSLibraryDirectory, &pane_path)) {
|
| - LOG(ERROR) << "Failed to get directory for local preference panes.";
|
| + std::string error_message =
|
| + "Failed to get directory for local preference panes.";
|
| + LOG(ERROR) << error_message;
|
| + on_error.Run(error_message, FROM_HERE);
|
| return false;
|
| }
|
| - pane_path = pane_path.Append("PreferencePanes").Append(kPrefPaneFileName);
|
|
|
| + pane_path = pane_path.Append("PreferencePanes").Append(kPrefPaneFileName);
|
| FSRef pane_path_ref;
|
| if (!base::mac::FSRefFromPath(pane_path.value(), &pane_path_ref)) {
|
| - LOG(ERROR) << "Failed to create FSRef";
|
| + std::string error_message = "Failed to create FSRef";
|
| + LOG(ERROR) << error_message;
|
| + on_error.Run(error_message, FROM_HERE);
|
| return false;
|
| }
|
| +
|
| OSStatus status = LSOpenFSRef(&pane_path_ref, nullptr);
|
| if (status != noErr) {
|
| - OSSTATUS_LOG(ERROR, status) << "LSOpenFSRef failed for path: "
|
| - << pane_path.value();
|
| + std::ostringstream error_message;
|
| + error_message << "LSOpenFSRef failed for path: "
|
| + << pane_path.value() << ": "
|
| + << GetMacOSStatusErrorString(status);
|
| + LOG(ERROR) << error_message;
|
| + on_error.Run(error_message.str(), FROM_HERE);
|
| return false;
|
| }
|
|
|
|
|