Home | History | Annotate | Download | only in performance_monitor
      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 namespace performance_monitor {
     13 
     14 // IMPORTANT: To add new events, please
     15 // - Place the new event above EVENT_NUMBER_OF_EVENTS.
     16 // - Add a member to the EventKeyChar enum in key_builder.cc.
     17 // - Add the appropriate messages in generated_resources.grd.
     18 // - Add the appropriate functions in
     19 //   chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h.
     20 enum EventType {
     21   EVENT_UNDEFINED,
     22 
     23   // Extension-Related events
     24   EVENT_EXTENSION_INSTALL,
     25   EVENT_EXTENSION_UNINSTALL,
     26   EVENT_EXTENSION_UPDATE,
     27   EVENT_EXTENSION_ENABLE,
     28   EVENT_EXTENSION_DISABLE,
     29 
     30   // Chrome's version has changed.
     31   EVENT_CHROME_UPDATE,
     32 
     33   // Renderer-Failure related events; these correspond to the RENDERER_HANG
     34   // event, and the two termination statuses ABNORMAL_EXIT and PROCESS_KILLED,
     35   // respectively.
     36   EVENT_RENDERER_HANG,
     37   EVENT_RENDERER_CRASH,
     38   EVENT_RENDERER_KILLED,
     39 
     40   // Chrome did not shut down correctly.
     41   EVENT_UNCLEAN_EXIT,
     42 
     43   EVENT_NUMBER_OF_EVENTS
     44 };
     45 
     46 const char* EventTypeToString(EventType event_type);
     47 
     48 // The wrapper class for the JSON-generated event classes for the performance
     49 // monitor. This class is used so we can pass around events in a single class,
     50 // rather than having a variety of different types (since JSON does not
     51 // currently support inheritance). Since the class will occasionally need to
     52 // be compared against other events, we construct it with type and time. Other
     53 // information should not be needed commonly, and is stored in a JSON-generated
     54 // DictionaryValue.
     55 class Event {
     56  public:
     57   Event(const EventType& type,
     58         const base::Time& time,
     59         scoped_ptr<base::DictionaryValue> data);
     60   virtual ~Event();
     61 
     62   // Construct an event from the given DictionaryValue; takes ownership of
     63   // |data|.
     64   static scoped_ptr<Event> FromValue(scoped_ptr<base::DictionaryValue> data);
     65 
     66   // Accessors
     67   EventType type() const { return type_; }
     68   base::Time time() const { return time_; }
     69   base::DictionaryValue* data() const { return data_.get(); }
     70 
     71  private:
     72 
     73   // The type of the event.
     74   EventType type_;
     75   // The time at which the event was recorded.
     76   base::Time time_;
     77   // The full JSON-generated value representing the information of the event;
     78   // these data are described in chrome/browser/performance_monitor/events.json.
     79   scoped_ptr<base::DictionaryValue> data_;
     80 };
     81 
     82 }  // namespace performance_monitor
     83 
     84 #endif  // CHROME_BROWSER_PERFORMANCE_MONITOR_EVENT_H_
     85