buffet: Move privet options and state into buffet

Now it's a single binary and don't deserve separate configs and states.

BUG=brillo:1211,brillo:1212
CQ-DEPEND=CL:281024
TEST=`FEATURES=test emerge-gizmo buffet`

Change-Id: I5886d3092b8ccba57be5f2f6edf7ddbc36fd199b
Reviewed-on: https://chromium-review.googlesource.com/281018
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/buffet.gyp b/buffet/buffet.gyp
index 1dd7218..3758634 100644
--- a/buffet/buffet.gyp
+++ b/buffet/buffet.gyp
@@ -52,13 +52,11 @@
         'privet/ap_manager_client.cc',
         'privet/cloud_delegate.cc',
         'privet/constants.cc',
-        'privet/daemon_state.cc',
         'privet/device_delegate.cc',
         'privet/openssl_utils.cc',
         'privet/peerd_client.cc',
         'privet/privet_handler.cc',
         'privet/privet_manager.cc',
-        'privet/privetd_conf_parser.cc',
         'privet/security_manager.cc',
         'privet/shill_client.cc',
         'privet/wifi_bootstrap_manager.cc',
@@ -197,7 +195,6 @@
             'notification/xmpp_channel_unittest.cc',
             'notification/xmpp_iq_stanza_handler_unittest.cc',
             'notification/xmpp_stream_parser_unittest.cc',
-            'privet/privetd_conf_parser_unittest.cc',
             'privet/privet_handler_unittest.cc',
             'privet/security_manager_unittest.cc',
             'privet/wifi_ssid_generator_unittest.cc',
diff --git a/buffet/buffet_config.cc b/buffet/buffet_config.cc
index dc3ae97..c89bb2d 100644
--- a/buffet/buffet_config.cc
+++ b/buffet/buffet_config.cc
@@ -4,9 +4,12 @@
 
 #include "buffet/buffet_config.h"
 
+#include <set>
+
 #include <base/files/file_util.h>
 #include <base/logging.h>
 #include <base/strings/string_number_conversions.h>
+#include <chromeos/strings/string_utils.h>
 
 #include "buffet/storage_impls.h"
 #include "buffet/storage_interface.h"
@@ -72,6 +75,10 @@
 const char kRefreshToken[] = "refresh_token";
 const char kDeviceId[] = "device_id";
 const char kRobotAccount[] = "robot_account";
+const char kWifiAutoSetupEnabled[] = "wifi_auto_setup_enabled";
+const char kEmbeddedCodePath[] = "embedded_code_path";
+const char kPairingModes[] = "pairing_modes";
+const char kLastConfiguredSsid[] = "last_configured_ssid";
 
 }  // namespace config_keys
 
@@ -128,6 +135,28 @@
   if (store.GetString(config_keys::kBackupPollingPeriodMs, &polling_period_str))
     CHECK(base::StringToUint64(polling_period_str, &backup_polling_period_ms_));
 
+  store.GetBoolean(config_keys::kWifiAutoSetupEnabled,
+                   &wifi_auto_setup_enabled_);
+
+  std::string embedded_code_path;
+  if (store.GetString(config_keys::kEmbeddedCodePath, &embedded_code_path)) {
+    embedded_code_path_ = base::FilePath(embedded_code_path);
+    if (!embedded_code_path_.empty())
+      pairing_modes_ = {privetd::PairingType::kEmbeddedCode};
+  }
+
+  std::string modes_str;
+  if (store.GetString(config_keys::kPairingModes, &modes_str)) {
+    std::set<privetd::PairingType> pairing_modes;
+    for (const std::string& mode :
+         chromeos::string_utils::Split(modes_str, ",", true, true)) {
+      privetd::PairingType pairing_mode;
+      CHECK(privetd::StringToPairingType(mode, &pairing_mode));
+      pairing_modes.insert(pairing_mode);
+    }
+    pairing_modes_ = std::move(pairing_modes);
+  }
+
   // Empty name set by user or server is allowed, still we expect some
   // meaningfull config value.
   store.GetString(config_keys::kName, &name_);
@@ -198,6 +227,9 @@
   if (dict->GetString(config_keys::kRobotAccount, &tmp))
     set_robot_account(tmp);
 
+  if (dict->GetString(config_keys::kLastConfiguredSsid, &tmp))
+    set_last_configured_ssid(tmp);
+
   if (dict->GetString(config_keys::kDeviceId, &tmp))
     set_device_id(tmp);
 }
@@ -214,6 +246,7 @@
   dict.SetString(config_keys::kRefreshToken, refresh_token_);
   dict.SetString(config_keys::kDeviceId, device_id_);
   dict.SetString(config_keys::kRobotAccount, robot_account_);
+  dict.SetString(config_keys::kLastConfiguredSsid, last_configured_ssid_);
   dict.SetString(config_keys::kName, name_);
   dict.SetString(config_keys::kDescription, description_);
   dict.SetString(config_keys::kLocation, location_);
diff --git a/buffet/buffet_config.h b/buffet/buffet_config.h
index 43202a6..ac04d28 100644
--- a/buffet/buffet_config.h
+++ b/buffet/buffet_config.h
@@ -5,6 +5,7 @@
 #ifndef BUFFET_BUFFET_CONFIG_H_
 #define BUFFET_BUFFET_CONFIG_H_
 
+#include <set>
 #include <string>
 #include <vector>
 
@@ -13,6 +14,8 @@
 #include <chromeos/errors/error.h>
 #include <chromeos/key_value_store.h>
 
+#include "buffet/privet/security_delegate.h"
+
 namespace buffet {
 
 class StorageInterface;
@@ -77,6 +80,9 @@
     void set_robot_account(const std::string& account) {
       config_->robot_account_ = account;
     }
+    void set_last_configured_ssid(const std::string& ssid) {
+      config_->last_configured_ssid_ = ssid;
+    }
 
     void Commit();
 
@@ -101,18 +107,29 @@
     return backup_polling_period_ms_;
   }
 
+  bool wifi_auto_setup_enabled() const { return wifi_auto_setup_enabled_; }
+  const std::set<privetd::PairingType>& pairing_modes() const {
+    return pairing_modes_;
+  }
+  const base::FilePath& embedded_code_path() const {
+    return embedded_code_path_;
+  }
+
   const std::string& name() const { return name_; }
   const std::string& description() const { return description_; }
   const std::string& location() const { return location_; }
-  std::string local_anonymous_access_role() const {
+  const std::string& local_anonymous_access_role() const {
     return local_anonymous_access_role_;
   }
   bool local_pairing_enabled() const { return local_pairing_enabled_; }
   bool local_discovery_enabled() const { return local_discovery_enabled_; }
 
-  std::string device_id() const { return device_id_; }
-  std::string refresh_token() const { return refresh_token_; }
-  std::string robot_account() const { return robot_account_; }
+  const std::string& device_id() const { return device_id_; }
+  const std::string& refresh_token() const { return refresh_token_; }
+  const std::string& robot_account() const { return robot_account_; }
+  const std::string& last_configured_ssid() const {
+    return last_configured_ssid_;
+  }
 
  private:
   bool Save();
@@ -135,9 +152,14 @@
   uint64_t polling_period_ms_{7000};  // 7 seconds.
   uint64_t backup_polling_period_ms_{30 * 60 * 1000};  // 30 minutes.
 
+  bool wifi_auto_setup_enabled_{true};
+  std::set<privetd::PairingType> pairing_modes_{privetd::PairingType::kPinCode};
+  base::FilePath embedded_code_path_;
+
   std::string device_id_;
   std::string refresh_token_;
   std::string robot_account_;
+  std::string last_configured_ssid_;
 
   // Serialization interface to save and load buffet state.
   std::unique_ptr<StorageInterface> storage_;
diff --git a/buffet/buffet_config_unittest.cc b/buffet/buffet_config_unittest.cc
index e1b4b30..f2c7063 100644
--- a/buffet/buffet_config_unittest.cc
+++ b/buffet/buffet_config_unittest.cc
@@ -4,6 +4,8 @@
 
 #include "buffet/buffet_config.h"
 
+#include <set>
+
 #include <base/bind.h>
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
@@ -54,6 +56,11 @@
   EXPECT_EQ("AAAAA", config_->model_id());
   EXPECT_EQ("vendor", config_->device_kind());
   EXPECT_EQ(7000, config_->polling_period_ms());
+  EXPECT_EQ(1800000, config_->backup_polling_period_ms());
+  EXPECT_TRUE(config_->wifi_auto_setup_enabled());
+  EXPECT_EQ(std::set<privetd::PairingType>{privetd::PairingType::kPinCode},
+            config_->pairing_modes());
+  EXPECT_EQ("", config_->embedded_code_path().value());
   EXPECT_EQ("Developer device", config_->name());
   EXPECT_EQ("", config_->description());
   EXPECT_EQ("", config_->location());
@@ -63,6 +70,7 @@
   EXPECT_EQ("", config_->device_id());
   EXPECT_EQ("", config_->refresh_token());
   EXPECT_EQ("", config_->robot_account());
+  EXPECT_EQ("", config_->last_configured_ssid());
 }
 
 TEST_F(BuffetConfigTest, LoadConfig) {
@@ -76,6 +84,11 @@
   config_store.SetString("model_name", "conf_model_name");
   config_store.SetString("model_id", "ABCDE");
   config_store.SetString("polling_period_ms", "12345");
+  config_store.SetString("backup_polling_period_ms", "6589");
+  config_store.SetBoolean("wifi_auto_setup_enabled", false);
+  config_store.SetString("pairing_modes",
+                         "pinCode,embeddedCode,ultrasound32,audible32");
+  config_store.SetString("embedded_code_path", "/conf_code");
   config_store.SetString("name", "conf_name");
   config_store.SetString("description", "conf_description");
   config_store.SetString("location", "conf_location");
@@ -88,6 +101,7 @@
   config_store.SetString("device_id", "conf_device_id");
   config_store.SetString("refresh_token", "conf_refresh_token");
   config_store.SetString("robot_account", "conf_robot_account");
+  config_store.SetString("last_configured_ssid", "conf_last_configured_ssid");
 
   EXPECT_CALL(*this, OnConfigChanged(_)).Times(1);
   config_->Load(config_store);
@@ -102,6 +116,13 @@
   EXPECT_EQ("ABCDE", config_->model_id());
   EXPECT_EQ("developmentBoard", config_->device_kind());
   EXPECT_EQ(12345, config_->polling_period_ms());
+  EXPECT_EQ(6589, config_->backup_polling_period_ms());
+  EXPECT_FALSE(config_->wifi_auto_setup_enabled());
+  std::set<privetd::PairingType> pairing_types{
+      privetd::PairingType::kPinCode, privetd::PairingType::kEmbeddedCode,
+      privetd::PairingType::kUltrasound32, privetd::PairingType::kAudible32};
+  EXPECT_EQ(pairing_types, config_->pairing_modes());
+  EXPECT_EQ("/conf_code", config_->embedded_code_path().value());
   EXPECT_EQ("conf_name", config_->name());
   EXPECT_EQ("conf_description", config_->description());
   EXPECT_EQ("conf_location", config_->location());
@@ -113,6 +134,7 @@
   EXPECT_EQ(default_.device_id(), config_->device_id());
   EXPECT_EQ(default_.refresh_token(), config_->refresh_token());
   EXPECT_EQ(default_.robot_account(), config_->robot_account());
+  EXPECT_EQ(default_.last_configured_ssid(), config_->last_configured_ssid());
 
   // Nothing should be saved yet.
   EXPECT_JSON_EQ("{}", *storage_->Load());
@@ -135,6 +157,7 @@
     'oauth_url': 'conf_oauth_url',
     'refresh_token': '',
     'robot_account': '',
+    'last_configured_ssid': '',
     'service_url': 'conf_service_url'
   })";
   EXPECT_JSON_EQ(expected, *storage_->Load());
@@ -155,6 +178,7 @@
     'oauth_url': 'state_oauth_url',
     'refresh_token': 'state_refresh_token',
     'robot_account': 'state_robot_account',
+    'last_configured_ssid': 'state_last_configured_ssid',
     'service_url': 'state_service_url'
   })";
   storage_->Save(*buffet::unittests::CreateDictionaryValue(state));
@@ -176,6 +200,12 @@
   EXPECT_EQ(default_.model_id(), config_->model_id());
   EXPECT_EQ(default_.device_kind(), config_->device_kind());
   EXPECT_EQ(default_.polling_period_ms(), config_->polling_period_ms());
+  EXPECT_EQ(default_.backup_polling_period_ms(),
+            config_->backup_polling_period_ms());
+  EXPECT_EQ(default_.wifi_auto_setup_enabled(),
+            config_->wifi_auto_setup_enabled());
+  EXPECT_EQ(default_.pairing_modes(), config_->pairing_modes());
+  EXPECT_EQ(default_.embedded_code_path(), config_->embedded_code_path());
   EXPECT_EQ("state_name", config_->name());
   EXPECT_EQ("state_description", config_->description());
   EXPECT_EQ("state_location", config_->location());
@@ -185,6 +215,7 @@
   EXPECT_EQ("state_device_id", config_->device_id());
   EXPECT_EQ("state_refresh_token", config_->refresh_token());
   EXPECT_EQ("state_robot_account", config_->robot_account());
+  EXPECT_EQ("state_last_configured_ssid", config_->last_configured_ssid());
 
   // Nothing should be saved yet.
   EXPECT_JSON_EQ("{}", *storage_->Load());
@@ -253,6 +284,9 @@
   change.set_robot_account("set_account");
   EXPECT_EQ("set_account", config_->robot_account());
 
+  change.set_last_configured_ssid("set_last_configured_ssid");
+  EXPECT_EQ("set_last_configured_ssid", config_->last_configured_ssid());
+
   EXPECT_CALL(*this, OnConfigChanged(_)).Times(1);
   change.Commit();
 
@@ -270,6 +304,7 @@
     'oauth_url': 'set_oauth_url',
     'refresh_token': 'set_token',
     'robot_account': 'set_account',
+    'last_configured_ssid': 'set_last_configured_ssid',
     'service_url': 'set_service_url'
   })";
   EXPECT_JSON_EQ(expected, *storage_->Load());
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h
index 85b4b65..860a8fc 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -147,7 +147,9 @@
                            const std::string& service_url,
                            chromeos::ErrorPtr* error);
 
+  // TODO(vitalybuka): remove getters and pass config to dependent code.
   const BuffetConfig& GetConfig() const { return *config_; }
+  BuffetConfig* GetMutableConfig() { return config_.get(); }
 
   base::WeakPtr<DeviceRegistrationInfo> AsWeakPtr() {
     return weak_factory_.GetWeakPtr();
diff --git a/buffet/manager.cc b/buffet/manager.cc
index bcb5cd6..184baa0 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -360,6 +360,14 @@
 
 void Manager::UpdateWiFiBootstrapState(
     privetd::WifiBootstrapManager::State state) {
+  if (auto wifi = privet_->GetWifiBootstrapManager()) {
+    const std::string& ssid{wifi->GetCurrentlyConnectedSsid()};
+    if (ssid != device_info_->GetConfig().last_configured_ssid()) {
+      BuffetConfig::Transaction change{device_info_->GetMutableConfig()};
+      change.set_last_configured_ssid(ssid);
+    }
+  }
+
   switch (state) {
     case privetd::WifiBootstrapManager::kDisabled:
       dbus_adaptor_.SetWiFiBootstrapState("disabled");
diff --git a/buffet/privet/daemon_state.cc b/buffet/privet/daemon_state.cc
deleted file mode 100644
index cdbe808..0000000
--- a/buffet/privet/daemon_state.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "buffet/privet/daemon_state.h"
-
-namespace privetd {
-
-namespace state_key {
-
-const char kDeviceId[] = "id";
-const char kDeviceName[] = "name";
-const char kDeviceDescription[] = "description";
-const char kDeviceLocation[] = "description";
-
-const char kWifiHasBeenBootstrapped[] = "have_ever_been_bootstrapped";
-const char kWifiLastConfiguredSSID[] = "last_configured_ssid";
-
-}  // namespace state_key
-
-DaemonState::DaemonState(const base::FilePath& state_path)
-    : state_path_(state_path) {
-}
-
-void DaemonState::Init() {
-  Load(state_path_);
-}
-
-void DaemonState::Save() const {
-  KeyValueStore::Save(state_path_);
-}
-
-}  // namespace privetd
diff --git a/buffet/privet/daemon_state.h b/buffet/privet/daemon_state.h
deleted file mode 100644
index a2d7616..0000000
--- a/buffet/privet/daemon_state.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_PRIVET_DAEMON_STATE_H_
-#define BUFFET_PRIVET_DAEMON_STATE_H_
-
-#include <base/files/file_path.h>
-#include <base/macros.h>
-#include <chromeos/key_value_store.h>
-
-namespace privetd {
-
-namespace state_key {
-
-extern const char kDeviceId[];
-extern const char kDeviceName[];
-extern const char kDeviceDescription[];
-extern const char kDeviceLocation[];
-
-extern const char kWifiHasBeenBootstrapped[];
-extern const char kWifiLastConfiguredSSID[];
-
-}  // namespace state_key
-
-class DaemonState : public chromeos::KeyValueStore {
- public:
-  explicit DaemonState(const base::FilePath& state_path);
-  // Load initial state from disk.
-  void Init();
-  // Save state to disk.
-  void Save() const;
-
- private:
-  const base::FilePath state_path_;
-
-  DISALLOW_COPY_AND_ASSIGN(DaemonState);
-};
-
-}  // namespace privetd
-
-#endif  // BUFFET_PRIVET_DAEMON_STATE_H_
diff --git a/buffet/privet/privet_manager.cc b/buffet/privet/privet_manager.cc
index 0365091..2f0dd37 100644
--- a/buffet/privet/privet_manager.cc
+++ b/buffet/privet/privet_manager.cc
@@ -28,14 +28,13 @@
 #include <libwebserv/server.h>
 
 #include "buffet/dbus_constants.h"
+#include "buffet/device_registration_info.h"
 #include "buffet/privet/ap_manager_client.h"
 #include "buffet/privet/cloud_delegate.h"
 #include "buffet/privet/constants.h"
-#include "buffet/privet/daemon_state.h"
 #include "buffet/privet/device_delegate.h"
 #include "buffet/privet/peerd_client.h"
 #include "buffet/privet/privet_handler.h"
-#include "buffet/privet/privetd_conf_parser.h"
 #include "buffet/privet/security_manager.h"
 #include "buffet/privet/shill_client.h"
 #include "buffet/privet/wifi_bootstrap_manager.h"
@@ -49,8 +48,6 @@
 using libwebserv::Request;
 using libwebserv::Response;
 
-const char kDefaultStateFilePath[] = "/var/lib/privetd/privetd.state";
-
 std::string GetFirstHeader(const Request& request, const std::string& name) {
   std::vector<std::string> headers = request.GetHeader(name);
   return headers.empty() ? std::string() : headers.front();
@@ -72,37 +69,22 @@
                     AsyncEventSequencer* sequencer) {
   disable_security_ = options.disable_security;
 
-  // TODO(vitalybuka): switch to BuffetConfig.
-  base::FilePath state_path{privetd::kDefaultStateFilePath};
-
-  state_store_.reset(new DaemonState(state_path));
-  parser_.reset(new PrivetdConfigParser);
-
-  chromeos::KeyValueStore config_store;
-  if (!config_store.Load(options.config_path)) {
-    LOG(ERROR) << "Failed to read privetd config file from "
-               << options.config_path.value();
-  } else {
-    CHECK(parser_->Parse(config_store)) << "Failed to read configuration file.";
-  }
-  state_store_->Init();
-
   device_ = DeviceDelegate::CreateDefault();
   cloud_ = CloudDelegate::CreateDefault(device, command_manager, state_manager);
   cloud_observer_.Add(cloud_.get());
-  security_.reset(new SecurityManager(parser_->pairing_modes(),
-                                      parser_->embedded_code_path(),
+  security_.reset(new SecurityManager(device->GetConfig().pairing_modes(),
+                                      device->GetConfig().embedded_code_path(),
                                       disable_security_));
   shill_client_.reset(new ShillClient(bus, options.device_whitelist));
   shill_client_->RegisterConnectivityListener(
       base::Bind(&Manager::OnConnectivityChanged, base::Unretained(this)));
   ap_manager_client_.reset(new ApManagerClient(bus));
 
-  if (parser_->wifi_auto_setup_enabled()) {
+  if (device->GetConfig().wifi_auto_setup_enabled()) {
     VLOG(1) << "Enabling WiFi bootstrapping.";
-    wifi_bootstrap_manager_.reset(
-        new WifiBootstrapManager(state_store_.get(), shill_client_.get(),
-                                 ap_manager_client_.get(), cloud_.get()));
+    wifi_bootstrap_manager_.reset(new WifiBootstrapManager(
+        device->GetConfig().last_configured_ssid(), shill_client_.get(),
+        ap_manager_client_.get(), cloud_.get()));
     wifi_bootstrap_manager_->Init();
   }
 
diff --git a/buffet/privet/privet_manager.h b/buffet/privet/privet_manager.h
index c54b6f0..72189c0 100644
--- a/buffet/privet/privet_manager.h
+++ b/buffet/privet/privet_manager.h
@@ -42,7 +42,6 @@
 class DeviceDelegate;
 class PeerdClient;
 class PrivetHandler;
-class PrivetdConfigParser;
 class SecurityManager;
 class ShillClient;
 class WifiBootstrapManager;
@@ -99,8 +98,6 @@
       libwebserv::ProtocolHandler* protocol_handler);
 
   bool disable_security_{false};
-  std::unique_ptr<PrivetdConfigParser> parser_;
-  std::unique_ptr<DaemonState> state_store_;
   std::unique_ptr<CloudDelegate> cloud_;
   std::unique_ptr<DeviceDelegate> device_;
   std::unique_ptr<SecurityManager> security_;
diff --git a/buffet/privet/privetd_conf_parser.cc b/buffet/privet/privetd_conf_parser.cc
deleted file mode 100644
index ca08ec8..0000000
--- a/buffet/privet/privetd_conf_parser.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2015 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "buffet/privet/privetd_conf_parser.h"
-
-#include <base/logging.h>
-#include <base/strings/string_number_conversions.h>
-#include <chromeos/strings/string_utils.h>
-
-#include "buffet/privet/security_delegate.h"
-
-namespace privetd {
-
-namespace {
-
-const char kWiFiBootstrapMode[] = "wifi_bootstrapping_mode";
-const char kPairingModes[] = "pairing_modes";
-const char kEmbeddedCodePath[] = "embedded_code_path";
-
-const char kBootstrapModeOff[] = "off";
-
-}  // namespace
-
-PrivetdConfigParser::PrivetdConfigParser()
-    : wifi_auto_setup_enabled_{true}, pairing_modes_{PairingType::kPinCode} {}
-
-bool PrivetdConfigParser::Parse(const chromeos::KeyValueStore& config_store) {
-  std::string wifi_bootstrap_mode_str;
-  // TODO(vitalybuka): switch to boolean.
-  if (config_store.GetString(kWiFiBootstrapMode, &wifi_bootstrap_mode_str)) {
-    wifi_auto_setup_enabled_ = (wifi_bootstrap_mode_str != kBootstrapModeOff);
-  }
-
-  std::set<PairingType> pairing_modes;
-  std::string embedded_code_path;
-  if (config_store.GetString(kEmbeddedCodePath, &embedded_code_path)) {
-    embedded_code_path_ = base::FilePath(embedded_code_path);
-    if (!embedded_code_path_.empty())
-      pairing_modes.insert(PairingType::kEmbeddedCode);
-  }
-
-  std::string modes_str;
-  if (config_store.GetString(kPairingModes, &modes_str)) {
-    for (const std::string& mode :
-         chromeos::string_utils::Split(modes_str, ",", true, true)) {
-      PairingType pairing_mode;
-      if (!StringToPairingType(mode, &pairing_mode)) {
-        LOG(ERROR) << "Invalid pairing mode : " << mode;
-        return false;
-      }
-      pairing_modes.insert(pairing_mode);
-    }
-  }
-
-  if (!pairing_modes.empty())
-    pairing_modes_ = std::move(pairing_modes);
-
-  return true;
-}
-
-}  // namespace privetd
diff --git a/buffet/privet/privetd_conf_parser.h b/buffet/privet/privetd_conf_parser.h
deleted file mode 100644
index db3e6ec..0000000
--- a/buffet/privet/privetd_conf_parser.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2015 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_PRIVET_PRIVETD_CONF_PARSER_H_
-#define BUFFET_PRIVET_PRIVETD_CONF_PARSER_H_
-
-#include <set>
-#include <string>
-
-#include <chromeos/key_value_store.h>
-
-namespace privetd {
-
-enum class PairingType;
-
-class PrivetdConfigParser final {
- public:
-  PrivetdConfigParser();
-
-  bool Parse(const chromeos::KeyValueStore& config_store);
-
-  bool wifi_auto_setup_enabled() const { return wifi_auto_setup_enabled_; }
-  const std::set<PairingType>& pairing_modes() { return pairing_modes_; }
-  const base::FilePath& embedded_code_path() const {
-    return embedded_code_path_;
-  }
-
- private:
-  bool wifi_auto_setup_enabled_;
-  std::set<PairingType> pairing_modes_;
-  base::FilePath embedded_code_path_;
-};
-
-}  // namespace privetd
-
-#endif  // BUFFET_PRIVET_PRIVETD_CONF_PARSER_H_
diff --git a/buffet/privet/privetd_conf_parser_unittest.cc b/buffet/privet/privetd_conf_parser_unittest.cc
deleted file mode 100644
index 86f0322..0000000
--- a/buffet/privet/privetd_conf_parser_unittest.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2015 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "buffet/privet/privetd_conf_parser.h"
-
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-#include <base/files/file_util.h>
-#include <base/files/scoped_temp_dir.h>
-#include <base/logging.h>
-#include <chromeos/strings/string_utils.h>
-#include <gtest/gtest.h>
-
-#include "buffet/privet/security_delegate.h"
-
-using chromeos::string_utils::Join;
-using chromeos::KeyValueStore;
-using std::map;
-using std::string;
-
-namespace privetd {
-
-namespace {
-
-const char kWiFiBootstrapMode[] = "wifi_bootstrapping_mode";
-const char kPairingModes[] = "pairing_modes";
-const char kEmbeddedCodePath[] = "embedded_code_path";
-
-}  // namespace
-
-class PrivetdConfParserTest : public testing::Test {
- public:
-  using ConfDict = map<string, string>;
-
-  void SetUp() override {
-    CHECK(temp_dir_.CreateUniqueTempDir());
-    temp_file_ = temp_dir_.path().Append("temp.conf");
-  }
-
-  void FillKeyValueStore(const ConfDict& conf_dict, KeyValueStore* store) {
-    std::vector<string> file_pieces;
-    for (const auto& it : conf_dict) {
-      file_pieces.push_back(Join("=", it.first, it.second));
-    }
-    string blob{Join("\n", file_pieces)};
-    int expected_len = blob.length();
-    CHECK(expected_len ==
-          base::WriteFile(temp_file_, blob.c_str(), expected_len));
-    CHECK(store->Load(temp_file_));
-  }
-
- private:
-  base::FilePath temp_file_;
-  base::ScopedTempDir temp_dir_;
-};
-
-TEST_F(PrivetdConfParserTest, ShouldParseSettings) {
-  const std::set<PairingType> kExpectedPairingModes{PairingType::kEmbeddedCode,
-                                                    PairingType::kPinCode};
-  static const char kExpectedEmbeddedCodePath[]{"123ABC"};
-  const ConfDict conf_dict{
-      {kWiFiBootstrapMode, "automatic"},
-      {kPairingModes, "pinCode"},
-      {kEmbeddedCodePath, kExpectedEmbeddedCodePath},
-  };
-  KeyValueStore store;
-  FillKeyValueStore(conf_dict, &store);
-  PrivetdConfigParser parser;
-  EXPECT_TRUE(parser.Parse(store));
-  EXPECT_TRUE(parser.wifi_auto_setup_enabled());
-  EXPECT_EQ(kExpectedPairingModes, parser.pairing_modes());
-  EXPECT_EQ(kExpectedEmbeddedCodePath, parser.embedded_code_path().value());
-}
-
-TEST_F(PrivetdConfParserTest, CriticalDefaults) {
-  PrivetdConfigParser parser;
-  EXPECT_TRUE(parser.wifi_auto_setup_enabled());
-  EXPECT_EQ(std::set<PairingType>{PairingType::kPinCode},
-            parser.pairing_modes());
-  EXPECT_TRUE(parser.embedded_code_path().empty());
-}
-
-}  // namespace privetd
diff --git a/buffet/privet/wifi_bootstrap_manager.cc b/buffet/privet/wifi_bootstrap_manager.cc
index da91a11..975717c 100644
--- a/buffet/privet/wifi_bootstrap_manager.cc
+++ b/buffet/privet/wifi_bootstrap_manager.cc
@@ -22,14 +22,15 @@
 const int kMonitorTimeoutSeconds = 120;
 }
 
-WifiBootstrapManager::WifiBootstrapManager(DaemonState* state_store,
-                                           ShillClient* shill_client,
-                                           ApManagerClient* ap_manager_client,
-                                           CloudDelegate* gcd)
-    : state_store_(state_store),
-      shill_client_(shill_client),
-      ap_manager_client_(ap_manager_client),
-      ssid_generator_(gcd, this) {
+WifiBootstrapManager::WifiBootstrapManager(
+    const std::string& last_configured_ssid,
+    ShillClient* shill_client,
+    ApManagerClient* ap_manager_client,
+    CloudDelegate* gcd)
+    : shill_client_{shill_client},
+      ap_manager_client_{ap_manager_client},
+      ssid_generator_{gcd, this},
+      last_configured_ssid_{last_configured_ssid} {
   cloud_observer_.Add(gcd);
 }
 
@@ -38,18 +39,11 @@
   std::string ssid = ssid_generator_.GenerateSsid();
   if (ssid.empty())
     return;  // Delay initialization until ssid_generator_ is ready.
-  chromeos::KeyValueStore state_store;
-  if (!state_store_->GetBoolean(state_key::kWifiHasBeenBootstrapped,
-                                &have_ever_been_bootstrapped_) ||
-      !state_store_->GetString(state_key::kWifiLastConfiguredSSID,
-                               &last_configured_ssid_)) {
-    have_ever_been_bootstrapped_ = false;
-  }
   UpdateConnectionState();
   shill_client_->RegisterConnectivityListener(
       base::Bind(&WifiBootstrapManager::OnConnectivityChange,
                  lifetime_weak_factory_.GetWeakPtr()));
-  if (!have_ever_been_bootstrapped_) {
+  if (last_configured_ssid_.empty()) {
     StartBootstrapping();
   } else {
     StartMonitoring();
@@ -76,7 +70,7 @@
   }
 
   UpdateState(kBootstrapping);
-  if (have_ever_been_bootstrapped_) {
+  if (!last_configured_ssid_.empty()) {
     // If we have been configured before, we'd like to periodically take down
     // our AP and find out if we can connect again.  Many kinds of failures are
     // transient, and having an AP up prohibits us from connecting as a client.
@@ -202,13 +196,7 @@
 
 void WifiBootstrapManager::OnConnectSuccess(const std::string& ssid) {
   VLOG(1) << "Wifi was connected successfully";
-  have_ever_been_bootstrapped_ = true;
   last_configured_ssid_ = ssid;
-  state_store_->SetBoolean(state_key::kWifiHasBeenBootstrapped,
-                           have_ever_been_bootstrapped_);
-  state_store_->SetString(state_key::kWifiLastConfiguredSSID,
-                          last_configured_ssid_);
-  state_store_->Save();
   setup_state_ = SetupState{SetupState::kSuccess};
   StartMonitoring();
 }
@@ -259,9 +247,8 @@
 
 void WifiBootstrapManager::UpdateConnectionState() {
   connection_state_ = ConnectionState{ConnectionState::kUnconfigured};
-  if (!have_ever_been_bootstrapped_) {
+  if (last_configured_ssid_.empty())
     return;
-  }
   ServiceState service_state{shill_client_->GetConnectionState()};
   switch (service_state) {
     case ServiceState::kOffline:
diff --git a/buffet/privet/wifi_bootstrap_manager.h b/buffet/privet/wifi_bootstrap_manager.h
index 81812ef..5f0a4b5 100644
--- a/buffet/privet/wifi_bootstrap_manager.h
+++ b/buffet/privet/wifi_bootstrap_manager.h
@@ -16,7 +16,6 @@
 #include <base/scoped_observer.h>
 
 #include "buffet/privet/cloud_delegate.h"
-#include "buffet/privet/daemon_state.h"
 #include "buffet/privet/privet_types.h"
 #include "buffet/privet/wifi_delegate.h"
 #include "buffet/privet/wifi_ssid_generator.h"
@@ -40,7 +39,7 @@
 
   using StateListener = base::Callback<void(State)>;
 
-  WifiBootstrapManager(DaemonState* state_store,
+  WifiBootstrapManager(const std::string& last_configured_ssid,
                        ShillClient* shill_client,
                        ApManagerClient* ap_manager_client,
                        CloudDelegate* gcd);
@@ -99,13 +98,11 @@
   // It is not persisted to disk.
   SetupState setup_state_{SetupState::kNone};
   ConnectionState connection_state_{ConnectionState::kDisabled};
-  DaemonState* state_store_;
   ShillClient* shill_client_;
   ApManagerClient* ap_manager_client_;
   WifiSsidGenerator ssid_generator_;
 
   std::vector<StateListener> state_listeners_;
-  bool have_ever_been_bootstrapped_{false};
   bool currently_online_{false};
   std::string last_configured_ssid_;