Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: chromeos/network/managed_state.h

Issue 11192024: Add chromeos::NetworkStateManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Separate out NetworkStateHandlerImpl, address feedback Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/network/managed_state.h
diff --git a/chromeos/network/managed_state.h b/chromeos/network/managed_state.h
new file mode 100644
index 0000000000000000000000000000000000000000..cfefb993bb4a060e8290a1b85fe4f47d64198798
--- /dev/null
+++ b/chromeos/network/managed_state.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium 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 CHROMEOS_NETWORK_MANAGED_STATE_H_
+#define CHROMEOS_NETWORK_MANAGED_STATE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "chromeos/chromeos_export.h"
+
+namespace base {
+class Value;
+}
+
+namespace chromeos {
+
+class DeviceState;
+class NetworkState;
+
+// Base class for states managed by NetworkStateManger which are associated
+// with a Shill path (e.g. service path or device path).
+class ManagedState {
+ public:
+ enum ManagedType {
+ MANAGED_TYPE_NETWORK,
+ MANAGED_TYPE_DEVICE
+ };
+
+ virtual ~ManagedState();
+
+ // This will construct and return a new instance of the approprate class
+ // based on |type|.
+ static ManagedState* Create(ManagedType type, const std::string& path);
+
+ // Returns the specific class pointer if this is the correct type, or
+ // NULL if it is not.
+ NetworkState* AsNetworkState();
+ DeviceState* AsDeviceState();
+
+ // Called by NetworkStateHandler when a property changes. Returns true if
+ // the property was recognized and parsed successfully.
+ virtual bool PropertyChanged(const std::string& key,
+ const base::Value& value) = 0;
+
+ const ManagedType managed_type() const { return managed_type_; }
+ const std::string& path() const { return path_; }
+ const std::string& name() const { return name_; }
+ const std::string& type() const { return type_; }
+
+ protected:
+ ManagedState(ManagedType type, const std::string& path);
+
+ // Parses common property keys (name, type).
+ bool ManagedStatePropertyChanged(const std::string& key,
+ const base::Value& value);
+
+ // Helper methods that log warnings if parsing failed.
+ bool GetBooleanValue(const std::string& key,
+ const base::Value& value,
+ bool* out_value);
+ bool GetIntegerValue(const std::string& key,
+ const base::Value& value,
+ int* out_value);
+ bool GetStringValue(const std::string& key,
+ const base::Value& value,
+ std::string* out_value);
+
+ private:
+ ManagedType managed_type_;
+ std::string path_;
+ std::string name_;
+ std::string type_;
+
+ DISALLOW_COPY_AND_ASSIGN(ManagedState);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_NETWORK_MANAGED_STATE_H_

Powered by Google App Engine
This is Rietveld 408576698