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

Unified Diff: base/values.h

Issue 2516363005: Inline StringValue into base::Value (Closed)
Patch Set: GetString by ref and TestStringValue Fix Created 4 years 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 | « base/json/json_parser.cc ('k') | base/values.cc » ('j') | base/values.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.h
diff --git a/base/values.h b/base/values.h
index a695536bfd9a6f8cbb8fd8b3a5e778331e455177..b335e5ca0885d613548223e0a49008bb825405c3 100644
--- a/base/values.h
+++ b/base/values.h
@@ -30,6 +30,7 @@
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/manual_constructor.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
@@ -92,6 +93,9 @@ class BASE_EXPORT Value {
bool GetBool() const;
int GetInt() const;
double GetDouble() const; // Implicitly converts from int if necessary.
+ // Returns |string_value_| as a non-const or const reference.
+ std::string& GetString();
jdoerrie 2016/12/16 09:54:37 For now I added the non-const ref version for simp
vabr (Chromium) 2016/12/16 17:00:56 Just for context: part of the discussion was also
+ const std::string& GetString() const;
// These methods allow the convenient retrieval of the contents of the Value.
// If the current object can be converted into the given type, the value is
@@ -141,15 +145,27 @@ class BASE_EXPORT Value {
explicit Value(int in_int);
explicit Value(double in_double);
- private:
- void InternalCopyFrom(const Value& that);
+ // TODO(crbug.com/646113) move to public when StringValue is gone.
+ explicit Value(StringPiece in_string);
jdoerrie 2016/12/16 09:54:37 Given that we need an explicit Value::Value(const
vabr (Chromium) 2016/12/16 17:00:56 Definitely in favour of replacing by string-based
+ explicit Value(const string16& in_string);
+
+ // Required despite StringPiece because otherwise the compiler will
+ // choose the Value(bool) constructor.
+ explicit Value(const char* in_string);
vabr (Chromium) 2016/12/16 17:00:55 As a TODO to be done in a separate CL, could we tr
jdoerrie 2016/12/19 11:54:09 If it is your goal to stop being able to do |Value
vabr (Chromium) 2016/12/19 13:00:56 Good to know about the error. However, because it
+ // TODO(crbug.com/646113): Make this private once JSONStringValue is removed.
Type type_;
+ private:
+ void InternalCopyFrom(const Value& that);
+ void InternalMoveFrom(Value&& that);
+ void InternalCleanup();
+
union {
bool bool_value_;
int int_value_;
double double_value_;
+ ManualConstructor<std::string> string_value_;
};
};
@@ -163,6 +179,7 @@ class BASE_EXPORT FundamentalValue : public Value {
~FundamentalValue() override;
};
+// TODO(crbug.com/64113) remove when callers are updated to use raw Value.
class BASE_EXPORT StringValue : public Value {
vabr (Chromium) 2016/12/16 17:00:56 Could we actually make this a typedef instead? (Fo
jdoerrie 2016/12/19 11:54:09 This is true, but it probably also would require m
vabr (Chromium) 2016/12/19 13:00:56 I'm not sure the comment about safety applies to a
public:
// Initializes a StringValue with a UTF-8 narrow character string.
@@ -170,22 +187,6 @@ class BASE_EXPORT StringValue : public Value {
// Initializes a StringValue with a string16.
explicit StringValue(const string16& in_value);
-
- ~StringValue() override;
-
- // Returns |value_| as a pointer or reference.
- std::string* GetString();
- const std::string& GetString() const;
-
- // Overridden from Value:
- bool GetAsString(std::string* out_value) const override;
- bool GetAsString(string16* out_value) const override;
- bool GetAsString(const StringValue** out_value) const override;
- StringValue* DeepCopy() const override;
- bool Equals(const Value* other) const override;
-
- private:
- std::string value_;
};
class BASE_EXPORT BinaryValue: public Value {
« no previous file with comments | « base/json/json_parser.cc ('k') | base/values.cc » ('j') | base/values.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698