1 // Copyright (c) 2009 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.
5 #include "chrome/utility/web_resource_unpacker.h"
7 #include "base/json/json_reader.h"
8 #include "base/values.h"
10 const char WebResourceUnpacker::kInvalidDataTypeError[] =
11 "Data from web resource server is missing or not valid JSON.";
13 const char WebResourceUnpacker::kUnexpectedJSONFormatError[] =
14 "Data from web resource server does not have expected format.";
16 WebResourceUnpacker::WebResourceUnpacker(const std::string &resource_data)
17 : resource_data_(resource_data) {
20 WebResourceUnpacker::~WebResourceUnpacker() {
23 // TODO(mrc): Right now, this reads JSON data from the experimental popgadget
24 // server. Change so the format is based on a template, once we have
25 // decided on final server format.
26 bool WebResourceUnpacker::Run() {
27 scoped_ptr<base::Value> value;
28 if (!resource_data_.empty()) {
29 value.reset(base::JSONReader::Read(resource_data_));
31 // Page information not properly read, or corrupted.
32 error_message_ = kInvalidDataTypeError;
35 if (!value->IsType(base::Value::TYPE_DICTIONARY)) {
36 error_message_ = kUnexpectedJSONFormatError;
39 parsed_json_.reset(static_cast<base::DictionaryValue*>(value.release()));
42 error_message_ = kInvalidDataTypeError;