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

Unified Diff: chrome/browser/extensions/api/system_info_storage/storage_info_provider.cc

Issue 18290002: [SystemInfo API] Finish TODOs in SystemInfoProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dev_rewrite_storage_info_api
Patch Set: Update according to Greg and Jeffrey's comments Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/system_info_storage/storage_info_provider.cc
diff --git a/chrome/browser/extensions/api/system_info_storage/storage_info_provider.cc b/chrome/browser/extensions/api/system_info_storage/storage_info_provider.cc
index 581e02f509b9c360f2cdeeaf22fb103babe3dc53..220687cdabc127a65f66e3501b0cd4629f52fa00 100644
--- a/chrome/browser/extensions/api/system_info_storage/storage_info_provider.cc
+++ b/chrome/browser/extensions/api/system_info_storage/storage_info_provider.cc
@@ -42,6 +42,11 @@ void BuildStorageUnitInfo(const chrome::StorageInfo& info,
const int kDefaultPollingIntervalMs = 1000;
const char kWatchingTokenName[] = "_storage_info_watching_token_";
+// Static member intialization.
+base::LazyInstance<scoped_refptr<SystemInfoProvider<StorageUnitInfoList> > >
+ SystemInfoProvider<StorageUnitInfoList>::provider_
+ = LAZY_INSTANCE_INITIALIZER;
+
StorageInfoProvider::StorageInfoProvider()
: observers_(new ObserverListThreadSafe<StorageFreeSpaceObserver>()),
watching_interval_(kDefaultPollingIntervalMs) {
@@ -50,55 +55,53 @@ StorageInfoProvider::StorageInfoProvider()
StorageInfoProvider::~StorageInfoProvider() {
}
+const StorageUnitInfoList& StorageInfoProvider::storage_unit_info_list() const {
+ return info_;
+}
+
void StorageInfoProvider::StartQueryInfoImpl() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // Register a callback to notify UI thread that StorageMonitor finishes the
- // storage metadata retrieval on FILE thread. See the comments of
- // StorageMonitor::Initialize about when the callback gets run.
+ // Register a callback to StorageMonitor.
+ // See the comments of StorageMonitor::EnsureInitialized about when the
+ // callback gets run.
StorageMonitor::GetInstance()->EnsureInitialized(
base::Bind(&StorageInfoProvider::QueryInfoImplOnUIThread, this));
}
void StorageInfoProvider::QueryInfoImplOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // At this point, we can call StorageMonitor::GetAllAvailableStorages to
- // get the correct results.
- QueryInfo(&info_);
- // The amount of available capacity should be queried on blocking pool.
- PostQueryTaskToBlockingPool(FROM_HERE,
- base::Bind(&StorageInfoProvider::QueryAvailableCapacityOnBlockingPool,
- this));
+
+ GetAllStoragesIntoInfoList();
+
+ PostQueryTaskToBlockingPool(
+ base::Bind(&StorageInfoProvider::QueryInfo, this));
}
-void StorageInfoProvider::QueryAvailableCapacityOnBlockingPool() {
+bool StorageInfoProvider::QueryInfo() {
DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
- for (StorageInfo::iterator it = info_.begin(); it != info_.end(); ++it) {
+ for (StorageUnitInfoList::iterator it = info_.begin();
+ it != info_.end(); ++it) {
int64 amount = GetStorageFreeSpaceFromTransientId((*it)->id);
if (amount > 0)
(*it)->available_capacity = static_cast<double>(amount);
}
- // Notify UI thread that the querying operation has completed.
- BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
- base::Bind(&StorageInfoProvider::OnQueryCompleted, this, true));
+ return true;
}
std::vector<chrome::StorageInfo> StorageInfoProvider::GetAllStorages() const {
return StorageMonitor::GetInstance()->GetAllAvailableStorages();
}
-bool StorageInfoProvider::QueryInfo(StorageInfo* info) {
+void StorageInfoProvider::GetAllStoragesIntoInfoList() {
+ info_.clear();
std::vector<chrome::StorageInfo> storage_list = GetAllStorages();
- StorageInfo results;
std::vector<chrome::StorageInfo>::const_iterator it = storage_list.begin();
for (; it != storage_list.end(); ++it) {
linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
systeminfo::BuildStorageUnitInfo(*it, unit.get());
- results.push_back(unit);
+ info_.push_back(unit);
}
- info->swap(results);
-
- return true;
}
void StorageInfoProvider::AddObserver(StorageFreeSpaceObserver* obs) {
@@ -128,6 +131,20 @@ void StorageInfoProvider::StopWatching(const std::string& transient_id) {
this, transient_id));
}
+void StorageInfoProvider::StartWatchingAllStorages() {
+ for (StorageUnitInfoList::const_iterator it = info_.begin();
+ it != info_.end(); ++it) {
+ StartWatching((*it)->id);
+ }
+}
+
+void StorageInfoProvider::StopWatchingAllStorages() {
+ for (StorageUnitInfoList::const_iterator it = info_.begin();
+ it != info_.end(); ++it) {
+ StopWatching((*it)->id);
+ }
+}
+
int64 StorageInfoProvider::GetStorageFreeSpaceFromTransientId(
const std::string& transient_id) {
std::vector<chrome::StorageInfo> storage_list = GetAllStorages();

Powered by Google App Engine
This is Rietveld 408576698