Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor.cc

Issue 10797056: CPM: API changes for API/UI integration. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/performance_monitor/performance_monitor_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/performance_monitor/performance_monitor_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698