summaryrefslogtreecommitdiffstats
path: root/chrome/common/web_resource/web_resource_unpacker.cc
blob: a8215472429ddc9afd31916252fd7a962df640f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/web_resource/web_resource_unpacker.h"

#include "base/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.";

// TODO(mrc): Right now, this reads JSON data from the experimental popgadget
// server.  Change so the format is based on a template, once we have
// decided on final server format.
bool WebResourceUnpacker::Run() {
  scoped_ptr<Value> value;
  if (!resource_data_.empty()) {
    value.reset(JSONReader::Read(resource_data_, false));
    if (!value.get()) {
      // Page information not properly read, or corrupted.
      error_message_ = kInvalidDataTypeError;
      return false;
    }
    if (!value->IsType(Value::TYPE_LIST)) {
      error_message_ = kUnexpectedJSONFormatError;
      return false;
    }
    parsed_json_.reset(static_cast<ListValue*>(value.release()));
    return true;
  }
  error_message_ = kInvalidDataTypeError;
  return false;
}