OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/stats_collection_controller.h" | 5 #include "content/renderer/stats_collection_controller.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 } | 40 } |
41 | 41 |
42 // Encodes a WebContentsLoadTime as JSON. | 42 // Encodes a WebContentsLoadTime as JSON. |
43 // Input: | 43 // Input: |
44 // - |load_start_time| - time at which page load started. | 44 // - |load_start_time| - time at which page load started. |
45 // - |load_stop_time| - time at which page load stopped. | 45 // - |load_stop_time| - time at which page load stopped. |
46 // - |result| - returned JSON. | 46 // - |result| - returned JSON. |
47 // Example return value: | 47 // Example return value: |
48 // {'load_start_ms': 1, 'load_duration_ms': 2.5} | 48 // {'load_start_ms': 1, 'load_duration_ms': 2.5} |
49 // either value may be null if a web contents hasn't fully loaded. | 49 // either value may be null if a web contents hasn't fully loaded. |
50 // load_start_ms is represented as milliseconds since system boot. | 50 // load_start_ms is represented as milliseconds since system boot. |
jeremy
2014/09/16 11:37:07
Comment needs updating
azarchs
2014/09/16 14:05:56
Done. It was already inaccurite, of course (befor
| |
51 void ConvertLoadTimeToJSON( | 51 void ConvertLoadTimeToJSON( |
52 const base::Time& load_start_time, | 52 const base::Time& load_start_time, |
53 const base::Time& load_stop_time, | 53 const base::Time& load_stop_time, |
54 std::string *result) { | 54 std::string *result) { |
55 base::DictionaryValue item; | 55 base::DictionaryValue item; |
56 | 56 |
57 if (load_start_time.is_null()) { | 57 if (load_start_time.is_null()) { |
58 item.Set("load_start_ms", base::Value::CreateNullValue()); | 58 item.Set("load_start_ms", base::Value::CreateNullValue()); |
59 } else { | 59 } else { |
60 item.SetDouble("load_start_ms", load_start_time.ToInternalValue() / 1000); | 60 item.SetDouble("load_start_ms", (load_start_time - base::Time::UnixEpoch()) |
61 .InMillisecondsF()); | |
61 } | 62 } |
62 if (load_start_time.is_null() || load_stop_time.is_null()) { | 63 if (load_start_time.is_null() || load_stop_time.is_null()) { |
63 item.Set("load_duration_ms", base::Value::CreateNullValue()); | 64 item.Set("load_duration_ms", base::Value::CreateNullValue()); |
64 } else { | 65 } else { |
65 item.SetDouble("load_duration_ms", | 66 item.SetDouble("load_duration_ms", |
66 (load_stop_time - load_start_time).InMillisecondsF()); | 67 (load_stop_time - load_start_time).InMillisecondsF()); |
67 } | 68 } |
68 base::JSONWriter::Write(&item, result); | 69 base::JSONWriter::Write(&item, result); |
69 } | 70 } |
70 | 71 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } | 151 } |
151 | 152 |
152 std::string tab_timing_json; | 153 std::string tab_timing_json; |
153 ConvertLoadTimeToJSON( | 154 ConvertLoadTimeToJSON( |
154 observer->load_start_time(), observer->load_stop_time(), | 155 observer->load_start_time(), observer->load_stop_time(), |
155 &tab_timing_json); | 156 &tab_timing_json); |
156 return tab_timing_json; | 157 return tab_timing_json; |
157 } | 158 } |
158 | 159 |
159 } // namespace content | 160 } // namespace content |
OLD | NEW |