diff options
author | Bo Liu <boliu@google.com> | 2014-05-01 10:37:37 -0700 |
---|---|---|
committer | Bo Liu <boliu@google.com> | 2014-05-01 10:37:37 -0700 |
commit | 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1 (patch) | |
tree | 5df224c921d52ab02739b38e2149652208b023e6 /chromeos | |
parent | 56e9d6e218656f3d05620cc9877fd61482337fb1 (diff) | |
download | chromium_org-5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1.tar.gz |
Merge from Chromium at DEPS revision 267519
This commit was generated by merge_to_master.py.
Change-Id: I6002987b71e09742c68bad9c834ae800ff531f25
Diffstat (limited to 'chromeos')
27 files changed, 329 insertions, 55 deletions
diff --git a/chromeos/CHROMEOS_LKGM b/chromeos/CHROMEOS_LKGM index 8a7aa153e3..8069ab7803 100644 --- a/chromeos/CHROMEOS_LKGM +++ b/chromeos/CHROMEOS_LKGM @@ -1 +1 @@ -5783.0.0
\ No newline at end of file +5795.0.0
\ No newline at end of file diff --git a/chromeos/chromeos_switches.cc b/chromeos/chromeos_switches.cc index 32c1909333..b69b538f16 100644 --- a/chromeos/chromeos_switches.cc +++ b/chromeos/chromeos_switches.cc @@ -15,6 +15,9 @@ const char kAppOemManifestFile[] = "app-mode-oem-manifest"; // Possible values: parallel|postpone. Default: parallel. const char kAshWebUIInit[] = "ash-webui-init"; +// Specifies the URL of the consumer device management backend. +const char kConsumerDeviceManagementUrl[] = "consumer-device-management-url"; + // Forces the stub implementation of dbus clients. const char kDbusStub[] = "dbus-stub"; @@ -142,7 +145,8 @@ const char kLoginManager[] = "login-manager"; // Specifies a password to be used to login (along with login-user). const char kLoginPassword[] = "login-password"; -// Specifies the profile to use once a chromeos user is logged in. +// Specifies the profile to use once a chromeos user is logged in. This is +// required unless --multi-profile is set. const char kLoginProfile[] = "login-profile"; // Specifies the user which is already logged in. diff --git a/chromeos/chromeos_switches.h b/chromeos/chromeos_switches.h index 17d2d47396..18b7685dec 100644 --- a/chromeos/chromeos_switches.h +++ b/chromeos/chromeos_switches.h @@ -22,6 +22,7 @@ namespace switches { // Please keep alphabetized. CHROMEOS_EXPORT extern const char kAppOemManifestFile[]; CHROMEOS_EXPORT extern const char kAshWebUIInit[]; +CHROMEOS_EXPORT extern const char kConsumerDeviceManagementUrl[]; CHROMEOS_EXPORT extern const char kDbusStub[]; CHROMEOS_EXPORT extern const char kDerelictDetectionTimeout[]; CHROMEOS_EXPORT extern const char kDerelictIdleTimeout[]; diff --git a/chromeos/dbus/debug_daemon_client.cc b/chromeos/dbus/debug_daemon_client.cc index 73d86aebf0..2c81c17fd8 100644 --- a/chromeos/dbus/debug_daemon_client.cc +++ b/chromeos/dbus/debug_daemon_client.cc @@ -222,6 +222,7 @@ class DebugDaemonClientImpl : public DebugDaemonClient { } pipe_reader_.reset(new PipeReaderForString( + base::WorkerPool::GetTaskRunner(true /* task_is_slow */), base::Bind(&DebugDaemonClientImpl::OnIOComplete, weak_ptr_factory_.GetWeakPtr()))); int write_fd = -1; diff --git a/chromeos/dbus/fake_session_manager_client.cc b/chromeos/dbus/fake_session_manager_client.cc index 306ade59bb..21f50c6a37 100644 --- a/chromeos/dbus/fake_session_manager_client.cc +++ b/chromeos/dbus/fake_session_manager_client.cc @@ -46,11 +46,14 @@ void FakeSessionManagerClient::RestartJob(int pid, const std::string& command_line) { } -void FakeSessionManagerClient::StartSession(const std::string& user_email) { +void FakeSessionManagerClient::StartSession( + const std::string& user_email, + const StartSessionCallback& callback) { DCHECK_EQ(0UL, user_sessions_.count(user_email)); std::string user_id_hash = CryptohomeClient::GetStubSanitizedUsername(user_email); user_sessions_[user_email] = user_id_hash; + base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true)); } void FakeSessionManagerClient::StopSession() { diff --git a/chromeos/dbus/fake_session_manager_client.h b/chromeos/dbus/fake_session_manager_client.h index 80dec1ab3d..e0cabcebfa 100644 --- a/chromeos/dbus/fake_session_manager_client.h +++ b/chromeos/dbus/fake_session_manager_client.h @@ -30,7 +30,8 @@ class FakeSessionManagerClient : public SessionManagerClient { virtual bool HasObserver(Observer* observer) OVERRIDE; virtual void EmitLoginPromptVisible() OVERRIDE; virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE; - virtual void StartSession(const std::string& user_email) OVERRIDE; + virtual void StartSession(const std::string& user_email, + const StartSessionCallback& callback) OVERRIDE; virtual void StopSession() OVERRIDE; virtual void StartDeviceWipe() OVERRIDE; virtual void RequestLockScreen() OVERRIDE; diff --git a/chromeos/dbus/fake_system_clock_client.cc b/chromeos/dbus/fake_system_clock_client.cc index 92a8dd37a3..c744bdd0f2 100644 --- a/chromeos/dbus/fake_system_clock_client.cc +++ b/chromeos/dbus/fake_system_clock_client.cc @@ -25,4 +25,11 @@ bool FakeSystemClockClient::HasObserver(Observer* observer) { return false; } +void FakeSystemClockClient::SetTime(int64 time_in_seconds) { +} + +bool FakeSystemClockClient::CanSetTime() { + return true; +} + } // namespace chromeos diff --git a/chromeos/dbus/fake_system_clock_client.h b/chromeos/dbus/fake_system_clock_client.h index 18c8b2d496..c109611edf 100644 --- a/chromeos/dbus/fake_system_clock_client.h +++ b/chromeos/dbus/fake_system_clock_client.h @@ -20,6 +20,8 @@ class CHROMEOS_EXPORT FakeSystemClockClient : public SystemClockClient { virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool HasObserver(Observer* observer) OVERRIDE; + virtual void SetTime(int64 time_in_seconds) OVERRIDE; + virtual bool CanSetTime() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(FakeSystemClockClient); diff --git a/chromeos/dbus/mock_session_manager_client.h b/chromeos/dbus/mock_session_manager_client.h index bde311376b..aa7e271991 100644 --- a/chromeos/dbus/mock_session_manager_client.h +++ b/chromeos/dbus/mock_session_manager_client.h @@ -24,7 +24,8 @@ class MockSessionManagerClient : public SessionManagerClient { MOCK_METHOD1(HasObserver, bool(Observer*)); MOCK_METHOD0(EmitLoginPromptVisible, void(void)); MOCK_METHOD2(RestartJob, void(int, const std::string&)); - MOCK_METHOD1(StartSession, void(const std::string&)); + MOCK_METHOD2(StartSession, + void(const std::string&, const StartSessionCallback&)); MOCK_METHOD0(StopSession, void(void)); MOCK_METHOD0(StartDeviceWipe, void(void)); MOCK_METHOD0(RequestLockScreen, void(void)); diff --git a/chromeos/dbus/pipe_reader.cc b/chromeos/dbus/pipe_reader.cc index 547a974908..1e91d75b4f 100644 --- a/chromeos/dbus/pipe_reader.cc +++ b/chromeos/dbus/pipe_reader.cc @@ -7,13 +7,18 @@ #include "base/bind.h" #include "base/platform_file.h" #include "base/posix/eintr_wrapper.h" +#include "base/task_runner.h" +#include "net/base/file_stream.h" +#include "net/base/io_buffer.h" #include "net/base/net_errors.h" namespace chromeos { -PipeReader::PipeReader(PipeReader::IOCompleteCallback callback) +PipeReader::PipeReader(const scoped_refptr<base::TaskRunner>& task_runner, + const IOCompleteCallback& callback) : write_fd_(-1), io_buffer_(new net::IOBufferWithSize(4096)), + task_runner_(task_runner), callback_(callback), weak_ptr_factory_(this) {} @@ -42,7 +47,8 @@ bool PipeReader::StartIO() { // Pass ownership of pipe_fds[0] to data_stream_, which will will close it. data_stream_.reset(new net::FileStream( data_file_, - base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC)); + base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC, + task_runner_)); // Post an initial async read to setup data collection int rv = data_stream_->Read( @@ -75,7 +81,10 @@ void PipeReader::OnDataReady(int byte_count) { } PipeReaderForString::PipeReaderForString( - PipeReader::IOCompleteCallback callback) : PipeReader(callback) {} + const scoped_refptr<base::TaskRunner>& task_runner, + const IOCompleteCallback& callback) + : PipeReader(task_runner, callback) { +} void PipeReaderForString::AcceptData(const char *data, int byte_count) { data_.append(data, byte_count); diff --git a/chromeos/dbus/pipe_reader.h b/chromeos/dbus/pipe_reader.h index bae17231eb..59d291ba68 100644 --- a/chromeos/dbus/pipe_reader.h +++ b/chromeos/dbus/pipe_reader.h @@ -5,10 +5,21 @@ #ifndef CHROMEOS_DBUS_PIPE_READER_H_ #define CHROMEOS_DBUS_PIPE_READER_H_ +#include <string> + #include "base/callback.h" -#include "base/memory/ref_counted_memory.h" -#include "net/base/file_stream.h" -#include "net/base/io_buffer.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" + +namespace base { +class TaskRunner; +} + +namespace net { +class FileStream; +class IOBufferWithSize; +} namespace chromeos { @@ -26,9 +37,10 @@ namespace chromeos { // |callback|. class PipeReader { public: - typedef base::Callback<void(void)>IOCompleteCallback; + typedef base::Callback<void(void)> IOCompleteCallback; - explicit PipeReader(PipeReader::IOCompleteCallback callback); + PipeReader(const scoped_refptr<base::TaskRunner>& task_runner, + const IOCompleteCallback& callback); virtual ~PipeReader(); // Closes writeable descriptor; normally used in parent process after fork. @@ -55,6 +67,7 @@ class PipeReader { int write_fd_; scoped_ptr<net::FileStream> data_stream_; scoped_refptr<net::IOBufferWithSize> io_buffer_; + scoped_refptr<base::TaskRunner> task_runner_; IOCompleteCallback callback_; // Note: This should remain the last member so it'll be destroyed and @@ -67,7 +80,8 @@ class PipeReader { // PipeReader subclass which accepts incoming data to a string. class PipeReaderForString : public PipeReader { public: - explicit PipeReaderForString(PipeReader::IOCompleteCallback callback); + PipeReaderForString(const scoped_refptr<base::TaskRunner>& task_runner, + const IOCompleteCallback& callback); virtual void AcceptData(const char *data, int length) OVERRIDE; diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc index 2785828436..486ce595f9 100644 --- a/chromeos/dbus/session_manager_client.cc +++ b/chromeos/dbus/session_manager_client.cc @@ -71,7 +71,8 @@ class SessionManagerClientImpl : public SessionManagerClient { weak_ptr_factory_.GetWeakPtr())); } - virtual void StartSession(const std::string& user_email) OVERRIDE { + virtual void StartSession(const std::string& user_email, + const StartSessionCallback& callback) OVERRIDE { dbus::MethodCall method_call(login_manager::kSessionManagerInterface, login_manager::kSessionManagerStartSession); dbus::MessageWriter writer(&method_call); @@ -81,7 +82,8 @@ class SessionManagerClientImpl : public SessionManagerClient { &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind(&SessionManagerClientImpl::OnStartSession, - weak_ptr_factory_.GetWeakPtr())); + weak_ptr_factory_.GetWeakPtr(), + callback)); } virtual void StopSession() OVERRIDE { @@ -332,10 +334,18 @@ class SessionManagerClientImpl : public SessionManagerClient { } // Called when kSessionManagerStartSession method is complete. - void OnStartSession(dbus::Response* response) { - LOG_IF(ERROR, !response) - << "Failed to call " - << login_manager::kSessionManagerStartSession; + void OnStartSession(const StartSessionCallback& callback, + dbus::Response* response) { + bool success = false; + if (!response) { + LOG(ERROR) << "Failed to call " + << login_manager::kSessionManagerStartSession; + } else { + dbus::MessageReader reader(response); + if (!reader.PopBool(&success)) + LOG(ERROR) << "Invalid response: " << response->ToString(); + } + callback.Run(success); } // Called when kSessionManagerStopSession method is complete. @@ -518,7 +528,10 @@ class SessionManagerClientStubImpl : public SessionManagerClient { } virtual void EmitLoginPromptVisible() OVERRIDE {} virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {} - virtual void StartSession(const std::string& user_email) OVERRIDE {} + virtual void StartSession(const std::string& user_email, + const StartSessionCallback& callback) OVERRIDE { + callback.Run(true); + } virtual void StopSession() OVERRIDE {} virtual void StartDeviceWipe() OVERRIDE {} virtual void RequestLockScreen() OVERRIDE { diff --git a/chromeos/dbus/session_manager_client.h b/chromeos/dbus/session_manager_client.h index 925ce5cfa1..9e3ca89d2a 100644 --- a/chromeos/dbus/session_manager_client.h +++ b/chromeos/dbus/session_manager_client.h @@ -70,8 +70,13 @@ class CHROMEOS_EXPORT SessionManagerClient : public DBusClient { // Restarts a job referenced by |pid| with the provided command line. virtual void RestartJob(int pid, const std::string& command_line) = 0; + // Used for StartSession. Takes a boolean indicating whether the + // operation was successful or not. + typedef base::Callback<void(bool success)> StartSessionCallback; + // Starts the session for the user. - virtual void StartSession(const std::string& user_email) = 0; + virtual void StartSession(const std::string& user_email, + const StartSessionCallback& callback) = 0; // Stops the current session. virtual void StopSession() = 0; diff --git a/chromeos/dbus/system_clock_client.cc b/chromeos/dbus/system_clock_client.cc index 7d5f4a4598..199a6acacc 100644 --- a/chromeos/dbus/system_clock_client.cc +++ b/chromeos/dbus/system_clock_client.cc @@ -5,6 +5,8 @@ #include "chromeos/dbus/system_clock_client.h" #include "base/bind.h" +#include "base/callback.h" +#include "base/observer_list.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" @@ -17,7 +19,10 @@ namespace chromeos { class SystemClockClientImpl : public SystemClockClient { public: SystemClockClientImpl() - : system_clock_proxy_(NULL), weak_ptr_factory_(this) {} + : can_set_time_(false), + can_set_time_initialized_(false), + system_clock_proxy_(NULL), + weak_ptr_factory_(this) {} virtual ~SystemClockClientImpl() { } @@ -34,12 +39,28 @@ class SystemClockClientImpl : public SystemClockClient { return observers_.HasObserver(observer); } + virtual void SetTime(int64 time_in_seconds) OVERRIDE { + // Always try to set the time, because |can_set_time_| may be stale. + dbus::MethodCall method_call(system_clock::kSystemClockInterface, + system_clock::kSystemClockSet); + dbus::MessageWriter writer(&method_call); + writer.AppendInt64(time_in_seconds); + system_clock_proxy_->CallMethod(&method_call, + dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + dbus::ObjectProxy::EmptyResponseCallback()); + } + + virtual bool CanSetTime() OVERRIDE { return can_set_time_; } + protected: virtual void Init(dbus::Bus* bus) OVERRIDE { system_clock_proxy_ = bus->GetObjectProxy( system_clock::kSystemClockServiceName, dbus::ObjectPath(system_clock::kSystemClockServicePath)); + // Check whether the system clock can be set. + GetCanSet(); + // Monitor the D-Bus signal for TimeUpdated changes. system_clock_proxy_->ConnectToSignal( system_clock::kSystemClockInterface, @@ -56,6 +77,9 @@ class SystemClockClientImpl : public SystemClockClient { VLOG(1) << "TimeUpdated signal received: " << signal->ToString(); dbus::MessageReader reader(signal); FOR_EACH_OBSERVER(Observer, observers_, SystemClockUpdated()); + + // Check if the system clock can be changed now. + GetCanSet(); } // Called when the TimeUpdated signal is initially connected. @@ -66,16 +90,62 @@ class SystemClockClientImpl : public SystemClockClient { << "Failed to connect to TimeUpdated signal."; } + // Callback for CanSetTime method. + void OnGetCanSet(dbus::Response* response) { + if (!response) { + LOG(WARNING) << "CanSetTime request failed."; + return; + } + + dbus::MessageReader reader(response); + bool can_set_time; + if (!reader.PopBool(&can_set_time)) { + LOG(ERROR) << "CanSetTime response invalid: " << response->ToString(); + return; + } + + // Nothing to do if the CanSetTime response hasn't changed. + if (can_set_time_initialized_ && can_set_time_ == can_set_time) + return; + + can_set_time_initialized_ = true; + can_set_time_ = can_set_time; + + FOR_EACH_OBSERVER( + Observer, observers_, SystemClockCanSetTimeChanged(can_set_time)); + } + + // Check whether the time can be set. + void GetCanSet() { + dbus::MethodCall method_call(system_clock::kSystemClockInterface, + system_clock::kSystemClockCanSet); + dbus::MessageWriter writer(&method_call); + system_clock_proxy_->CallMethod( + &method_call, + dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&SystemClockClientImpl::OnGetCanSet, + weak_ptr_factory_.GetWeakPtr())); + } + + // Whether the time can be set. Value is false until the first + // CanSetTime response is received. + bool can_set_time_; + bool can_set_time_initialized_; dbus::ObjectProxy* system_clock_proxy_; ObserverList<Observer> observers_; - // Note: This should remain the last member so it'll be destroyed and - // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<SystemClockClientImpl> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(SystemClockClientImpl); }; +void SystemClockClient::Observer::SystemClockUpdated() { +} + +void SystemClockClient::Observer::SystemClockCanSetTimeChanged( + bool can_set_time) { +} + SystemClockClient::SystemClockClient() { } diff --git a/chromeos/dbus/system_clock_client.h b/chromeos/dbus/system_clock_client.h index 849612db46..1757853950 100644 --- a/chromeos/dbus/system_clock_client.h +++ b/chromeos/dbus/system_clock_client.h @@ -5,7 +5,7 @@ #ifndef CHROMEOS_DBUS_SYSTEM_CLOCK_CLIENT_H_ #define CHROMEOS_DBUS_SYSTEM_CLOCK_CLIENT_H_ -#include "base/observer_list.h" +#include "base/callback.h" #include "chromeos/chromeos_export.h" #include "chromeos/dbus/dbus_client.h" @@ -18,19 +18,31 @@ class CHROMEOS_EXPORT SystemClockClient : public DBusClient { class Observer { public: // Called when the status is updated. - virtual void SystemClockUpdated() {} + virtual void SystemClockUpdated(); + + // Called when the system clock has become settable or unsettable, e.g., + // when the clock syncs with or goes out of sync with the network. + virtual void SystemClockCanSetTimeChanged(bool can_set_time); + protected: virtual ~Observer() {} }; virtual ~SystemClockClient(); - // Adds and removes the observer. + // Adds the given observer. virtual void AddObserver(Observer* observer) = 0; + // Removes the given observer if this object has the observer. virtual void RemoveObserver(Observer* observer) = 0; // Returns true if this object has the given observer. virtual bool HasObserver(Observer* observer) = 0; + // Sets the system clock. + virtual void SetTime(int64 time_in_seconds) = 0; + + // Checks if the system time can be set. + virtual bool CanSetTime() = 0; + // Creates the instance. static SystemClockClient* Create(); diff --git a/chromeos/network/favorite_state.cc b/chromeos/network/favorite_state.cc index 8ad9d3f962..efe4b383e7 100644 --- a/chromeos/network/favorite_state.cc +++ b/chromeos/network/favorite_state.cc @@ -46,13 +46,8 @@ bool FavoriteState::PropertyChanged(const std::string& key, ui_data_ = *new_ui_data; // Add ONCSource to |properties_| for debugging. - scoped_ptr<base::DictionaryValue> onc_dict(new base::DictionaryValue); - ui_data_.FillDictionary(onc_dict.get()); - std::string onc_source; - onc_dict->GetStringWithoutPathExpansion(NetworkUIData::kKeyONCSource, - &onc_source); properties_.SetStringWithoutPathExpansion(NetworkUIData::kKeyONCSource, - onc_source); + ui_data_.GetONCSourceAsString()); return true; } else if (key == shill::kGuidProperty) { return GetStringValue(key, value, &guid_); diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index d754bbb16e..8e906ea96d 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -127,11 +127,16 @@ void NetworkStateHandler::SetTechnologyEnabled( const NetworkTypePattern& type, bool enabled, const network_handler::ErrorCallback& error_callback) { - std::string technology = GetTechnologyForType(type); - NET_LOG_USER("SetTechnologyEnabled", - base::StringPrintf("%s:%d", technology.c_str(), enabled)); - shill_property_handler_->SetTechnologyEnabled( - technology, enabled, error_callback); + ScopedVector<std::string> technologies = GetTechnologiesForType(type); + for (ScopedVector<std::string>::iterator it = technologies.begin(); + it != technologies.end(); ++it) { + std::string* technology = *it; + DCHECK(technology); + NET_LOG_USER("SetTechnologyEnabled", + base::StringPrintf("%s:%d", technology->c_str(), enabled)); + shill_property_handler_->SetTechnologyEnabled( + *technology, enabled, error_callback); + } // Signal Device/Technology state changed. NotifyDeviceListChanged(); } @@ -835,4 +840,24 @@ std::string NetworkStateHandler::GetTechnologyForType( return std::string(); } +ScopedVector<std::string> NetworkStateHandler::GetTechnologiesForType( + const NetworkTypePattern& type) const { + ScopedVector<std::string> technologies; + if (type.MatchesType(shill::kTypeEthernet)) + technologies.push_back(new std::string(shill::kTypeEthernet)); + if (type.MatchesType(shill::kTypeWifi)) + technologies.push_back(new std::string(shill::kTypeWifi)); + if (type.MatchesType(shill::kTypeWimax)) + technologies.push_back(new std::string(shill::kTypeWimax)); + if (type.MatchesType(shill::kTypeCellular)) + technologies.push_back(new std::string(shill::kTypeCellular)); + if (type.MatchesType(shill::kTypeBluetooth)) + technologies.push_back(new std::string(shill::kTypeBluetooth)); + if (type.MatchesType(shill::kTypeVPN)) + technologies.push_back(new std::string(shill::kTypeVPN)); + + CHECK_GT(technologies.size(), 0ul); + return technologies.Pass(); +} + } // namespace chromeos diff --git a/chromeos/network/network_state_handler.h b/chromeos/network/network_state_handler.h index 2c4e6210f0..72d4029405 100644 --- a/chromeos/network/network_state_handler.h +++ b/chromeos/network/network_state_handler.h @@ -13,6 +13,7 @@ #include "base/callback_forward.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" #include "base/observer_list.h" #include "chromeos/chromeos_export.h" #include "chromeos/network/managed_state.h" @@ -327,9 +328,14 @@ class CHROMEOS_EXPORT NetworkStateHandler // Called whenever Device.Scanning state transitions to false. void ScanCompleted(const std::string& type); - // Returns the technology type for |type|. + // Returns one technology type for |type|. This technology will be the + // highest priority technology in the type pattern. std::string GetTechnologyForType(const NetworkTypePattern& type) const; + // Returns all the technology types for |type|. + ScopedVector<std::string> GetTechnologiesForType( + const NetworkTypePattern& type) const; + // Shill property handler instance, owned by this class. scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; diff --git a/chromeos/network/network_ui_data.cc b/chromeos/network/network_ui_data.cc index 65ac5f3e59..b5c09df0b6 100644 --- a/chromeos/network/network_ui_data.cc +++ b/chromeos/network/network_ui_data.cc @@ -15,6 +15,9 @@ const char NetworkUIData::kKeyONCSource[] = "onc_source"; const char NetworkUIData::kKeyCertificatePattern[] = "certificate_pattern"; const char NetworkUIData::kKeyCertificateType[] = "certificate_type"; const char NetworkUIData::kKeyUserSettings[] = "user_settings"; +const char NetworkUIData::kONCSourceUserImport[] = "user_import"; +const char NetworkUIData::kONCSourceDevicePolicy[] = "device_policy"; +const char NetworkUIData::kONCSourceUserPolicy[] = "user_policy"; namespace { @@ -25,9 +28,9 @@ struct StringEnumEntry { }; const StringEnumEntry< ::onc::ONCSource> kONCSourceTable[] = { - { "user_import", ::onc::ONC_SOURCE_USER_IMPORT }, - { "device_policy", ::onc::ONC_SOURCE_DEVICE_POLICY }, - { "user_policy", ::onc::ONC_SOURCE_USER_POLICY } + { NetworkUIData::kONCSourceUserImport, ::onc::ONC_SOURCE_USER_IMPORT }, + { NetworkUIData::kONCSourceDevicePolicy, ::onc::ONC_SOURCE_DEVICE_POLICY }, + { NetworkUIData::kONCSourceUserPolicy, ::onc::ONC_SOURCE_USER_POLICY } }; const StringEnumEntry<ClientCertType> kClientCertTable[] = { @@ -117,10 +120,14 @@ void NetworkUIData::set_user_settings(scoped_ptr<base::DictionaryValue> dict) { user_settings_ = dict.Pass(); } +std::string NetworkUIData::GetONCSourceAsString() const { + return EnumToString(kONCSourceTable, onc_source_); +} + void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const { dict->Clear(); - std::string source_string = EnumToString(kONCSourceTable, onc_source_); + std::string source_string = GetONCSourceAsString(); if (!source_string.empty()) dict->SetString(kKeyONCSource, source_string); diff --git a/chromeos/network/network_ui_data.h b/chromeos/network/network_ui_data.h index 92595ee1b2..42658c410b 100644 --- a/chromeos/network/network_ui_data.h +++ b/chromeos/network/network_ui_data.h @@ -72,6 +72,9 @@ class CHROMEOS_EXPORT NetworkUIData { policy_guid_ = guid; } + // Returns |onc_source_| as a string, one of kONCSource*. + std::string GetONCSourceAsString() const; + // Fills in |dict| with the currently configured values. This will write the // keys appropriate for Network::ui_data() as defined below (kKeyXXX). void FillDictionary(base::DictionaryValue* dict) const; @@ -96,6 +99,11 @@ class CHROMEOS_EXPORT NetworkUIData { // Key for storing the user settings. static const char kKeyUserSettings[]; + // Values for kKeyONCSource + static const char kONCSourceUserImport[]; + static const char kONCSourceDevicePolicy[]; + static const char kONCSourceUserPolicy[]; + private: CertificatePattern certificate_pattern_; ::onc::ONCSource onc_source_; diff --git a/chromeos/network/onc/onc_signature.cc b/chromeos/network/onc/onc_signature.cc index eb72ec8247..a5f8cc3d54 100644 --- a/chromeos/network/onc/onc_signature.cc +++ b/chromeos/network/onc/onc_signature.cc @@ -163,11 +163,11 @@ const OncFieldSignature ethernet_fields[] = { { ::onc::ethernet::kEAP, &kEAPSignature}, {NULL}}; -// Not supported, yet. +// Not supported for policy but for reading network state. const OncFieldSignature ipconfig_fields[] = { { ::onc::ipconfig::kGateway, &kStringSignature}, { ::onc::ipconfig::kIPAddress, &kStringSignature}, - { ::onc::network_config::kNameServers, &kStringSignature}, + { ::onc::ipconfig::kNameServers, &kStringListSignature}, { ::onc::ipconfig::kRoutingPrefix, &kIntegerSignature}, { ::onc::network_config::kSearchDomains, &kStringListSignature}, { ::onc::ipconfig::kType, &kStringSignature}, @@ -261,7 +261,7 @@ const OncFieldSignature network_configuration_fields[] = { { ::onc::kRecommended, &kRecommendedSignature}, { ::onc::network_config::kEthernet, &kEthernetSignature}, { ::onc::network_config::kGUID, &kStringSignature}, - // Not supported, yet. + // Not supported for policy but for reading network state. { ::onc::network_config::kIPConfigs, &kIPConfigListSignature}, { ::onc::network_config::kName, &kStringSignature}, // Not supported, yet. diff --git a/chromeos/network/onc/onc_translation_tables.cc b/chromeos/network/onc/onc_translation_tables.cc index 603c3b3ae2..c520cf9be5 100644 --- a/chromeos/network/onc/onc_translation_tables.cc +++ b/chromeos/network/onc/onc_translation_tables.cc @@ -18,8 +18,6 @@ namespace onc { // // Proxy settings are converted to Shill by function // ConvertOncProxySettingsToProxyConfig(...). -// -// Translation of IPConfig objects is not supported, yet. namespace { @@ -175,6 +173,13 @@ const FieldTranslationEntry network_fields[] = { // { ::onc::network_config::kConnectionState, shill::kStateProperty }, {NULL}}; +const FieldTranslationEntry ipconfig_fields[] = { + { ::onc::ipconfig::kIPAddress, shill::kAddressProperty}, + { ::onc::ipconfig::kGateway, shill::kGatewayProperty}, + { ::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty}, + { ::onc::ipconfig::kNameServers, shill::kNameServersProperty}, + {NULL}}; + struct OncValueTranslationEntry { const OncValueSignature* onc_signature; const FieldTranslationEntry* field_translation_table; @@ -196,6 +201,7 @@ const OncValueTranslationEntry onc_value_translation_table[] = { { &kCellularWithStateSignature, cellular_fields }, { &kNetworkWithStateSignature, network_fields }, { &kNetworkConfigurationSignature, network_fields }, + { &kIPConfigSignature, ipconfig_fields }, { NULL } }; diff --git a/chromeos/network/onc/onc_translator_shill_to_onc.cc b/chromeos/network/onc/onc_translator_shill_to_onc.cc index 11f59f45e8..7716fbf295 100644 --- a/chromeos/network/onc/onc_translator_shill_to_onc.cc +++ b/chromeos/network/onc/onc_translator_shill_to_onc.cc @@ -66,6 +66,7 @@ class ShillToONCTranslator { void TranslateWiFiWithState(); void TranslateCellularWithState(); void TranslateNetworkWithState(); + void TranslateIPConfig(); // Creates an ONC object from |dictionary| according to the signature // associated to |onc_field_name| and adds it to |onc_object_| at @@ -131,6 +132,8 @@ ShillToONCTranslator::CreateTranslatedONCObject() { TranslateWiFiWithState(); } else if (onc_signature_ == &kCellularWithStateSignature) { TranslateCellularWithState(); + } else if (onc_signature_ == &kIPConfigSignature) { + TranslateIPConfig(); } else { CopyPropertiesAccordingToSignature(); } @@ -254,10 +257,10 @@ void ShillToONCTranslator::TranslateCellularWithState() { shill::kCellularApnProperty, &dictionary)) { TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); } - const base::ListValue* list = NULL; + const base::ListValue* shill_apns = NULL; if (shill_dictionary_->GetListWithoutPathExpansion( - shill::kCellularApnListProperty, &list)) { - TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *list); + shill::kCellularApnListProperty, &shill_apns)) { + TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns); } } @@ -299,6 +302,33 @@ void ShillToONCTranslator::TranslateNetworkWithState() { onc_object_->SetStringWithoutPathExpansion( ::onc::network_config::kConnectionState, onc_state); } + + // Shill's Service has an IPConfig property (note the singular, and not a + // IPConfigs property). However, we require the caller of the translation to + // patch the Shill dictionary before passing it to the translator. + const base::ListValue* shill_ipconfigs = NULL; + if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, + &shill_ipconfigs)) { + TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, + *shill_ipconfigs); + } +} + +void ShillToONCTranslator::TranslateIPConfig() { + CopyPropertiesAccordingToSignature(); + std::string shill_ip_method; + shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, + &shill_ip_method); + if (shill_ip_method != shill::kTypeIPv4 && + shill_ip_method != shill::kTypeIPv6) { + LOG(ERROR) << "Unhandled IPConfig Method value " << shill_ip_method; + return; + } + + std::string type = ::onc::ipconfig::kIPv4; + if (shill_ip_method == shill::kTypeIPv6) + type = ::onc::ipconfig::kIPv6; + onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type); } void ShillToONCTranslator::TranslateAndAddNestedObject( @@ -345,14 +375,13 @@ void ShillToONCTranslator::TranslateAndAddListOfObjects( *field_signature->value_signature->onc_array_entry_signature); scoped_ptr<base::DictionaryValue> nested_object = nested_translator.CreateTranslatedONCObject(); + // If the nested object couldn't be parsed, simply omit it. if (nested_object->empty()) - // The nested object couldn't be parsed, so simply omit it. continue; result->Append(nested_object.release()); } + // If there are no entries in the list, there is no need to expose this field. if (result->empty()) - // There are no entries in the list, so there is no need to expose this - // field. return; onc_object_->SetWithoutPathExpansion(onc_field_name, result.release()); } diff --git a/chromeos/network/onc/onc_translator_unittest.cc b/chromeos/network/onc/onc_translator_unittest.cc index c81aaa647e..29a77b99d3 100644 --- a/chromeos/network/onc/onc_translator_unittest.cc +++ b/chromeos/network/onc/onc_translator_unittest.cc @@ -92,6 +92,8 @@ INSTANTIATE_TEST_CASE_P( "translation_of_shill_ethernet.onc"), std::make_pair("shill_ethernet_with_eap.json", "translation_of_shill_ethernet_with_eap.onc"), + std::make_pair("shill_ethernet_with_ipconfig.json", + "translation_of_shill_ethernet_with_ipconfig.onc"), std::make_pair("shill_wifi_clientcert.json", "translation_of_shill_wifi_clientcert.onc"), std::make_pair("shill_wifi_wpa1.json", diff --git a/chromeos/network/onc/onc_validator_unittest.cc b/chromeos/network/onc/onc_validator_unittest.cc index 4108d2f640..51f4109f0c 100644 --- a/chromeos/network/onc/onc_validator_unittest.cc +++ b/chromeos/network/onc/onc_validator_unittest.cc @@ -179,6 +179,9 @@ INSTANTIATE_TEST_CASE_P( OncParams("ethernet_with_eap.onc", &kNetworkConfigurationSignature, true), + OncParams("translation_of_shill_ethernet_with_ipconfig.onc", + &kNetworkConfigurationSignature, + true), OncParams("translation_of_shill_wifi_with_state.onc", &kNetworkWithStateSignature, false), diff --git a/chromeos/test/data/network/shill_ethernet_with_ipconfig.json b/chromeos/test/data/network/shill_ethernet_with_ipconfig.json new file mode 100644 index 0000000000..3eae24ef2e --- /dev/null +++ b/chromeos/test/data/network/shill_ethernet_with_ipconfig.json @@ -0,0 +1,23 @@ +{ + "GUID":"guid", + "IPConfigs":[ + { + "Address":"123.123.123.123", + "Gateway":"1.1.1.1", + "Method":"ipv4", + "NameServers":[ + "1.1.1.2", + "1.1.1.3" + ], + "Prefixlen":24 + }, + { + "Address":"2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "Gateway":"2001:db8:85a3::7a2e:370:7331", + "Method":"ipv6", + "NameServers":[], + "Prefixlen":12 + } + ], + "Type":"ethernet" +} diff --git a/chromeos/test/data/network/translation_of_shill_ethernet_with_ipconfig.onc b/chromeos/test/data/network/translation_of_shill_ethernet_with_ipconfig.onc new file mode 100644 index 0000000000..d4a472f581 --- /dev/null +++ b/chromeos/test/data/network/translation_of_shill_ethernet_with_ipconfig.onc @@ -0,0 +1,27 @@ +{ + "Ethernet":{ + "Authentication":"None" + }, + "GUID":"guid", + "IPConfigs":[ + { + "Gateway":"1.1.1.1", + "IPAddress":"123.123.123.123", + "NameServers":[ + "1.1.1.2", + "1.1.1.3" + ], + "RoutingPrefix":24, + "Type":"IPv4" + }, + { + "Gateway":"2001:db8:85a3::7a2e:370:7331", + "IPAddress":"2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "NameServers":[], + "RoutingPrefix":12, + "Type":"IPv6" + } + ], + "Name":"", + "Type":"Ethernet" +} |