OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/performance_monitor/performance_monitor.h" | 5 #include "chrome/browser/performance_monitor/performance_monitor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // PerformanceMonitor already initialized with another path. | 44 // PerformanceMonitor already initialized with another path. |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 // static | 48 // static |
49 PerformanceMonitor* PerformanceMonitor::GetInstance() { | 49 PerformanceMonitor* PerformanceMonitor::GetInstance() { |
50 return Singleton<PerformanceMonitor>::get(); | 50 return Singleton<PerformanceMonitor>::get(); |
51 } | 51 } |
52 | 52 |
53 void PerformanceMonitor::Start() { | 53 void PerformanceMonitor::Start() { |
54 BrowserThread::PostBlockingPoolTaskAndReply( | 54 util::PostTaskToDatabaseThreadAndReply( |
55 FROM_HERE, | 55 FROM_HERE, |
56 base::Bind(&PerformanceMonitor::InitOnBackgroundThread, | 56 base::Bind(&PerformanceMonitor::InitOnBackgroundThread, |
57 base::Unretained(this)), | 57 base::Unretained(this)), |
58 base::Bind(&PerformanceMonitor::FinishInit, | 58 base::Bind(&PerformanceMonitor::FinishInit, |
59 base::Unretained(this))); | 59 base::Unretained(this))); |
60 } | 60 } |
61 | 61 |
62 void PerformanceMonitor::InitOnBackgroundThread() { | 62 void PerformanceMonitor::InitOnBackgroundThread() { |
63 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
64 database_ = Database::Create(database_path_); | 64 database_ = Database::Create(database_path_); |
65 } | 65 } |
66 | 66 |
67 void PerformanceMonitor::FinishInit() { | 67 void PerformanceMonitor::FinishInit() { |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
69 RegisterForNotifications(); | 69 RegisterForNotifications(); |
70 BrowserThread::PostBlockingPoolSequencedTask( | 70 BrowserThread::PostBlockingPoolSequencedTask( |
71 Database::kDatabaseSequenceToken, | 71 Database::kDatabaseSequenceToken, |
72 FROM_HERE, | 72 FROM_HERE, |
73 base::Bind(&PerformanceMonitor::CheckForVersionUpdateOnBackgroundThread, | 73 base::Bind(&PerformanceMonitor::CheckForVersionUpdateOnBackgroundThread, |
74 base::Unretained(this))); | 74 base::Unretained(this))); |
75 | 75 |
76 // Post a task to the background thread to a function which does nothing. | 76 // Post a task to the background thread to a function which does nothing. |
77 // This will force any tasks the database is performing to finish prior to | 77 // This will force any tasks the database is performing to finish prior to |
78 // the reply being sent, since they use the same thread. | 78 // the reply being sent, since they use the same thread. |
79 // | 79 // |
80 // Important! Make sure that methods in FinishInit() only rely on posting | 80 // Important! Make sure that methods in FinishInit() only rely on posting |
81 // to the background thread, and do not rely upon a reply from the background | 81 // to the background thread, and do not rely upon a reply from the background |
82 // thread; this is necessary for this notification to be valid. | 82 // thread; this is necessary for this notification to be valid. |
83 util::PostTaskToDatabaseThreadAndReply( | 83 util::PostTaskToDatabaseThreadAndReply( |
| 84 FROM_HERE, |
84 base::Bind(&base::DoNothing), | 85 base::Bind(&base::DoNothing), |
85 base::Bind(&PerformanceMonitor::NotifyInitialized, | 86 base::Bind(&PerformanceMonitor::NotifyInitialized, |
86 base::Unretained(this))); | 87 base::Unretained(this))); |
87 } | 88 } |
88 | 89 |
89 void PerformanceMonitor::RegisterForNotifications() { | 90 void PerformanceMonitor::RegisterForNotifications() { |
90 // Extensions | 91 // Extensions |
91 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 92 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
92 content::NotificationService::AllSources()); | 93 content::NotificationService::AllSources()); |
93 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, | 94 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 break; | 261 break; |
261 } | 262 } |
262 default: { | 263 default: { |
263 NOTREACHED(); | 264 NOTREACHED(); |
264 break; | 265 break; |
265 } | 266 } |
266 } | 267 } |
267 } | 268 } |
268 | 269 |
269 } // namespace performance_monitor | 270 } // namespace performance_monitor |
OLD | NEW |