OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ | 5 #ifndef EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ |
6 #define EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ | 6 #define EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ |
7 | 7 |
8 #include <memory> | |
9 #include <string> | 8 #include <string> |
10 | 9 |
11 #include "base/callback.h" | 10 #include "base/callback_forward.h" |
12 #include "base/macros.h" | |
13 #include "content/public/browser/utility_process_host_client.h" | |
14 #include "extensions/browser/updater/manifest_fetch_data.h" | |
15 #include "extensions/common/update_manifest.h" | 11 #include "extensions/common/update_manifest.h" |
16 | 12 |
17 namespace extensions { | 13 namespace extensions { |
18 | 14 |
19 // Utility class to handle doing xml parsing in a sandboxed utility process. | 15 // Parses an update manifest |xml| safely in a utility process and calls |
20 class SafeManifestParser : public content::UtilityProcessHostClient { | 16 // |callback| with the results, which will be null on failure. Runs on |
21 public: | 17 // the UI thread. |
22 // Callback that is invoked when the manifest results are ready. | 18 void ParseUpdateManifest( |
23 typedef base::Callback<void(const UpdateManifest::Results*)> ResultsCallback; | 19 const std::string& xml, |
24 | 20 const base::Callback<void(const UpdateManifest::Results*)>& callback); |
25 SafeManifestParser(const std::string& xml, | |
26 const ResultsCallback& results_callback); | |
27 | |
28 // Posts a task over to the IO loop to start the parsing of xml_ in a | |
29 // utility process. | |
30 void Start(); | |
31 | |
32 private: | |
33 ~SafeManifestParser() override; | |
34 | |
35 // Creates the sandboxed utility process and tells it to start parsing. | |
36 void ParseInSandbox(); | |
37 | |
38 // content::UtilityProcessHostClient implementation. | |
39 bool OnMessageReceived(const IPC::Message& message) override; | |
40 | |
41 void OnParseUpdateManifestSucceeded(const UpdateManifest::Results& results); | |
42 void OnParseUpdateManifestFailed(const std::string& error_message); | |
43 | |
44 const std::string xml_; | |
45 | |
46 // Should be accessed only on UI thread. | |
47 ResultsCallback results_callback_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(SafeManifestParser); | |
50 }; | |
51 | 21 |
52 } // namespace extensions | 22 } // namespace extensions |
53 | 23 |
54 #endif // EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ | 24 #endif // EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ |
OLD | NEW |