Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/service/cloud_print/connector_settings.h" | 5 #include "chrome/service/cloud_print/connector_settings.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
| 9 #include "chrome/service/cloud_print/cloud_print_consts.h" | 9 #include "chrome/service/cloud_print/cloud_print_consts.h" |
| 10 #include "chrome/service/cloud_print/print_system.h" | 10 #include "chrome/service/cloud_print/print_system.h" |
| 11 #include "chrome/service/service_process_prefs.h" | 11 #include "chrome/service/service_process_prefs.h" |
| 12 | 12 |
| 13 namespace { | |
| 14 | |
| 15 const char kDeleteOnEnumFail[] = "delete_on_enum_fail"; | 13 const char kDeleteOnEnumFail[] = "delete_on_enum_fail"; |
| 16 | 14 |
| 17 } // namespace | 15 ConnectorSettings::ConnectorSettings() |
| 18 | 16 : remove_missing_printers_(false) { |
| 19 ConnectorSettings::ConnectorSettings() : remove_missing_printers_(false) { | |
| 20 } | 17 } |
| 21 | 18 |
| 22 ConnectorSettings::~ConnectorSettings() { | 19 ConnectorSettings::~ConnectorSettings() { |
| 23 } | 20 } |
| 24 | 21 |
| 25 void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) { | 22 void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) { |
| 26 CopyFrom(ConnectorSettings()); | 23 CopyFrom(ConnectorSettings()); |
| 27 | 24 |
| 28 prefs->GetString(prefs::kCloudPrintProxyId, &proxy_id_); | 25 proxy_id_ = prefs->GetString(prefs::kCloudPrintProxyId, ""); |
| 29 if (proxy_id_.empty()) { | 26 if (proxy_id_.empty()) { |
| 30 proxy_id_ = cloud_print::PrintSystem::GenerateProxyId(); | 27 proxy_id_ = cloud_print::PrintSystem::GenerateProxyId(); |
| 31 prefs->SetString(prefs::kCloudPrintProxyId, proxy_id_); | 28 prefs->SetString(prefs::kCloudPrintProxyId, proxy_id_); |
| 32 prefs->WritePrefs(); | 29 prefs->WritePrefs(); |
| 33 } | 30 } |
| 34 | 31 |
| 35 // Getting print system specific settings from the preferences. | 32 // Getting print system specific settings from the preferences. |
| 36 const base::DictionaryValue* print_system_settings = NULL; | 33 const base::DictionaryValue* print_system_settings = |
| 37 prefs->GetDictionary(prefs::kCloudPrintPrintSystemSettings, | 34 prefs->GetDictionary(prefs::kCloudPrintPrintSystemSettings); |
| 38 &print_system_settings); | |
| 39 if (print_system_settings) { | 35 if (print_system_settings) { |
| 40 print_system_settings_.reset(print_system_settings->DeepCopy()); | 36 print_system_settings_.reset(print_system_settings->DeepCopy()); |
| 41 // TODO(vitalybuka) : Consider to move option from print_system_settings. | 37 // TODO(vitalybuka) : Consider to rename and move out option from |
| 38 // print_system_settings. | |
| 42 print_system_settings_->GetBoolean(kDeleteOnEnumFail, | 39 print_system_settings_->GetBoolean(kDeleteOnEnumFail, |
| 43 &remove_missing_printers_); | 40 &remove_missing_printers_); |
| 44 } | 41 } |
| 45 | 42 |
| 46 // Check if there is an override for the cloud print server URL. | 43 // Check if there is an override for the cloud print server URL. |
| 47 std::string cloud_print_server_url_str; | 44 server_url_ = GURL(prefs->GetString(prefs::kCloudPrintServiceURL, "")); |
| 48 prefs->GetString(prefs::kCloudPrintServiceURL, | 45 DCHECK(server_url_.is_empty() || server_url_.is_valid()); |
| 49 &cloud_print_server_url_str); | 46 if (server_url_.is_empty() || !server_url_.is_valid()) { |
| 50 if (cloud_print_server_url_str.empty()) { | 47 server_url_ = GURL(kDefaultCloudPrintServerUrl); |
| 51 cloud_print_server_url_str = kDefaultCloudPrintServerUrl; | |
| 52 } | 48 } |
| 53 server_url_ = GURL(cloud_print_server_url_str.c_str()); | |
| 54 DCHECK(server_url_.is_valid()); | 49 DCHECK(server_url_.is_valid()); |
| 55 } | 50 } |
| 56 | 51 |
| 57 void ConnectorSettings::CopyFrom(const ConnectorSettings& source) { | 52 void ConnectorSettings::CopyFrom(const ConnectorSettings& source) { |
| 58 server_url_ = source.server_url(); | 53 server_url_ = source.server_url(); |
| 59 proxy_id_ = source.proxy_id(); | 54 proxy_id_ = source.proxy_id(); |
| 55 remove_missing_printers_ = source.remove_missing_printers(); | |
|
gene
2012/09/21 22:57:04
this is from previous CL
| |
| 60 if (source.print_system_settings()) | 56 if (source.print_system_settings()) |
| 61 print_system_settings_.reset(source.print_system_settings()->DeepCopy()); | 57 print_system_settings_.reset(source.print_system_settings()->DeepCopy()); |
| 62 } | 58 } |
| 63 | 59 |
| OLD | NEW |