• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_
6 #define EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_
7 
8 #include <string>
9 
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.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"
16 
17 namespace extensions {
18 
19 // Utility class to handle doing xml parsing in a sandboxed utility process.
20 class SafeManifestParser : public content::UtilityProcessHostClient {
21  public:
22   // Callback that is invoked when the manifest results are ready.
23   typedef base::Callback<void(const ManifestFetchData&,
24                               const UpdateManifest::Results*)> UpdateCallback;
25 
26   // Takes ownership of |fetch_data|.
27   SafeManifestParser(const std::string& xml,
28                      ManifestFetchData* fetch_data,
29                      const UpdateCallback& update_callback);
30 
31   // Posts a task over to the IO loop to start the parsing of xml_ in a
32   // utility process.
33   void Start();
34 
35  private:
36   virtual ~SafeManifestParser();
37 
38   // Creates the sandboxed utility process and tells it to start parsing.
39   void ParseInSandbox();
40 
41   // content::UtilityProcessHostClient implementation.
42   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
43 
44   void OnParseUpdateManifestSucceeded(const UpdateManifest::Results& results);
45   void OnParseUpdateManifestFailed(const std::string& error_message);
46 
47   const std::string xml_;
48 
49   // Should be accessed only on UI thread.
50   scoped_ptr<ManifestFetchData> fetch_data_;
51   UpdateCallback update_callback_;
52 
53   DISALLOW_COPY_AND_ASSIGN(SafeManifestParser);
54 };
55 
56 }  // namespace extensions
57 
58 #endif  // EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_
59