summaryrefslogtreecommitdiffstats
path: root/cloud_print
diff options
context:
space:
mode:
authormaksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-04 18:52:28 +0000
committermaksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-04 18:52:28 +0000
commit872e8e1683de933fe09e948ce42c2dfc6bcdf5b7 (patch)
treebf64225842ed0c7cd76c3c5c61ac86c19704b629 /cloud_print
parent1cde8287acdc1a94c27647c562bd8ece4761e831 (diff)
downloadchromium_src-872e8e1683de933fe09e948ce42c2dfc6bcdf5b7.zip
chromium_src-872e8e1683de933fe09e948ce42c2dfc6bcdf5b7.tar.gz
chromium_src-872e8e1683de933fe09e948ce42c2dfc6bcdf5b7.tar.bz2
GCP2.0 Device: New command line parameter: state-path
BUG= Review URL: https://chromiumcodereview.appspot.com/21296002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215541 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print')
-rw-r--r--cloud_print/gcp20/prototype/command_line_reader.cc24
-rw-r--r--cloud_print/gcp20/prototype/command_line_reader.h5
-rw-r--r--cloud_print/gcp20/prototype/gcp20_device.cc1
-rw-r--r--cloud_print/gcp20/prototype/printer.cc22
-rw-r--r--cloud_print/gcp20/prototype/printer.h4
5 files changed, 43 insertions, 13 deletions
diff --git a/cloud_print/gcp20/prototype/command_line_reader.cc b/cloud_print/gcp20/prototype/command_line_reader.cc
index 0ca8a66..2d9b51e 100644
--- a/cloud_print/gcp20/prototype/command_line_reader.cc
+++ b/cloud_print/gcp20/prototype/command_line_reader.cc
@@ -10,11 +10,17 @@
namespace command_line_reader {
+const char kHttpPortSwitch[] = "http-port";
+const char kTtlSwitch[] = "ttl";
+const char kServiceNameSwitch[] = "service-name";
+const char kDomainNameSwitch[] = "domain-name";
+const char kStatePathSwitch[] = "state-path";
+
uint16 ReadHttpPort(uint16 default_value) {
uint32 http_port = 0;
std::string http_port_string =
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII("http-port");
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kHttpPortSwitch);
if (!base::StringToUint(http_port_string, &http_port))
http_port = default_value;
@@ -32,7 +38,8 @@ uint32 ReadTtl(uint32 default_value) {
uint32 ttl = 0;
if (!base::StringToUint(
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII("ttl"), &ttl)) {
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kTtlSwitch),
+ &ttl)) {
ttl = default_value;
}
@@ -42,14 +49,14 @@ uint32 ReadTtl(uint32 default_value) {
std::string ReadServiceNamePrefix(const std::string& default_value) {
std::string service_name =
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII("service-name");
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kServiceNameSwitch);
return service_name.empty() ? default_value : service_name;
}
std::string ReadDomainName(const std::string& default_value) {
std::string domain_name =
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII("domain-name");
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kDomainNameSwitch);
if (domain_name.empty())
return default_value;
@@ -69,5 +76,14 @@ std::string ReadDomainName(const std::string& default_value) {
return domain_name;
}
+std::string ReadStatePath(const std::string& default_value) {
+ std::string filename =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kStatePathSwitch);
+
+ if (filename.empty())
+ return default_value;
+ return filename;
+}
+
} // namespace command_line_reader
diff --git a/cloud_print/gcp20/prototype/command_line_reader.h b/cloud_print/gcp20/prototype/command_line_reader.h
index cf2ce0c..20be585 100644
--- a/cloud_print/gcp20/prototype/command_line_reader.h
+++ b/cloud_print/gcp20/prototype/command_line_reader.h
@@ -12,10 +12,15 @@
namespace command_line_reader {
uint16 ReadHttpPort(uint16 default_value);
+
uint32 ReadTtl(uint32 default_value);
+
std::string ReadServiceNamePrefix(const std::string& default_value);
+
std::string ReadDomainName(const std::string& default_value);
+std::string ReadStatePath(const std::string& default_value);
+
} // namespace command_line_reader
#endif // CLOUD_PRINT_GCP20_PROTOTYPE_COMMAND_LINE_READER_H_
diff --git a/cloud_print/gcp20/prototype/gcp20_device.cc b/cloud_print/gcp20/prototype/gcp20_device.cc
index e26d45a..01d34ed 100644
--- a/cloud_print/gcp20/prototype/gcp20_device.cc
+++ b/cloud_print/gcp20/prototype/gcp20_device.cc
@@ -33,6 +33,7 @@ const char kHelpMessage[] =
" --domain-name=<name> sets, should ends with '.local'\n"
" --http-port=<value> sets port for HTTP server\n"
" --service-name=<name> sets DNS service name\n"
+ " --state-path=<path> sets path to file with registration state\n"
" --ttl=<value> sets TTL for DNS announcements\n"
"\n"
"WARNING: mDNS probing is not implemented\n";
diff --git a/cloud_print/gcp20/prototype/printer.cc b/cloud_print/gcp20/prototype/printer.cc
index 9421c03..5a252c0 100644
--- a/cloud_print/gcp20/prototype/printer.cc
+++ b/cloud_print/gcp20/prototype/printer.cc
@@ -22,8 +22,7 @@
#include "net/base/net_util.h"
#include "net/base/url_util.h"
-const base::FilePath::CharType kPrinterStatePath[] =
- FILE_PATH_LITERAL("printer_state.json");
+const char kPrinterStatePathDefault[] = "printer_state.json";
namespace {
@@ -145,7 +144,7 @@ bool Printer::Start() {
if (!http_server_.Start(port))
return false;
- if (!LoadFromFile(base::FilePath(kPrinterStatePath)))
+ if (!LoadFromFile())
reg_info_ = RegistrationInfo();
// Starting DNS-SD server.
@@ -537,7 +536,7 @@ void Printer::RememberAccessToken(const std::string& access_token,
kTimeToNextAccessTokenUpdate);
access_token_update_ = Time::Now() + TimeDelta::FromSeconds(time_to_update);
VLOG(1) << "Current access_token: " << access_token;
- SaveToFile(base::FilePath(kPrinterStatePath));
+ SaveToFile();
}
PrivetHttpServer::RegistrationErrorStatus Printer::CheckCommonRegErrors(
@@ -597,7 +596,11 @@ std::vector<std::string> Printer::CreateTxt() const {
return txt;
}
-void Printer::SaveToFile(const base::FilePath& file_path) const {
+void Printer::SaveToFile() const {
+ base::FilePath file_path;
+ file_path = file_path.AppendASCII(
+ command_line_reader::ReadStatePath(kPrinterStatePathDefault));
+
base::DictionaryValue json;
// TODO(maksymb): Get rid of in-place constants.
if (IsRegistered()) {
@@ -624,9 +627,14 @@ void Printer::SaveToFile(const base::FilePath& file_path) const {
LOG(INFO) << "State written to file.";
}
-bool Printer::LoadFromFile(const base::FilePath& file_path) {
- if (!base::PathExists(file_path))
+bool Printer::LoadFromFile() {
+ base::FilePath file_path;
+ file_path = file_path.AppendASCII(
+ command_line_reader::ReadStatePath(kPrinterStatePathDefault));
+ if (!base::PathExists(file_path)) {
+ LOG(INFO) << "Registration info is not found. Printer is unregistered.";
return false;
+ }
LOG(INFO) << "Loading registration info from file.";
std::string json_str;
diff --git a/cloud_print/gcp20/prototype/printer.h b/cloud_print/gcp20/prototype/printer.h
index 7b1ba50..fab9189 100644
--- a/cloud_print/gcp20/prototype/printer.h
+++ b/cloud_print/gcp20/prototype/printer.h
@@ -181,8 +181,8 @@ class Printer : public base::SupportsWeakPtr<Printer>,
std::vector<std::string> CreateTxt() const;
// Saving and loading registration info from file.
- void SaveToFile(const base::FilePath& file_path) const;
- bool LoadFromFile(const base::FilePath& file_path);
+ void SaveToFile() const;
+ bool LoadFromFile();
// Adds |OnIdle| method to the MessageLoop.
void PostOnIdle();