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

Unified Diff: third_party/mojo/src/mojo/edk/system/unique_identifier.cc

Issue 1157843002: Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
Index: third_party/mojo/src/mojo/edk/system/unique_identifier.cc
diff --git a/third_party/mojo/src/mojo/edk/system/unique_identifier.cc b/third_party/mojo/src/mojo/edk/system/unique_identifier.cc
index 11e482b64b52728ea0aaf3641bef92f3d08f2398..6e036c81f0c3762466510027e9b7952465292429 100644
--- a/third_party/mojo/src/mojo/edk/system/unique_identifier.cc
+++ b/third_party/mojo/src/mojo/edk/system/unique_identifier.cc
@@ -4,7 +4,9 @@
#include "mojo/edk/system/unique_identifier.h"
-#include <ostream>
+#include <stdint.h>
+
+#include <vector>
#include "base/strings/string_number_conversions.h"
#include "mojo/edk/embedder/platform_support.h"
@@ -12,12 +14,6 @@
namespace mojo {
namespace system {
-std::ostream& operator<<(std::ostream& out,
- const UniqueIdentifier& unique_identifier) {
- return out << base::HexEncode(unique_identifier.data_,
- sizeof(unique_identifier.data_));
-}
-
// static
UniqueIdentifier UniqueIdentifier::Generate(
embedder::PlatformSupport* platform_support) {
@@ -26,5 +22,24 @@ UniqueIdentifier UniqueIdentifier::Generate(
return rv;
}
+// static
+UniqueIdentifier UniqueIdentifier::FromString(const std::string& s,
+ bool* success) {
+ UniqueIdentifier rv;
+ std::vector<uint8_t> bytes;
+ if (base::HexStringToBytes(s, &bytes) && bytes.size() == sizeof(rv.data_)) {
+ memcpy(rv.data_, &bytes[0], sizeof(rv.data_));
+ *success = true;
+ } else {
+ *success = false;
+ }
+ return rv;
+}
+
+std::string UniqueIdentifier::ToString() const {
+ // TODO(vtl): Maybe we should base-64 encode instead?
+ return base::HexEncode(data_, sizeof(data_));
+}
+
} // namespace system
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698