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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/device_storage_handler.cc

Issue 2348913002: Port storage manager to MD settings. (Closed)
Patch Set: Address review comments 2. Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ui/webui/options/chromeos/storage_manager_handler.h" 5 #include "chrome/browser/ui/webui/settings/chromeos/device_storage_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <numeric> 8 #include <numeric>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" 14 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h" 15 #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h"
(...skipping 15 matching lines...) Expand all
31 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h" 31 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h"
32 #include "components/drive/chromeos/file_system_interface.h" 32 #include "components/drive/chromeos/file_system_interface.h"
33 #include "components/user_manager/user_manager.h" 33 #include "components/user_manager/user_manager.h"
34 #include "content/public/browser/browser_context.h" 34 #include "content/public/browser/browser_context.h"
35 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/storage_partition.h" 36 #include "content/public/browser/storage_partition.h"
37 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/text/bytes_formatting.h" 38 #include "ui/base/text/bytes_formatting.h"
39 39
40 namespace chromeos { 40 namespace chromeos {
41 namespace options { 41 namespace settings {
42 namespace { 42 namespace {
43 43
44 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path, 44 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path,
45 int64_t* total_size, 45 int64_t* total_size,
46 int64_t* available_size) { 46 int64_t* available_size) {
47 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path); 47 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path);
48 if (size >= 0) 48 if (size >= 0)
49 *total_size = size; 49 *total_size = size;
50 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path); 50 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path);
51 if (size >= 0) 51 if (size >= 0)
52 *available_size = size; 52 *available_size = size;
53 } 53 }
54 54
55 // Threshold to show a message indicating space is critically low (512 MB). 55 // Threshold to show a message indicating space is critically low (512 MB).
56 const int64_t kSpaceCriticallyLowBytes = 512 * 1024 * 1024; 56 const int64_t kSpaceCriticallyLowBytes = 512 * 1024 * 1024;
57 57
58 // Threshold to show a message indicating space is low (1 GB). 58 // Threshold to show a message indicating space is low (1 GB).
59 const int64_t kSpaceLowBytes = 1 * 1024 * 1024 * 1024; 59 const int64_t kSpaceLowBytes = 1 * 1024 * 1024 * 1024;
60 60
61 } // namespace 61 } // namespace
62 62
63 StorageManagerHandler::StorageManagerHandler() 63 StorageHandler::StorageHandler()
64 : browser_cache_size_(-1), 64 : browser_cache_size_(-1),
65 has_browser_cache_size_(false), 65 has_browser_cache_size_(false),
66 browser_site_data_size_(-1), 66 browser_site_data_size_(-1),
67 has_browser_site_data_size_(false), 67 has_browser_site_data_size_(false),
68 updating_downloads_size_(false), 68 updating_downloads_size_(false),
69 updating_drive_cache_size_(false), 69 updating_drive_cache_size_(false),
70 updating_browsing_data_size_(false), 70 updating_browsing_data_size_(false),
71 updating_arc_size_(false), 71 updating_android_size_(false),
72 updating_other_users_size_(false), 72 updating_other_users_size_(false) {
73 weak_ptr_factory_(this) {
74 } 73 }
75 74
76 StorageManagerHandler::~StorageManagerHandler() { 75 StorageHandler::~StorageHandler() {
77 } 76 }
78 77
79 void StorageManagerHandler::GetLocalizedValues( 78 void StorageHandler::RegisterMessages() {
80 base::DictionaryValue* localized_strings) {
81 DCHECK(localized_strings);
82
83 RegisterTitle(localized_strings, "storageManagerPage",
84 IDS_OPTIONS_SETTINGS_STORAGE_MANAGER_TAB_TITLE);
85 RegisterTitle(localized_strings, "storageClearDriveCachePage",
86 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_TAB_TITLE);
87
88 localized_strings->SetString(
89 "storageItemLabelCapacity", l10n_util::GetStringUTF16(
90 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_CAPACITY));
91 localized_strings->SetString(
92 "storageItemLabelInUse", l10n_util::GetStringUTF16(
93 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_IN_USE));
94 localized_strings->SetString(
95 "storageItemLabelAvailable", l10n_util::GetStringUTF16(
96 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_AVAILABLE));
97 localized_strings->SetString(
98 "storageSubitemLabelDownloads", l10n_util::GetStringUTF16(
99 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS));
100 localized_strings->SetString(
101 "storageSubitemLabelDriveCache", l10n_util::GetStringUTF16(
102 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DRIVE_CACHE));
103 localized_strings->SetString(
104 "storageSubitemLabelBrowsingData", l10n_util::GetStringUTF16(
105 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_BROWSING_DATA));
106 localized_strings->SetString(
107 "storageSubitemLabelOtherUsers", l10n_util::GetStringUTF16(
108 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_OTHER_USERS));
109 localized_strings->SetString(
110 "storageSubitemLabelArc", l10n_util::GetStringUTF16(
111 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC));
112 localized_strings->SetString(
113 "storageSizeCalculating", l10n_util::GetStringUTF16(
114 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING));
115 localized_strings->SetString(
116 "storageClearDriveCacheDialogTitle", l10n_util::GetStringUTF16(
117 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DIALOG_TITLE));
118 localized_strings->SetString(
119 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16(
120 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DESCRIPTION));
121 localized_strings->SetString(
122 "storageDeleteAllButtonTitle", l10n_util::GetStringUTF16(
123 IDS_OPTIONS_SETTINGS_STORAGE_DELETE_ALL_BUTTON_TITLE));
124 localized_strings->SetString(
125 "storageLowMessageTitle", l10n_util::GetStringUTF16(
126 IDS_OPTIONS_SETTINGS_STORAGE_SPACE_LOW_MESSAGE_TITLE));
127 localized_strings->SetString(
128 "storageLowMessageLine1", l10n_util::GetStringUTF16(
129 IDS_OPTIONS_SETTINGS_STORAGE_SPACE_LOW_MESSAGE_LINE_1));
130 localized_strings->SetString(
131 "storageLowMessageLine2", l10n_util::GetStringUTF16(
132 IDS_OPTIONS_SETTINGS_STORAGE_SPACE_LOW_MESSAGE_LINE_2));
133 localized_strings->SetString(
134 "storageCriticallyLowMessageTitle", l10n_util::GetStringUTF16(
135 IDS_OPTIONS_SETTINGS_STORAGE_SPACE_CRITICALLY_LOW_MESSAGE_TITLE));
136 localized_strings->SetString(
137 "storageCriticallyLowMessageLine1", l10n_util::GetStringUTF16(
138 IDS_OPTIONS_SETTINGS_STORAGE_SPACE_CRITICALLY_LOW_MESSAGE_LINE_1));
139 localized_strings->SetString(
140 "storageCriticallyLowMessageLine2", l10n_util::GetStringUTF16(
141 IDS_OPTIONS_SETTINGS_STORAGE_SPACE_CRITICALLY_LOW_MESSAGE_LINE_2));
142 }
143
144 void StorageManagerHandler::InitializePage() {
145 DCHECK(web_ui());
146 }
147
148 void StorageManagerHandler::RegisterMessages() {
149 DCHECK(web_ui()); 79 DCHECK(web_ui());
150 80
151 web_ui()->RegisterMessageCallback( 81 web_ui()->RegisterMessageCallback(
152 "updateStorageInfo", 82 "updateStorageInfo",
153 base::Bind(&StorageManagerHandler::HandleUpdateStorageInfo, 83 base::Bind(&StorageHandler::HandleUpdateStorageInfo,
154 weak_ptr_factory_.GetWeakPtr())); 84 base::Unretained(this)));
155 web_ui()->RegisterMessageCallback( 85 web_ui()->RegisterMessageCallback(
156 "openDownloads", 86 "openDownloads",
157 base::Bind(&StorageManagerHandler::HandleOpenDownloads, 87 base::Bind(&StorageHandler::HandleOpenDownloads,
158 weak_ptr_factory_.GetWeakPtr())); 88 base::Unretained(this)));
159 web_ui()->RegisterMessageCallback( 89 web_ui()->RegisterMessageCallback(
160 "openArcStorage", 90 "openArcStorage",
161 base::Bind(&StorageManagerHandler::HandleOpenArcStorage, 91 base::Bind(&StorageHandler::HandleOpenArcStorage,
162 weak_ptr_factory_.GetWeakPtr())); 92 base::Unretained(this)));
163 web_ui()->RegisterMessageCallback( 93 web_ui()->RegisterMessageCallback(
164 "clearDriveCache", 94 "clearDriveCache",
165 base::Bind(&StorageManagerHandler::HandleClearDriveCache, 95 base::Bind(&StorageHandler::HandleClearDriveCache,
166 weak_ptr_factory_.GetWeakPtr())); 96 base::Unretained(this)));
167 } 97 }
168 98
169 void StorageManagerHandler::HandleUpdateStorageInfo( 99 void StorageHandler::HandleUpdateStorageInfo(const base::ListValue* args) {
170 const base::ListValue* unused_args) { 100 AllowJavascript();
101
171 UpdateSizeStat(); 102 UpdateSizeStat();
172 UpdateDownloadsSize(); 103 UpdateDownloadsSize();
173 UpdateDriveCacheSize(); 104 UpdateDriveCacheSize();
174 UpdateBrowsingDataSize(); 105 UpdateBrowsingDataSize();
175 UpdateOtherUsersSize(); 106 UpdateOtherUsersSize();
176 UpdateArcSize(); 107 UpdateAndroidSize();
177 } 108 }
178 109
179 void StorageManagerHandler::HandleOpenDownloads( 110 void StorageHandler::HandleOpenDownloads(
180 const base::ListValue* unused_args) { 111 const base::ListValue* unused_args) {
181 Profile* const profile = Profile::FromWebUI(web_ui()); 112 Profile* const profile = Profile::FromWebUI(web_ui());
182 const base::FilePath downloads_path = 113 const base::FilePath downloads_path =
183 file_manager::util::GetDownloadsFolderForProfile(profile); 114 file_manager::util::GetDownloadsFolderForProfile(profile);
184 platform_util::OpenItem( 115 platform_util::OpenItem(
185 profile, 116 profile,
186 downloads_path, 117 downloads_path,
187 platform_util::OPEN_FOLDER, 118 platform_util::OPEN_FOLDER,
188 platform_util::OpenOperationCallback()); 119 platform_util::OpenOperationCallback());
189 } 120 }
190 121
191 void StorageManagerHandler::HandleOpenArcStorage( 122 void StorageHandler::HandleOpenArcStorage(
192 const base::ListValue* unused_args) { 123 const base::ListValue* unused_args) {
193 arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings(); 124 arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings();
194 } 125 }
195 126
196 void StorageManagerHandler::HandleClearDriveCache( 127 void StorageHandler::HandleClearDriveCache(
197 const base::ListValue* unused_args) { 128 const base::ListValue* unused_args) {
198 drive::FileSystemInterface* const file_system = 129 drive::FileSystemInterface* const file_system =
199 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); 130 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui()));
200 file_system->FreeDiskSpaceIfNeededFor( 131 file_system->FreeDiskSpaceIfNeededFor(
201 std::numeric_limits<int64_t>::max(), // Removes as much as possible. 132 std::numeric_limits<int64_t>::max(), // Removes as much as possible.
202 base::Bind(&StorageManagerHandler::OnClearDriveCacheDone, 133 base::Bind(&StorageHandler::OnClearDriveCacheDone,
203 weak_ptr_factory_.GetWeakPtr())); 134 base::Unretained(this)));
204 } 135 }
205 136
206 void StorageManagerHandler::UpdateSizeStat() { 137 void StorageHandler::UpdateSizeStat() {
207 Profile* const profile = Profile::FromWebUI(web_ui()); 138 Profile* const profile = Profile::FromWebUI(web_ui());
208 const base::FilePath downloads_path = 139 const base::FilePath downloads_path =
209 file_manager::util::GetDownloadsFolderForProfile(profile); 140 file_manager::util::GetDownloadsFolderForProfile(profile);
210 141
211 int64_t* total_size = new int64_t(0); 142 int64_t* total_size = new int64_t(0);
212 int64_t* available_size = new int64_t(0); 143 int64_t* available_size = new int64_t(0);
213 content::BrowserThread::PostBlockingPoolTaskAndReply( 144 content::BrowserThread::PostBlockingPoolTaskAndReply(
214 FROM_HERE, 145 FROM_HERE,
215 base::Bind(&GetSizeStatOnBlockingPool, 146 base::Bind(&GetSizeStatOnBlockingPool,
216 downloads_path, 147 downloads_path,
217 total_size, 148 total_size,
218 available_size), 149 available_size),
219 base::Bind(&StorageManagerHandler::OnGetSizeStat, 150 base::Bind(&StorageHandler::OnGetSizeStat,
220 weak_ptr_factory_.GetWeakPtr(), 151 base::Unretained(this),
221 base::Owned(total_size), 152 base::Owned(total_size),
222 base::Owned(available_size))); 153 base::Owned(available_size)));
223 } 154 }
224 155
225 void StorageManagerHandler::OnGetSizeStat(int64_t* total_size, 156 void StorageHandler::OnGetSizeStat(int64_t* total_size,
226 int64_t* available_size) { 157 int64_t* available_size) {
227 int64_t used_size = *total_size - *available_size; 158 int64_t used_size = *total_size - *available_size;
228 base::DictionaryValue size_stat; 159 base::DictionaryValue size_stat;
229 size_stat.SetString("totalSize", ui::FormatBytes(*total_size)); 160 size_stat.SetString("totalSize", ui::FormatBytes(*total_size));
230 size_stat.SetString("availableSize", ui::FormatBytes(*available_size)); 161 size_stat.SetString("availableSize", ui::FormatBytes(*available_size));
231 size_stat.SetString("usedSize", ui::FormatBytes(used_size)); 162 size_stat.SetString("usedSize", ui::FormatBytes(used_size));
232 size_stat.SetDouble("usedRatio", 163 size_stat.SetDouble("usedRatio",
233 static_cast<double>(used_size) / *total_size); 164 static_cast<double>(used_size) / *total_size);
234 int storage_space_state = STORAGE_SPACE_NORMAL; 165 int storage_space_state = STORAGE_SPACE_NORMAL;
235 if (*available_size < kSpaceCriticallyLowBytes) 166 if (*available_size < kSpaceCriticallyLowBytes)
236 storage_space_state = STORAGE_SPACE_CRITICALLY_LOW; 167 storage_space_state = STORAGE_SPACE_CRITICALLY_LOW;
237 else if (*available_size < kSpaceLowBytes) 168 else if (*available_size < kSpaceLowBytes)
238 storage_space_state = STORAGE_SPACE_LOW; 169 storage_space_state = STORAGE_SPACE_LOW;
239 size_stat.SetInteger("spaceState", storage_space_state); 170 size_stat.SetInteger("spaceState", storage_space_state);
240 171
241 web_ui()->CallJavascriptFunctionUnsafe( 172 CallJavascriptFunction("cr.webUIListenerCallback",
242 "options.StorageManager.setSizeStat", size_stat); 173 base::StringValue("storage-size-stat-changed"),
174 size_stat);
243 } 175 }
244 176
245 void StorageManagerHandler::UpdateDownloadsSize() { 177 void StorageHandler::UpdateDownloadsSize() {
246 if (updating_downloads_size_) 178 if (updating_downloads_size_)
247 return; 179 return;
248 updating_downloads_size_ = true; 180 updating_downloads_size_ = true;
249 181
250 Profile* const profile = Profile::FromWebUI(web_ui()); 182 Profile* const profile = Profile::FromWebUI(web_ui());
251 const base::FilePath downloads_path = 183 const base::FilePath downloads_path =
252 file_manager::util::GetDownloadsFolderForProfile(profile); 184 file_manager::util::GetDownloadsFolderForProfile(profile);
253 185
254 base::PostTaskAndReplyWithResult( 186 base::PostTaskAndReplyWithResult(
255 content::BrowserThread::GetBlockingPool(), 187 content::BrowserThread::GetBlockingPool(),
256 FROM_HERE, 188 FROM_HERE,
257 base::Bind(&base::ComputeDirectorySize, downloads_path), 189 base::Bind(&base::ComputeDirectorySize, downloads_path),
258 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, 190 base::Bind(&StorageHandler::OnGetDownloadsSize,
259 weak_ptr_factory_.GetWeakPtr())); 191 base::Unretained(this)));
260 } 192 }
261 193
262 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { 194 void StorageHandler::OnGetDownloadsSize(int64_t size) {
263 updating_downloads_size_ = false; 195 updating_downloads_size_ = false;
264 web_ui()->CallJavascriptFunctionUnsafe( 196 CallJavascriptFunction("cr.webUIListenerCallback",
265 "options.StorageManager.setDownloadsSize", 197 base::StringValue("storage-downloads-size-changed"),
266 base::StringValue(ui::FormatBytes(size))); 198 base::StringValue(ui::FormatBytes(size)));
267 } 199 }
268 200
269 void StorageManagerHandler::UpdateDriveCacheSize() { 201 void StorageHandler::UpdateDriveCacheSize() {
270 if (updating_drive_cache_size_) 202 if (updating_drive_cache_size_)
271 return; 203 return;
272 204
273 drive::FileSystemInterface* const file_system = 205 drive::FileSystemInterface* const file_system =
274 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); 206 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui()));
275 if (!file_system) 207 if (!file_system)
276 return; 208 return;
277 209
278 // Shows the item "Offline cache" and start calculating size. 210 // Shows the item "Offline cache" and start calculating size.
279 web_ui()->CallJavascriptFunctionUnsafe( 211 CallJavascriptFunction("cr.webUIListenerCallback",
280 "options.StorageManager.showDriveCacheItem"); 212 base::StringValue("storage-drive-enabled-changed"),
213 base::FundamentalValue(true));
281 updating_drive_cache_size_ = true; 214 updating_drive_cache_size_ = true;
282 file_system->CalculateCacheSize( 215 file_system->CalculateCacheSize(
283 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, 216 base::Bind(&StorageHandler::OnGetDriveCacheSize, base::Unretained(this)));
284 weak_ptr_factory_.GetWeakPtr()));
285 } 217 }
286 218
287 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { 219 void StorageHandler::OnGetDriveCacheSize(int64_t size) {
288 updating_drive_cache_size_ = false; 220 updating_drive_cache_size_ = false;
289 web_ui()->CallJavascriptFunctionUnsafe( 221 CallJavascriptFunction("cr.webUIListenerCallback",
290 "options.StorageManager.setDriveCacheSize", 222 base::StringValue("storage-drive-cache-size-changed"),
291 base::StringValue(ui::FormatBytes(size))); 223 base::StringValue(ui::FormatBytes(size)));
292 } 224 }
293 225
294 void StorageManagerHandler::UpdateBrowsingDataSize() { 226 void StorageHandler::UpdateBrowsingDataSize() {
295 if (updating_browsing_data_size_) 227 if (updating_browsing_data_size_)
296 return; 228 return;
297 updating_browsing_data_size_ = true; 229 updating_browsing_data_size_ = true;
298 230
299 has_browser_cache_size_ = false; 231 has_browser_cache_size_ = false;
300 has_browser_site_data_size_ = false; 232 has_browser_site_data_size_ = false;
301 Profile* const profile = Profile::FromWebUI(web_ui()); 233 Profile* const profile = Profile::FromWebUI(web_ui());
302 // Fetch the size of http cache in browsing data. 234 // Fetch the size of http cache in browsing data.
303 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. 235 // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
304 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( 236 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
305 content::BrowserContext::GetDefaultStoragePartition(profile), 237 content::BrowserContext::GetDefaultStoragePartition(profile),
306 base::Time(), 238 base::Time(),
307 base::Time::Max())->Count( 239 base::Time::Max())->Count(
308 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize, 240 base::Bind(&StorageHandler::OnGetBrowsingDataSize,
309 weak_ptr_factory_.GetWeakPtr(), false)); 241 base::Unretained(this), false));
310 242
311 // Fetch the size of site data in browsing data. 243 // Fetch the size of site data in browsing data.
312 if (!site_data_size_collector_.get()) { 244 if (!site_data_size_collector_.get()) {
313 content::StoragePartition* storage_partition = 245 content::StoragePartition* storage_partition =
314 content::BrowserContext::GetDefaultStoragePartition(profile); 246 content::BrowserContext::GetDefaultStoragePartition(profile);
315 site_data_size_collector_.reset(new SiteDataSizeCollector( 247 site_data_size_collector_.reset(new SiteDataSizeCollector(
316 storage_partition->GetPath(), 248 storage_partition->GetPath(),
317 new BrowsingDataCookieHelper(profile->GetRequestContext()), 249 new BrowsingDataCookieHelper(profile->GetRequestContext()),
318 new BrowsingDataDatabaseHelper(profile), 250 new BrowsingDataDatabaseHelper(profile),
319 new BrowsingDataLocalStorageHelper(profile), 251 new BrowsingDataLocalStorageHelper(profile),
320 new BrowsingDataAppCacheHelper(profile), 252 new BrowsingDataAppCacheHelper(profile),
321 new BrowsingDataIndexedDBHelper( 253 new BrowsingDataIndexedDBHelper(
322 storage_partition->GetIndexedDBContext()), 254 storage_partition->GetIndexedDBContext()),
323 BrowsingDataFileSystemHelper::Create( 255 BrowsingDataFileSystemHelper::Create(
324 storage_partition->GetFileSystemContext()), 256 storage_partition->GetFileSystemContext()),
325 BrowsingDataChannelIDHelper::Create(profile->GetRequestContext()), 257 BrowsingDataChannelIDHelper::Create(profile->GetRequestContext()),
326 new BrowsingDataServiceWorkerHelper( 258 new BrowsingDataServiceWorkerHelper(
327 storage_partition->GetServiceWorkerContext()), 259 storage_partition->GetServiceWorkerContext()),
328 new BrowsingDataCacheStorageHelper( 260 new BrowsingDataCacheStorageHelper(
329 storage_partition->GetCacheStorageContext()), 261 storage_partition->GetCacheStorageContext()),
330 BrowsingDataFlashLSOHelper::Create(profile))); 262 BrowsingDataFlashLSOHelper::Create(profile)));
331 } 263 }
332 site_data_size_collector_->Fetch( 264 site_data_size_collector_->Fetch(
333 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize, 265 base::Bind(&StorageHandler::OnGetBrowsingDataSize,
334 weak_ptr_factory_.GetWeakPtr(), true)); 266 base::Unretained(this), true));
335 } 267 }
336 268
337 void StorageManagerHandler::OnGetBrowsingDataSize(bool is_site_data, 269 void StorageHandler::OnGetBrowsingDataSize(bool is_site_data, int64_t size) {
338 int64_t size) {
339 if (is_site_data) { 270 if (is_site_data) {
340 has_browser_site_data_size_ = true; 271 has_browser_site_data_size_ = true;
341 browser_site_data_size_ = size; 272 browser_site_data_size_ = size;
342 } else { 273 } else {
343 has_browser_cache_size_ = true; 274 has_browser_cache_size_ = true;
344 browser_cache_size_ = size; 275 browser_cache_size_ = size;
345 } 276 }
346 if (has_browser_cache_size_ && has_browser_site_data_size_) { 277 if (has_browser_cache_size_ && has_browser_site_data_size_) {
347 base::string16 size_string; 278 base::string16 size_string;
348 if (browser_cache_size_ >= 0 && browser_site_data_size_ >= 0) { 279 if (browser_cache_size_ >= 0 && browser_site_data_size_ >= 0) {
349 size_string = ui::FormatBytes( 280 size_string = ui::FormatBytes(
350 browser_site_data_size_ + browser_cache_size_); 281 browser_site_data_size_ + browser_cache_size_);
351 } else { 282 } else {
352 size_string = l10n_util::GetStringUTF16( 283 size_string = l10n_util::GetStringUTF16(
353 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); 284 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN);
354 } 285 }
355 updating_browsing_data_size_ = false; 286 updating_browsing_data_size_ = false;
356 web_ui()->CallJavascriptFunctionUnsafe( 287 CallJavascriptFunction(
357 "options.StorageManager.setBrowsingDataSize", 288 "cr.webUIListenerCallback",
289 base::StringValue("storage-browsing-data-size-changed"),
358 base::StringValue(size_string)); 290 base::StringValue(size_string));
359 } 291 }
360 } 292 }
361 293
362 void StorageManagerHandler::UpdateOtherUsersSize() { 294 void StorageHandler::UpdateOtherUsersSize() {
363 if (updating_other_users_size_) 295 if (updating_other_users_size_)
364 return; 296 return;
365 updating_other_users_size_ = true; 297 updating_other_users_size_ = true;
366 298
367 other_users_.clear(); 299 other_users_.clear();
368 user_sizes_.clear(); 300 user_sizes_.clear();
369 const user_manager::UserList& users = 301 const user_manager::UserList& users =
370 user_manager::UserManager::Get()->GetUsers(); 302 user_manager::UserManager::Get()->GetUsers();
371 for (auto* user : users) { 303 for (auto* user : users) {
372 if (user->is_active()) 304 if (user->is_active())
373 continue; 305 continue;
374 other_users_.push_back(user); 306 other_users_.push_back(user);
375 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage( 307 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage(
376 cryptohome::Identification(user->GetAccountId()), 308 cryptohome::Identification(user->GetAccountId()),
377 base::Bind(&StorageManagerHandler::OnGetOtherUserSize, 309 base::Bind(&StorageHandler::OnGetOtherUserSize,
378 weak_ptr_factory_.GetWeakPtr())); 310 base::Unretained(this)));
379 } 311 }
380 // We should show "0 B" if there is no other user. 312 // We should show "0 B" if there is no other user.
381 if (other_users_.empty()) { 313 if (other_users_.empty()) {
382 updating_other_users_size_ = false; 314 updating_other_users_size_ = false;
383 web_ui()->CallJavascriptFunctionUnsafe( 315 CallJavascriptFunction(
384 "options.StorageManager.setOtherUsersSize", 316 "cr.webUIListenerCallback",
317 base::StringValue("storage-other-users-size-changed"),
385 base::StringValue(ui::FormatBytes(0))); 318 base::StringValue(ui::FormatBytes(0)));
386 } 319 }
387 } 320 }
388 321
389 void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) { 322 void StorageHandler::OnGetOtherUserSize(bool success, int64_t size) {
390 user_sizes_.push_back(success ? size : -1); 323 user_sizes_.push_back(success ? size : -1);
391 if (user_sizes_.size() == other_users_.size()) { 324 if (user_sizes_.size() == other_users_.size()) {
392 base::string16 size_string; 325 base::string16 size_string;
393 // If all the requests succeed, shows the total bytes in the UI. 326 // If all the requests succeed, shows the total bytes in the UI.
394 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) { 327 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) {
395 size_string = ui::FormatBytes( 328 size_string = ui::FormatBytes(
396 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL)); 329 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL));
397 } else { 330 } else {
398 size_string = l10n_util::GetStringUTF16( 331 size_string = l10n_util::GetStringUTF16(
399 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); 332 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN);
400 } 333 }
401 updating_other_users_size_ = false; 334 updating_other_users_size_ = false;
402 web_ui()->CallJavascriptFunctionUnsafe( 335 CallJavascriptFunction(
403 "options.StorageManager.setOtherUsersSize", 336 "cr.webUIListenerCallback",
337 base::StringValue("storage-other-users-size-changed"),
404 base::StringValue(size_string)); 338 base::StringValue(size_string));
405 } 339 }
406 } 340 }
407 341
408 void StorageManagerHandler::UpdateArcSize() { 342 void StorageHandler::UpdateAndroidSize() {
409 if (updating_arc_size_) 343 if (updating_android_size_)
410 return; 344 return;
411 updating_arc_size_ = true; 345 updating_android_size_ = true;
412 346
413 Profile* const profile = Profile::FromWebUI(web_ui()); 347 Profile* const profile = Profile::FromWebUI(web_ui());
414 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || 348 if (!arc::ArcAuthService::IsAllowedForProfile(profile) ||
415 arc::ArcAuthService::IsOptInVerificationDisabled() || 349 arc::ArcAuthService::IsOptInVerificationDisabled() ||
416 !arc::ArcAuthService::Get()->IsArcEnabled()) { 350 !arc::ArcAuthService::Get()->IsArcEnabled()) {
417 return; 351 return;
418 } 352 }
419 353
420 // Shows the item "Android apps and cache" and start calculating size. 354 // Shows the item "Android apps and cache" and start calculating size.
421 web_ui()->CallJavascriptFunctionUnsafe( 355 CallJavascriptFunction("cr.webUIListenerCallback",
422 "options.StorageManager.showArcItem"); 356 base::StringValue("storage-android-enabled-changed"),
357 base::FundamentalValue(true));
423 bool success = arc::ArcStorageManager::Get()->GetApplicationsSize( 358 bool success = arc::ArcStorageManager::Get()->GetApplicationsSize(
424 base::Bind(&StorageManagerHandler::OnGetArcSize, 359 base::Bind(&StorageHandler::OnGetAndroidSize,
425 weak_ptr_factory_.GetWeakPtr())); 360 base::Unretained(this)));
426 if (!success) 361 if (!success)
427 updating_arc_size_ = false; 362 updating_android_size_ = false;
428 } 363 }
429 364
430 void StorageManagerHandler::OnGetArcSize(bool succeeded, 365 void StorageHandler::OnGetAndroidSize(bool succeeded,
431 arc::mojom::ApplicationsSizePtr size) { 366 arc::mojom::ApplicationsSizePtr size) {
432 base::string16 size_string; 367 base::string16 size_string;
433 if (succeeded) { 368 if (succeeded) {
434 uint64_t total_bytes = size->total_code_bytes + 369 uint64_t total_bytes = size->total_code_bytes +
435 size->total_data_bytes + 370 size->total_data_bytes +
436 size->total_cache_bytes; 371 size->total_cache_bytes;
437 size_string = ui::FormatBytes(total_bytes); 372 size_string = ui::FormatBytes(total_bytes);
438 } else { 373 } else {
439 size_string = l10n_util::GetStringUTF16( 374 size_string = l10n_util::GetStringUTF16(
440 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); 375 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN);
441 } 376 }
442 updating_arc_size_ = false; 377 updating_android_size_ = false;
443 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", 378 CallJavascriptFunction("cr.webUIListenerCallback",
444 base::StringValue(size_string)); 379 base::StringValue("storage-android-size-changed"),
380 base::StringValue(size_string));
445 } 381 }
446 382
447 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { 383 void StorageHandler::OnClearDriveCacheDone(bool success) {
448 UpdateDriveCacheSize(); 384 UpdateDriveCacheSize();
449 } 385 }
450 386
451 } // namespace options 387 } // namespace settings
452 } // namespace chromeos 388 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698