summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 01:37:10 +0000
committerlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 01:37:10 +0000
commit56daa02f07b30f00bc4bc723ff4629cb6a4d1874 (patch)
treecd0f298c3e59a9771704ddc6042a287d903c4a8c /remoting
parent83e7756e8c38dd974ca6fabd7a4194322b16e39b (diff)
downloadchromium_src-56daa02f07b30f00bc4bc723ff4629cb6a4d1874.zip
chromium_src-56daa02f07b30f00bc4bc723ff4629cb6a4d1874.tar.gz
chromium_src-56daa02f07b30f00bc4bc723ff4629cb6a4d1874.tar.bz2
Use third_party/jsoncpp in Mac pref-pane
Use third_party JSON library instead of base/json to remove a dependency on code from "base". This is to enable the pref-pane to be built for 64-bit on Mac OS X. Linking to individual files in base/ is not feasible, since any calls to the logging facility cause many files to be pulled in as dependencies, creating a burden for any maintainers of those files. So we prefer to avoid using base/ entirely, until Chrome supports building for 64-bit on Mac OS X. BUG=125116 TEST=manual Review URL: https://chromiumcodereview.appspot.com/10381141 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/DEPS1
-rw-r--r--remoting/host/me2me_preference_pane.h25
-rw-r--r--remoting/host/me2me_preference_pane.mm61
-rw-r--r--remoting/remoting.gyp12
4 files changed, 88 insertions, 11 deletions
diff --git a/remoting/host/DEPS b/remoting/host/DEPS
index 4cedae8..b72988b 100644
--- a/remoting/host/DEPS
+++ b/remoting/host/DEPS
@@ -10,6 +10,7 @@ include_rules = [
"+remoting/protocol",
"+remoting/jingle_glue",
+ "+third_party/jsoncpp",
"+third_party/modp_b64",
"+third_party/npapi",
]
diff --git a/remoting/host/me2me_preference_pane.h b/remoting/host/me2me_preference_pane.h
index 2ed986e..13529d3 100644
--- a/remoting/host/me2me_preference_pane.h
+++ b/remoting/host/me2me_preference_pane.h
@@ -9,9 +9,32 @@
#include <string>
#include "base/memory/scoped_ptr.h"
+#include "third_party/jsoncpp/source/include/json/value.h"
namespace remoting {
-class JsonHostConfig;
+
+// This is an implementation of JsonHostConfig which does not use code from
+// the "base" target, so it can be built for 64-bit on Mac OS X.
+
+// TODO(lambroslambrou): Once the "base" target has 64-bit support, remove this
+// implementation and use the one in remoting/host/json_host_config.h - see
+// http://crbug.com/128122.
+class JsonHostConfig {
+ public:
+ JsonHostConfig(const std::string& filename);
+ ~JsonHostConfig();
+
+ bool Read();
+ bool GetString(const std::string& path, std::string* out_value) const;
+ std::string GetSerializedData() const;
+
+ private:
+ Json::Value config_;
+ std::string filename_;
+
+ DISALLOW_COPY_AND_ASSIGN(JsonHostConfig);
+};
+
}
@interface Me2MePreferencePane : NSPreferencePane {
diff --git a/remoting/host/me2me_preference_pane.mm b/remoting/host/me2me_preference_pane.mm
index f5e0a5a..79acf7c 100644
--- a/remoting/host/me2me_preference_pane.mm
+++ b/remoting/host/me2me_preference_pane.mm
@@ -9,10 +9,11 @@
#include <launch.h>
#import <PreferencePanes/PreferencePanes.h>
#import <SecurityInterface/SFAuthorizationView.h>
+#include <unistd.h>
+
+#include <fstream>
#include "base/eintr_wrapper.h"
-#include "base/file_path.h"
-#include "base/file_util.h"
#include "base/logging.h"
#include "base/mac/authorization_util.h"
#include "base/mac/foundation_util.h"
@@ -23,7 +24,8 @@
#include "base/stringprintf.h"
#include "base/sys_string_conversions.h"
#include "remoting/host/host_config.h"
-#include "remoting/host/json_host_config.h"
+#include "third_party/jsoncpp/source/include/json/reader.h"
+#include "third_party/jsoncpp/source/include/json/writer.h"
#include "third_party/modp_b64/modp_b64.h"
namespace {
@@ -43,10 +45,13 @@ namespace {
// informs the host's launch script of whether the host is enabled or disabled.
const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh";
-bool GetTemporaryConfigFilePath(FilePath* path) {
- if (!file_util::GetTempDir(path))
+bool GetTemporaryConfigFilePath(std::string* path) {
+ NSString* filename = NSTemporaryDirectory();
+ if (filename == nil)
return false;
- *path = path->Append(kServiceName ".json");
+
+ filename = [filename stringByAppendingString:@"/" kServiceName ".json"];
+ *path = [filename UTF8String];
return true;
}
@@ -99,6 +104,42 @@ bool IsPinValid(const std::string& pin, const std::string& host_id,
} // namespace
+namespace remoting {
+JsonHostConfig::JsonHostConfig(const std::string& filename)
+ : filename_(filename) {
+}
+
+JsonHostConfig::~JsonHostConfig() {
+}
+
+bool JsonHostConfig::Read() {
+ std::ifstream file(filename_.c_str());
+ Json::Reader reader;
+ return reader.parse(file, config_, false /* ignore comments */);
+}
+
+bool JsonHostConfig::GetString(const std::string& path,
+ std::string* out_value) const {
+ if (!config_.isObject())
+ return false;
+
+ if (!config_.isMember(path))
+ return false;
+
+ Json::Value value = config_[path];
+ if (!value.isString())
+ return false;
+
+ *out_value = value.asString();
+ return true;
+}
+
+std::string JsonHostConfig::GetSerializedData() const {
+ Json::FastWriter writer;
+ return writer.write(config_);
+}
+
+} // namespace remoting
@implementation Me2MePreferencePane
@@ -220,13 +261,13 @@ bool IsPinValid(const std::string& pin, const std::string& host_id,
}
- (void)readNewConfig {
- FilePath file;
+ std::string file;
if (!GetTemporaryConfigFilePath(&file)) {
LOG(ERROR) << "Failed to get path of configuration data.";
[self showError];
return;
}
- if (!file_util::PathExists(file))
+ if (access(file.c_str(), F_OK) != 0)
return;
scoped_ptr<remoting::JsonHostConfig> new_config_(
@@ -234,11 +275,11 @@ bool IsPinValid(const std::string& pin, const std::string& host_id,
if (!new_config_->Read()) {
// Report the error, because the file exists but couldn't be read. The
// case of non-existence is normal and expected.
- LOG(ERROR) << "Error reading configuration data from " << file.value();
+ LOG(ERROR) << "Error reading configuration data from " << file.c_str();
[self showError];
return;
}
- file_util::Delete(file, false);
+ remove(file.c_str());
if (!IsConfigValid(new_config_.get())) {
LOG(ERROR) << "Invalid configuration data read.";
[self showError];
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 05f5ddb..681cad6 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -383,7 +383,19 @@
'remoting_base',
'remoting_host',
],
+ 'defines': [
+ 'JSON_USE_EXCEPTION=0',
+ ],
+ 'include_dirs': [
+ '../third_party/jsoncpp/overrides/include/',
+ '../third_party/jsoncpp/source/include/',
+ '../third_party/jsoncpp/source/src/lib_json/',
+ ],
'sources': [
+ # The jsoncpp target is not yet built for Mac OS X 64-bit, so
+ # include the files directly, instead of depending on the target.
+ '../third_party/jsoncpp/source/src/lib_json/json_reader.cpp',
+ '../third_party/jsoncpp/source/src/lib_json/json_writer.cpp',
'host/me2me_preference_pane.h',
'host/me2me_preference_pane.mm',
],