Chromium Code Reviews| 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..983bdf09bd1d895cfa5e00bc25494309cc133699 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[] = {'|', 0}; |
|
James Cook
2017/05/15 16:37:23
const char kDelimiter[] = "|"; doesn't work here?
msw
2017/05/15 19:21:31
Done.
|
| + |
| +} // 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 + std::string(kDelimiter) + launch_id; |
|
James Cook
2017/05/15 16:37:23
You might be able to skip the std::string(kDelimit
msw
2017/05/15 19:21:31
Done.
|
| +} |
| + |
| +// static |
| +ShelfID ShelfID::Deserialize(const std::string* string) { |
| + if (!string) |
|
James Cook
2017/05/15 16:37:23
Could this be a DCHECK?
msw
2017/05/15 19:21:31
I'd rather not, every kShelfIDKey property read wo
|
| + 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 |