Removed potential memory leak in PasswordFormManager::OnRequestDone
[chromium-blink-merge.git] / courgette / ensemble.cc
blob669e264e5770dfcefe3d8eecfe7f223f499ca0c3
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.
5 #include "courgette/ensemble.h"
7 #include "base/basictypes.h"
8 #include "base/strings/string_number_conversions.h"
10 #include "courgette/region.h"
11 #include "courgette/simple_delta.h"
12 #include "courgette/streams.h"
14 namespace courgette {
16 Element::Element(ExecutableType kind,
17 Ensemble* ensemble,
18 const Region& region)
19 : kind_(kind), ensemble_(ensemble), region_(region) {
22 Element::~Element() {}
24 std::string Element::Name() const {
25 return ensemble_->name() + "("
26 + base::IntToString(kind()) + ","
27 + base::Uint64ToString(offset_in_ensemble()) + ","
28 + base::Uint64ToString(region().length()) + ")";
31 // Scans the Ensemble's region, sniffing out Elements. We assume that the
32 // elements do not overlap.
33 Status Ensemble::FindEmbeddedElements() {
35 size_t length = region_.length();
36 const uint8* start = region_.start();
38 size_t position = 0;
39 while (position < length) {
40 ExecutableType type;
41 size_t detected_length;
43 Status result = DetectExecutableType(start + position,
44 length - position,
45 &type, &detected_length);
47 if (result == C_OK) {
48 Region region(start + position, detected_length);
50 Element* element = new Element(type, this, region);
51 owned_elements_.push_back(element);
52 elements_.push_back(element);
53 position += region.length();
54 } else {
55 position++;
58 return C_OK;
61 Ensemble::~Ensemble() {
62 for (size_t i = 0; i < owned_elements_.size(); ++i)
63 delete owned_elements_[i];
66 } // namespace