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

Side by Side Diff: chrome/browser/extensions/api/system_storage/storage_info_provider.cc

Issue 216513002: Replace DCHECK(BrowserThread::CurrentlyOn) with DCHECK_CURRENTLY_ON in extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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 4
5 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h" 5 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 provider_.Get() = provider; 57 provider_.Get() = provider;
58 } 58 }
59 59
60 void StorageInfoProvider::PrepareQueryOnUIThread() { 60 void StorageInfoProvider::PrepareQueryOnUIThread() {
61 // Get all available storage devices before invoking |QueryInfo()|. 61 // Get all available storage devices before invoking |QueryInfo()|.
62 GetAllStoragesIntoInfoList(); 62 GetAllStoragesIntoInfoList();
63 } 63 }
64 64
65 void StorageInfoProvider::InitializeProvider( 65 void StorageInfoProvider::InitializeProvider(
66 const base::Closure& do_query_info_callback) { 66 const base::Closure& do_query_info_callback) {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 DCHECK_CURRENTLY_ON(BrowserThread::UI);
68 // Register the |do_query_info_callback| callback to StorageMonitor. 68 // Register the |do_query_info_callback| callback to StorageMonitor.
69 // See the comments of StorageMonitor::EnsureInitialized about when the 69 // See the comments of StorageMonitor::EnsureInitialized about when the
70 // callback gets run. 70 // callback gets run.
71 StorageMonitor::GetInstance()->EnsureInitialized(do_query_info_callback); 71 StorageMonitor::GetInstance()->EnsureInitialized(do_query_info_callback);
72 } 72 }
73 73
74 bool StorageInfoProvider::QueryInfo() { 74 bool StorageInfoProvider::QueryInfo() {
75 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 75 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
76 // No info to query since we get all available storage devices' info in 76 // No info to query since we get all available storage devices' info in
77 // |PrepareQueryOnUIThread()|. 77 // |PrepareQueryOnUIThread()|.
78 return true; 78 return true;
79 } 79 }
80 80
81 void StorageInfoProvider::GetAllStoragesIntoInfoList() { 81 void StorageInfoProvider::GetAllStoragesIntoInfoList() {
82 info_.clear(); 82 info_.clear();
83 std::vector<StorageInfo> storage_list = 83 std::vector<StorageInfo> storage_list =
84 StorageMonitor::GetInstance()->GetAllAvailableStorages(); 84 StorageMonitor::GetInstance()->GetAllAvailableStorages();
85 85
86 for (std::vector<StorageInfo>::const_iterator it = storage_list.begin(); 86 for (std::vector<StorageInfo>::const_iterator it = storage_list.begin();
87 it != storage_list.end(); ++it) { 87 it != storage_list.end(); ++it) {
88 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo()); 88 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
89 systeminfo::BuildStorageUnitInfo(*it, unit.get()); 89 systeminfo::BuildStorageUnitInfo(*it, unit.get());
90 info_.push_back(unit); 90 info_.push_back(unit);
91 } 91 }
92 } 92 }
93 93
94 double StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread( 94 double StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread(
95 const std::string& transient_id) { 95 const std::string& transient_id) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 96 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
97 std::vector<StorageInfo> storage_list = 97 std::vector<StorageInfo> storage_list =
98 StorageMonitor::GetInstance()->GetAllAvailableStorages(); 98 StorageMonitor::GetInstance()->GetAllAvailableStorages();
99 99
100 std::string device_id = 100 std::string device_id =
101 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( 101 StorageMonitor::GetInstance()->GetDeviceIdForTransientId(
102 transient_id); 102 transient_id);
103 103
104 // Lookup the matched storage info by |device_id|. 104 // Lookup the matched storage info by |device_id|.
105 for (std::vector<StorageInfo>::const_iterator it = 105 for (std::vector<StorageInfo>::const_iterator it =
106 storage_list.begin(); 106 storage_list.begin();
107 it != storage_list.end(); ++it) { 107 it != storage_list.end(); ++it) {
108 if (device_id == it->device_id()) 108 if (device_id == it->device_id())
109 return static_cast<double>(base::SysInfo::AmountOfFreeDiskSpace( 109 return static_cast<double>(base::SysInfo::AmountOfFreeDiskSpace(
110 base::FilePath(it->location()))); 110 base::FilePath(it->location())));
111 } 111 }
112 112
113 return -1; 113 return -1;
114 } 114 }
115 115
116 // static 116 // static
117 StorageInfoProvider* StorageInfoProvider::Get() { 117 StorageInfoProvider* StorageInfoProvider::Get() {
118 if (provider_.Get().get() == NULL) 118 if (provider_.Get().get() == NULL)
119 provider_.Get() = new StorageInfoProvider(); 119 provider_.Get() = new StorageInfoProvider();
120 return provider_.Get(); 120 return provider_.Get();
121 } 121 }
122 122
123 } // namespace extensions 123 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698