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

Unified Diff: components/safe_json/safe_json_parser.h

Issue 1214903010: Make JSONParser a pure interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: review Created 5 years, 6 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: components/safe_json/safe_json_parser.h
diff --git a/components/safe_json/safe_json_parser.h b/components/safe_json/safe_json_parser.h
index 8fb703b3e9a619f630906418841a8c87bd6d395f..0d426289296862fdac7c118b9416257f41fd7f74 100644
--- a/components/safe_json/safe_json_parser.h
+++ b/components/safe_json/safe_json_parser.h
@@ -2,67 +2,47 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_H_
-#define COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_H_
+#ifndef COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_
Robert Sesek 2015/07/02 17:28:19 The include guards are swapped for this file and t
Bernhard Bauer 2015/07/02 22:38:23 D'oh! Fixed.
+#define COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
-#include "content/public/browser/utility_process_host_client.h"
namespace base {
-class ListValue;
-class SingleThreadTaskRunner;
class Value;
}
-namespace IPC {
-class Message;
-}
-
namespace safe_json {
-// SafeJsonParser parses a given JSON safely via a utility process. The object
-// is ref-counted and kept alive after Start() is called until one of the two
-// callbacks is called.
-class SafeJsonParser : public content::UtilityProcessHostClient {
+// SafeJsonParser parses a given JSON safely via a platform-dependent mechanism
+// (like parsing it in a utility process or in a memory-safe environment).
+// The object is kept alive after Start() is called until one of the two
+// callbacks is called, after which it will delete itself.
+class SafeJsonParser {
public:
- typedef base::Callback<void(scoped_ptr<base::Value>)> SuccessCallback;
- typedef base::Callback<void(const std::string&)> ErrorCallback;
-
- SafeJsonParser(const std::string& unsafe_json,
- const SuccessCallback& success_callback,
- const ErrorCallback& error_callback);
+ using SuccessCallback = base::Callback<void(scoped_ptr<base::Value>)>;
+ using ErrorCallback = base::Callback<void(const std::string&)>;
- void Start();
-
- private:
- ~SafeJsonParser() override;
+ using Factory = SafeJsonParser* (*)(const std::string& unsafe_json,
+ const SuccessCallback& success_callback,
+ const ErrorCallback& error_callback);
- void StartWorkOnIOThread();
+ static void Parse(const std::string& unsafe_json,
Robert Sesek 2015/07/02 17:28:19 Since this is the only public method, it should ha
Bernhard Bauer 2015/07/02 22:38:24 Done.
+ const SuccessCallback& success_callback,
+ const ErrorCallback& error_callback);
- void OnJSONParseSucceeded(const base::ListValue& wrapper);
- void OnJSONParseFailed(const std::string& error_message);
+ static void SetFactoryForTesting(Factory factory);
- void ReportResults();
- void ReportResultsOnOriginThread();
+ protected:
+ virtual ~SafeJsonParser() {}
- // Implementing pieces of the UtilityProcessHostClient interface.
- bool OnMessageReceived(const IPC::Message& message) override;
-
- const std::string unsafe_json_;
- SuccessCallback success_callback_;
- ErrorCallback error_callback_;
- scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
-
- scoped_ptr<base::Value> parsed_json_;
- std::string error_;
-
- DISALLOW_COPY_AND_ASSIGN(SafeJsonParser);
+ private:
+ virtual void Start() = 0;
};
} // namespace safe_json
-#endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_H_
+#endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698