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

Side by Side Diff: chrome/browser/extensions/api/system_info/system_info_provider.h

Issue 16707002: [SystemInfo API] Rewrite storage info provider using storage monitor impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 7 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_ 4 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_
5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_ 5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
62 DCHECK(!callback.is_null()); 62 DCHECK(!callback.is_null());
63 63
64 callbacks_.push(callback); 64 callbacks_.push(callback);
65 65
66 if (is_waiting_for_completion_) 66 if (is_waiting_for_completion_)
67 return; 67 return;
68 68
69 is_waiting_for_completion_ = true; 69 is_waiting_for_completion_ = true;
70 70
71 StartQueryInfoImpl();
72 }
73
74 protected:
75 // Default implementation of querying system information.
76 virtual void StartQueryInfoImpl() {
77 base::Closure callback =
78 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this);
79 PostQueryTaskToBlockingPool(FROM_HERE, callback);
80 }
81
82 // Post a task to blocking pool for information querying.
83 void PostQueryTaskToBlockingPool(const tracked_objects::Location& from_here,
84 const base::Closure& query_callback) {
85 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
71 base::SequencedWorkerPool* worker_pool = 86 base::SequencedWorkerPool* worker_pool =
72 content::BrowserThread::GetBlockingPool(); 87 content::BrowserThread::GetBlockingPool();
73 // The query task posted to the worker pool won't block shutdown, and any 88 // The query task posted to the worker pool won't block shutdown, and any
74 // running query task at shutdown time will be ignored. 89 // running query task at shutdown time will be ignored.
75 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( 90 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior(
76 worker_pool_token_, 91 worker_pool_token_, from_here, query_callback,
77 FROM_HERE,
78 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this),
79 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 92 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
80 } 93 }
81 94
82 protected:
83 // Query the system information synchronously and output the result to the 95 // Query the system information synchronously and output the result to the
84 // |info| parameter. The |info| contents MUST be reset firstly in its 96 // |info| parameter. The |info| contents MUST be reset firstly in its
85 // platform specific implementation. Return true if it succeeds, otherwise 97 // platform specific implementation. Return true if it succeeds, otherwise
86 // false is returned. 98 // false is returned.
87 virtual bool QueryInfo(T* info) = 0; 99 virtual bool QueryInfo(T* info) = 0;
88 100
89 virtual void QueryOnWorkerPool() { 101 virtual void QueryOnWorkerPool() {
90 bool success = QueryInfo(&info_); 102 bool success = QueryInfo(&info_);
91 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 103 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
92 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success)); 104 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 }; 152 };
141 153
142 // Static member intialization. 154 // Static member intialization.
143 template<class T> 155 template<class T>
144 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > > 156 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > >
145 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER; 157 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER;
146 158
147 } // namespace extensions 159 } // namespace extensions
148 160
149 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_ 161 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698