OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/caps/generate_state_json.h" | 5 #include "chrome/browser/caps/generate_state_json.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/cpu.h" | 11 #include "base/cpu.h" |
12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/location.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 17 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 20 #include "base/thread_task_runner_handle.h" |
19 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
20 #include "base/time/time.h" | 22 #include "base/time/time.h" |
21 #include "base/values.h" | 23 #include "base/values.h" |
22 #include "chrome/browser/task_manager/task_manager.h" | 24 #include "chrome/browser/task_manager/task_manager.h" |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 std::string Key(base::ProcessId pid, const char* category) { | 28 std::string Key(base::ProcessId pid, const char* category) { |
27 return category ? | 29 return category ? |
28 base::StringPrintf("process.%d.%s", pid, category) : | 30 base::StringPrintf("process.%d.%s", pid, category) : |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 69 |
68 private: | 70 private: |
69 friend class base::RefCountedThreadSafe<TaskManagerDataDumper>; | 71 friend class base::RefCountedThreadSafe<TaskManagerDataDumper>; |
70 ~TaskManagerDataDumper() { | 72 ~TaskManagerDataDumper() { |
71 } | 73 } |
72 | 74 |
73 void OnDataReady() { | 75 void OnDataReady() { |
74 // Some data (for example V8 memory) has not yet arrived, so we wait. | 76 // Some data (for example V8 memory) has not yet arrived, so we wait. |
75 // TODO(cpu): Figure out how to make this reliable. | 77 // TODO(cpu): Figure out how to make this reliable. |
76 static base::TimeDelta delay = base::TimeDelta::FromMilliseconds(250); | 78 static base::TimeDelta delay = base::TimeDelta::FromMilliseconds(250); |
77 base::MessageLoop::current()->PostDelayedTask( | 79 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
78 FROM_HERE, | 80 FROM_HERE, base::Bind(&TaskManagerDataDumper::OnDataReadyDelayed, this), |
79 base::Bind(&TaskManagerDataDumper::OnDataReadyDelayed, this), | |
80 delay); | 81 delay); |
81 } | 82 } |
82 | 83 |
83 void OnDataReadyDelayed() { | 84 void OnDataReadyDelayed() { |
84 model_->StopListening(); | 85 model_->StopListening(); |
85 // Task manager finally computed (most) values. Lets generate the JSON | 86 // Task manager finally computed (most) values. Lets generate the JSON |
86 // data and send it over the pipe. | 87 // data and send it over the pipe. |
87 base::DictionaryValue dict; | 88 base::DictionaryValue dict; |
88 GatherComputerValues(&dict); | 89 GatherComputerValues(&dict); |
89 GatherChromeValues(&dict); | 90 GatherChromeValues(&dict); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } // namespace | 196 } // namespace |
196 | 197 |
197 namespace caps { | 198 namespace caps { |
198 | 199 |
199 void GenerateStateJSON( | 200 void GenerateStateJSON( |
200 scoped_refptr<TaskManagerModel> model, base::File file) { | 201 scoped_refptr<TaskManagerModel> model, base::File file) { |
201 new TaskManagerDataDumper(model, file.Pass()); | 202 new TaskManagerDataDumper(model, file.Pass()); |
202 } | 203 } |
203 | 204 |
204 } | 205 } |
OLD | NEW |