Index: ash/public/cpp/shelf_types.cc |
diff --git a/ash/public/cpp/shelf_types.cc b/ash/public/cpp/shelf_types.cc |
index 53d683239caf45fcfd8a4f7b5dce63ff02048523..044872357f4ccc78b74d54757e827d471288736f 100644 |
--- a/ash/public/cpp/shelf_types.cc |
+++ b/ash/public/cpp/shelf_types.cc |
@@ -5,9 +5,17 @@ |
#include "ash/public/cpp/shelf_types.h" |
#include "base/logging.h" |
+#include "base/strings/string_split.h" |
namespace ash { |
+namespace { |
+ |
+// A delimiter used to serialize the ShelfID string pair as a single string. |
+constexpr char kDelimiter[] = "|"; |
+ |
+} // namespace |
+ |
bool IsValidShelfItemType(int64_t type) { |
return type == TYPE_APP_PANEL || type == TYPE_PINNED_APP || |
type == TYPE_APP_LIST || type == TYPE_BROWSER_SHORTCUT || |
@@ -44,4 +52,20 @@ bool ShelfID::IsNull() const { |
return app_id.empty() && launch_id.empty(); |
} |
+std::string ShelfID::Serialize() const { |
+ DCHECK_EQ(std::string::npos, app_id.find(kDelimiter)) << "Invalid ShelfID"; |
+ DCHECK_EQ(std::string::npos, launch_id.find(kDelimiter)) << "Invalid ShelfID"; |
+ return app_id + kDelimiter + launch_id; |
+} |
+ |
+// static |
+ShelfID ShelfID::Deserialize(const std::string* string) { |
+ if (!string) |
+ return ShelfID(); |
+ std::vector<std::string> components = base::SplitString( |
+ *string, kDelimiter, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
+ DCHECK_EQ(2u, components.size()) << "ShelfID serialized incorrectly."; |
+ return ShelfID(components[0], components[1]); |
+} |
+ |
} // namespace ash |