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

Unified Diff: ash/public/cpp/shelf_types.cc

Issue 2878133002: mash: Serialize ShelfIDs for property conversion and transport. (Closed)
Patch Set: Address comments. Created 3 years, 7 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
« no previous file with comments | « ash/public/cpp/shelf_types.h ('k') | ash/public/cpp/window_properties.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ash/public/cpp/shelf_types.h ('k') | ash/public/cpp/window_properties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698