Home | History | Annotate | Download | only in network
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chromeos/network/favorite_state.h"
      6 
      7 #include "base/logging.h"
      8 #include "base/strings/stringprintf.h"
      9 #include "base/values.h"
     10 #include "chromeos/network/network_event_log.h"
     11 #include "chromeos/network/network_profile_handler.h"
     12 #include "chromeos/network/network_state.h"
     13 #include "third_party/cros_system_api/dbus/service_constants.h"
     14 
     15 namespace chromeos {
     16 
     17 FavoriteState::FavoriteState(const std::string& path)
     18     : ManagedState(MANAGED_TYPE_FAVORITE, path) {
     19 }
     20 
     21 FavoriteState::~FavoriteState() {
     22 }
     23 
     24 bool FavoriteState::PropertyChanged(const std::string& key,
     25                                     const base::Value& value) {
     26   if (ManagedStatePropertyChanged(key, value))
     27     return true;
     28   if (key == flimflam::kProfileProperty) {
     29     return GetStringValue(key, value, &profile_path_);
     30   } else if (key == flimflam::kUIDataProperty) {
     31     if (!NetworkState::GetUIDataFromValue(value, &ui_data_)) {
     32       NET_LOG_ERROR("Failed to parse " + key, path());
     33       return false;
     34     }
     35     return true;
     36   }
     37   return false;
     38 }
     39 
     40 bool FavoriteState::IsManaged() const {
     41   return ui_data_.onc_source() == onc::ONC_SOURCE_DEVICE_POLICY ||
     42       ui_data_.onc_source() == onc::ONC_SOURCE_USER_POLICY;
     43 }
     44 
     45 bool FavoriteState::IsPrivate() const {
     46   return !profile_path_.empty() &&
     47       profile_path_ != NetworkProfileHandler::kSharedProfilePath;
     48 }
     49 
     50 }  // namespace chromeos
     51