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

Unified Diff: remoting/host/setup/daemon_controller_delegate_mac.mm

Issue 1272833002: Pass error messages from native messaging to web-app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests. Created 5 years, 4 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/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..5175f3a1cb0a22cd7be19b35e2f335c13adccf33 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,35 @@ 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::string error_message =
+ "Reading config from " + config_file_path.value() + " failed";
+ LOG(ERROR) << error_message;
+ on_error.Run(error_message, 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 +120,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 +133,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 +173,51 @@ 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(&current_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::string error_message =
+ "Failed to save configuration data to: " + config_path.value();
+ LOG(ERROR) << error_message;
+ on_error.Run(error_message, FROM_HERE);
return false;
}
}
@@ -206,20 +226,29 @@ 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::string error_message =
+ "LSOpenFSRef failed for path: " + pane_path.value() + ": " +
+ GetMacOSStatusErrorString(status);
+ LOG(ERROR) << error_message;
+ on_error.Run(error_message, FROM_HERE);
return false;
}

Powered by Google App Engine
This is Rietveld 408576698