- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / performance_monitor / event.h
1 // Copyright (c) 2012 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.
4
5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_EVENT_H_
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_EVENT_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "base/values.h"
11
12 #include "chrome/browser/performance_monitor/event_type.h"
13
14 namespace performance_monitor {
15
16 const char* EventTypeToString(EventType event_type);
17
18 // The wrapper class for the JSON-generated event classes for the performance
19 // monitor. This class is used so we can pass around events in a single class,
20 // rather than having a variety of different types (since JSON does not
21 // currently support inheritance). Since the class will occasionally need to
22 // be compared against other events, we construct it with type and time. Other
23 // information should not be needed commonly, and is stored in a JSON-generated
24 // DictionaryValue.
25 class Event {
26  public:
27   Event(const EventType& type,
28         const base::Time& time,
29         scoped_ptr<base::DictionaryValue> data);
30   virtual ~Event();
31
32   // Construct an event from the given DictionaryValue; takes ownership of
33   // |data|.
34   static scoped_ptr<Event> FromValue(scoped_ptr<base::DictionaryValue> data);
35
36   // Accessors
37   EventType type() const { return type_; }
38   base::Time time() const { return time_; }
39   base::DictionaryValue* data() const { return data_.get(); }
40
41  private:
42
43   // The type of the event.
44   EventType type_;
45   // The time at which the event was recorded.
46   base::Time time_;
47   // The full JSON-generated value representing the information of the event;
48   // these data are described in chrome/browser/performance_monitor/events.json.
49   scoped_ptr<base::DictionaryValue> data_;
50 };
51
52 }  // namespace performance_monitor
53
54 #endif  // CHROME_BROWSER_PERFORMANCE_MONITOR_EVENT_H_