Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Copyright (c) 2006-2008 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.
5 #include "base/tracked.h"
7 #include "base/string_util.h"
8 #include "base/tracked_objects.h"
10 using base::Time;
12 namespace tracked_objects {
14 //------------------------------------------------------------------------------
15 void Location::Write(bool display_filename, bool display_function_name,
16 std::string* output) const {
17 StringAppendF(output, "%s[%d] ",
18 display_filename ? file_name_ : "line",
19 line_number_);
21 if (display_function_name) {
22 WriteFunctionName(output);
23 output->push_back(' ');
24 }
25 }
27 void Location::WriteFunctionName(std::string* output) const {
28 // Translate "<" to "<" for HTML safety.
29 // TODO(jar): Support ASCII or html for logging in ASCII.
30 for (const char *p = function_name_; *p; p++) {
31 switch (*p) {
32 case '<':
33 output->append("<");
34 break;
36 case '>':
37 output->append(">");
38 break;
40 default:
41 output->push_back(*p);
42 break;
43 }
44 }
45 }
47 //------------------------------------------------------------------------------
49 #ifndef TRACK_ALL_TASK_OBJECTS
51 Tracked::Tracked() {}
52 Tracked::~Tracked() {}
53 void Tracked::SetBirthPlace(const Location& from_here) {}
54 bool Tracked::MissingBirthplace() const { return false; }
55 void Tracked::ResetBirthTime() {}
57 #else
59 Tracked::Tracked() : tracked_births_(NULL), tracked_birth_time_(Time::Now()) {
60 if (!ThreadData::IsActive())
61 return;
62 SetBirthPlace(Location("NoFunctionName", "NeedToSetBirthPlace", -1));
63 }
65 Tracked::~Tracked() {
66 if (!ThreadData::IsActive() || !tracked_births_)
67 return;
68 ThreadData::current()->TallyADeath(*tracked_births_,
69 Time::Now() - tracked_birth_time_);
70 }
72 void Tracked::SetBirthPlace(const Location& from_here) {
73 if (!ThreadData::IsActive())
74 return;
75 if (tracked_births_)
76 tracked_births_->ForgetBirth();
77 ThreadData* current_thread_data = ThreadData::current();
78 if (!current_thread_data)
79 return; // Shutdown started, and this thread wasn't registered.
80 tracked_births_ = current_thread_data->FindLifetime(from_here);
81 tracked_births_->RecordBirth();
82 }
84 void Tracked::ResetBirthTime() {
85 tracked_birth_time_ = Time::Now();
86 }
88 bool Tracked::MissingBirthplace() const {
89 return -1 == tracked_births_->location().line_number();
90 }
92 #endif // NDEBUG
94 } // namespace tracked_objects