This source file includes following definitions.
- Run
#include "chrome/utility/web_resource_unpacker.h"
#include "base/json/json_reader.h"
#include "base/values.h"
const char* WebResourceUnpacker::kInvalidDataTypeError =
"Data from web resource server is missing or not valid JSON.";
const char* WebResourceUnpacker::kUnexpectedJSONFormatError =
"Data from web resource server does not have expected format.";
WebResourceUnpacker::WebResourceUnpacker(const std::string &resource_data)
: resource_data_(resource_data) {
}
WebResourceUnpacker::~WebResourceUnpacker() {
}
bool WebResourceUnpacker::Run() {
scoped_ptr<base::Value> value;
if (!resource_data_.empty()) {
value.reset(base::JSONReader::Read(resource_data_));
if (!value.get()) {
error_message_ = kInvalidDataTypeError;
return false;
}
if (!value->IsType(base::Value::TYPE_DICTIONARY)) {
error_message_ = kUnexpectedJSONFormatError;
return false;
}
parsed_json_.reset(static_cast<base::DictionaryValue*>(value.release()));
return true;
}
error_message_ = kInvalidDataTypeError;
return false;
}