Home | History | Annotate | Download | only in utility
      1 // Copyright (c) 2011 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 // This class is called by the WebResourceService in a sandboxed process
      6 // to unpack data retrieved from a web resource feed.  Right now, it
      7 // takes a string of data in JSON format, parses it, and hands it back
      8 // to the WebResourceService as a list of items.  In the future
      9 // it will be set up to unpack and verify image data in addition to
     10 // just parsing a JSON feed.
     11 
     12 #ifndef CHROME_UTILITY_WEB_RESOURCE_UNPACKER_H_
     13 #define CHROME_UTILITY_WEB_RESOURCE_UNPACKER_H_
     14 
     15 #include <string>
     16 
     17 #include "base/basictypes.h"
     18 #include "base/memory/scoped_ptr.h"
     19 
     20 namespace base {
     21 class DictionaryValue;
     22 }
     23 
     24 class WebResourceUnpacker {
     25  public:
     26   static const char* kInvalidDataTypeError;
     27   static const char* kUnexpectedJSONFormatError;
     28 
     29   explicit WebResourceUnpacker(const std::string &resource_data);
     30   ~WebResourceUnpacker();
     31 
     32   // This does the actual parsing.  In case of an error, error_message_
     33   // is set to an appropriate value.
     34   bool Run();
     35 
     36   // Returns the last error message set by Run().
     37   const std::string& error_message() { return error_message_; }
     38 
     39   // Gets data which has been parsed by Run().
     40   base::DictionaryValue* parsed_json() {
     41     return parsed_json_.get();
     42   }
     43 
     44  private:
     45   // Holds the string which is to be parsed.
     46   std::string resource_data_;
     47 
     48   // Holds the result of JSON parsing of resource_data_.
     49   scoped_ptr<base::DictionaryValue> parsed_json_;
     50 
     51   // Holds the last error message produced by Run().
     52   std::string error_message_;
     53 
     54   DISALLOW_COPY_AND_ASSIGN(WebResourceUnpacker);
     55 };
     56 
     57 #endif  // CHROME_UTILITY_WEB_RESOURCE_UNPACKER_H_
     58