summaryrefslogtreecommitdiffstats
path: root/chrome/browser/state_tracker.h
blob: 3d9ce2e4f4ea05abfaed83f5b0eebce85a3b06be (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
39
40
// 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.

#ifndef CHROME_BROWSER_STATE_TRACKER_H_
#define CHROME_BROWSER_STATE_TRACKER_H_

#include <string>

#include "base/logging.h"
#include "base/scoped_ptr.h"

// StateTracker maintains a circular character buffer. It is intended for use in
// tracking down crashes. As various events occur invoke Append. When you're
// ready to crash, invoke Crash, which copies the state onto
// the state and CHECKs.
// The '!' in the array indicates the position the next character is inserted.
// The string of characters before the '!' gives the most recent strings that
// were appended.
class StateTracker {
 public:
  StateTracker();

  // Appends |text|.
  void Append(const std::string& text);

  // Copies the appended text onto the stack and CHECKs.
  void Crash();

 private:
  // Current index into the string content is inserted at.
  size_t index_;

  // The content.
  scoped_array<char> content_;

  DISALLOW_COPY_AND_ASSIGN(StateTracker);
};

#endif  // CHROME_BROWSER_STATE_TRACKER_H_