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

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: nullptr 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
« no previous file with comments | « components/safe_json/BUILD.gn ('k') | components/safe_json/safe_json_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..35919c9b0a251b0693f6b9c213f4589e4f626296 100644
--- a/components/safe_json/safe_json_parser.h
+++ b/components/safe_json/safe_json_parser.h
@@ -10,57 +10,36 @@
#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);
-
- void Start();
-
- private:
- ~SafeJsonParser() override;
-
- void StartWorkOnIOThread();
-
- void OnJSONParseSucceeded(const base::ListValue& wrapper);
- void OnJSONParseFailed(const std::string& error_message);
+ using SuccessCallback = base::Callback<void(scoped_ptr<base::Value>)>;
+ using ErrorCallback = base::Callback<void(const std::string&)>;
- void ReportResults();
- void ReportResultsOnOriginThread();
+ using Factory = SafeJsonParser* (*)(const std::string& unsafe_json,
+ const SuccessCallback& success_callback,
+ const ErrorCallback& error_callback);
- // Implementing pieces of the UtilityProcessHostClient interface.
- bool OnMessageReceived(const IPC::Message& message) override;
+ static SafeJsonParser* Create(const std::string& unsafe_json,
Robert Sesek 2015/07/01 22:19:04 At minium, ditto the comment about ownership here.
Bernhard Bauer 2015/07/02 14:16:01 Done. I also moved the Impl class to a separate f
+ const SuccessCallback& success_callback,
Robert Sesek 2015/07/01 22:19:04 nit: alignment
Bernhard Bauer 2015/07/02 14:16:01 Done.
+ const ErrorCallback& error_callback);
- const std::string unsafe_json_;
- SuccessCallback success_callback_;
- ErrorCallback error_callback_;
- scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
+ virtual void Start() = 0;
- scoped_ptr<base::Value> parsed_json_;
- std::string error_;
+ static void SetFactoryForTesting(Factory factory);
- DISALLOW_COPY_AND_ASSIGN(SafeJsonParser);
+ protected:
+ virtual ~SafeJsonParser() {}
};
} // namespace safe_json
« no previous file with comments | « components/safe_json/BUILD.gn ('k') | components/safe_json/safe_json_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698