OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/public/cpp/shelf_types.h" | 5 #include "ash/public/cpp/shelf_types.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_split.h" | |
8 | 9 |
9 namespace ash { | 10 namespace ash { |
10 | 11 |
12 namespace { | |
13 | |
14 // A delimiter used to serialize the ShelfID string pair as a single string. | |
15 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.
| |
16 | |
17 } // namespace | |
18 | |
11 bool IsValidShelfItemType(int64_t type) { | 19 bool IsValidShelfItemType(int64_t type) { |
12 return type == TYPE_APP_PANEL || type == TYPE_PINNED_APP || | 20 return type == TYPE_APP_PANEL || type == TYPE_PINNED_APP || |
13 type == TYPE_APP_LIST || type == TYPE_BROWSER_SHORTCUT || | 21 type == TYPE_APP_LIST || type == TYPE_BROWSER_SHORTCUT || |
14 type == TYPE_APP || type == TYPE_DIALOG || type == TYPE_UNDEFINED; | 22 type == TYPE_APP || type == TYPE_DIALOG || type == TYPE_UNDEFINED; |
15 } | 23 } |
16 | 24 |
17 ShelfID::ShelfID(const std::string& app_id, const std::string& launch_id) | 25 ShelfID::ShelfID(const std::string& app_id, const std::string& launch_id) |
18 : app_id(app_id), launch_id(launch_id) { | 26 : app_id(app_id), launch_id(launch_id) { |
19 DCHECK(launch_id.empty() || !app_id.empty()) << "launch ids require app ids."; | 27 DCHECK(launch_id.empty() || !app_id.empty()) << "launch ids require app ids."; |
20 } | 28 } |
(...skipping 16 matching lines...) Expand all Loading... | |
37 | 45 |
38 bool ShelfID::operator<(const ShelfID& other) const { | 46 bool ShelfID::operator<(const ShelfID& other) const { |
39 return app_id < other.app_id || | 47 return app_id < other.app_id || |
40 (app_id == other.app_id && launch_id < other.launch_id); | 48 (app_id == other.app_id && launch_id < other.launch_id); |
41 } | 49 } |
42 | 50 |
43 bool ShelfID::IsNull() const { | 51 bool ShelfID::IsNull() const { |
44 return app_id.empty() && launch_id.empty(); | 52 return app_id.empty() && launch_id.empty(); |
45 } | 53 } |
46 | 54 |
55 std::string ShelfID::Serialize() const { | |
56 DCHECK_EQ(std::string::npos, app_id.find(kDelimiter)) << "Invalid ShelfID"; | |
57 DCHECK_EQ(std::string::npos, launch_id.find(kDelimiter)) << "Invalid ShelfID"; | |
58 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.
| |
59 } | |
60 | |
61 // static | |
62 ShelfID ShelfID::Deserialize(const std::string* string) { | |
63 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
| |
64 return ShelfID(); | |
65 std::vector<std::string> components = base::SplitString( | |
66 *string, kDelimiter, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
67 DCHECK_EQ(2u, components.size()) << "ShelfID serialized incorrectly."; | |
68 return ShelfID(components[0], components[1]); | |
69 } | |
70 | |
47 } // namespace ash | 71 } // namespace ash |
OLD | NEW |