| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/tracking_synchronizer.h" | 5 #include "chrome/browser/metrics/tracking_synchronizer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
| 14 #include "chrome/browser/ui/webui/tracing_ui.h" | 14 #include "chrome/browser/ui/webui/tracing_ui.h" |
| 15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
| 17 #include "content/common/child_process_info.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 19 | 20 |
| 20 using base::TimeTicks; | 21 using base::TimeTicks; |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace chrome_browser_metrics { | 24 namespace chrome_browser_metrics { |
| 24 | 25 |
| 25 // Negative numbers are never used as sequence numbers. We explicitly pick a | 26 // Negative numbers are never used as sequence numbers. We explicitly pick a |
| 26 // negative number that is "so negative" that even when we add one (as is done | 27 // negative number that is "so negative" that even when we add one (as is done |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Ignore processes that don't have a connection, such as crashed tabs. | 122 // Ignore processes that don't have a connection, such as crashed tabs. |
| 122 if (!process || !process->HasConnection()) | 123 if (!process || !process->HasConnection()) |
| 123 return; | 124 return; |
| 124 process->Send(new ChromeViewMsg_SetTrackingStatus(enable)); | 125 process->Send(new ChromeViewMsg_SetTrackingStatus(enable)); |
| 125 } | 126 } |
| 126 | 127 |
| 127 // static | 128 // static |
| 128 void TrackingSynchronizer::DeserializeTrackingList( | 129 void TrackingSynchronizer::DeserializeTrackingList( |
| 129 int sequence_number, | 130 int sequence_number, |
| 130 const std::string& tracking_data, | 131 const std::string& tracking_data, |
| 131 ChildProcessInfo::ProcessType process_type) { | 132 content::ProcessType process_type) { |
| 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 133 BrowserThread::PostTask( | 134 BrowserThread::PostTask( |
| 134 BrowserThread::UI, FROM_HERE, | 135 BrowserThread::UI, FROM_HERE, |
| 135 base::Bind( | 136 base::Bind( |
| 136 &TrackingSynchronizer::DeserializeTrackingListOnUI, | 137 &TrackingSynchronizer::DeserializeTrackingListOnUI, |
| 137 sequence_number, tracking_data, process_type)); | 138 sequence_number, tracking_data, process_type)); |
| 138 } | 139 } |
| 139 | 140 |
| 140 // static | 141 // static |
| 141 void TrackingSynchronizer::DeserializeTrackingListOnUI( | 142 void TrackingSynchronizer::DeserializeTrackingListOnUI( |
| 142 int sequence_number, | 143 int sequence_number, |
| 143 const std::string& tracking_data, | 144 const std::string& tracking_data, |
| 144 ChildProcessInfo::ProcessType process_type) { | 145 content::ProcessType process_type) { |
| 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 146 | 147 |
| 147 TrackingSynchronizer* current_synchronizer = CurrentSynchronizer(); | 148 TrackingSynchronizer* current_synchronizer = CurrentSynchronizer(); |
| 148 if (current_synchronizer == NULL) | 149 if (current_synchronizer == NULL) |
| 149 return; | 150 return; |
| 150 | 151 |
| 151 base::Value* value = | 152 base::Value* value = |
| 152 base::JSONReader().JsonToValue(tracking_data, false, true); | 153 base::JSONReader().JsonToValue(tracking_data, false, true); |
| 153 DCHECK(value->GetType() == base::Value::TYPE_DICTIONARY); | 154 DCHECK(value->GetType() == base::Value::TYPE_DICTIONARY); |
| 154 base::DictionaryValue* dictionary_value = | 155 base::DictionaryValue* dictionary_value = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 ++request->processes_pending_; | 188 ++request->processes_pending_; |
| 188 if (!render_process_host->Send( | 189 if (!render_process_host->Send( |
| 189 new ChromeViewMsg_GetRendererTrackedData(sequence_number))) { | 190 new ChromeViewMsg_GetRendererTrackedData(sequence_number))) { |
| 190 DecrementPendingProcesses(sequence_number); | 191 DecrementPendingProcesses(sequence_number); |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Get the ThreadData for the browser process and send it back. | 195 // Get the ThreadData for the browser process and send it back. |
| 195 base::DictionaryValue* value = tracked_objects::ThreadData::ToValue(); | 196 base::DictionaryValue* value = tracked_objects::ThreadData::ToValue(); |
| 196 const std::string process_type = | 197 const std::string process_type = |
| 197 ChildProcessInfo::GetTypeNameInEnglish(ChildProcessInfo::BROWSER_PROCESS); | 198 ChildProcessInfo::GetTypeNameInEnglish(content::PROCESS_TYPE_BROWSER); |
| 198 value->SetString("process_type", process_type); | 199 value->SetString("process_type", process_type); |
| 199 value->SetInteger("process_id", base::GetCurrentProcId()); | 200 value->SetInteger("process_id", base::GetCurrentProcId()); |
| 200 DCHECK_GT(request->processes_pending_, 0); | 201 DCHECK_GT(request->processes_pending_, 0); |
| 201 DecrementPendingProcessesAndSendData(sequence_number, value); | 202 DecrementPendingProcessesAndSendData(sequence_number, value); |
| 202 | 203 |
| 203 return sequence_number; | 204 return sequence_number; |
| 204 } | 205 } |
| 205 | 206 |
| 206 void TrackingSynchronizer::DecrementPendingProcessesAndSendData( | 207 void TrackingSynchronizer::DecrementPendingProcessesAndSendData( |
| 207 int sequence_number, | 208 int sequence_number, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Watch out for wrapping to a negative number. | 266 // Watch out for wrapping to a negative number. |
| 266 if (last_used_sequence_number_ < 0) | 267 if (last_used_sequence_number_ < 0) |
| 267 last_used_sequence_number_ = 1; | 268 last_used_sequence_number_ = 1; |
| 268 return last_used_sequence_number_; | 269 return last_used_sequence_number_; |
| 269 } | 270 } |
| 270 | 271 |
| 271 // static | 272 // static |
| 272 TrackingSynchronizer* TrackingSynchronizer::tracking_synchronizer_ = NULL; | 273 TrackingSynchronizer* TrackingSynchronizer::tracking_synchronizer_ = NULL; |
| 273 | 274 |
| 274 } // namespace chrome_browser_metrics | 275 } // namespace chrome_browser_metrics |
| OLD | NEW |