OLD | NEW |
---|---|
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/options/chromeos/storage_manager_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <numeric> | 8 #include <numeric> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 StorageManagerHandler::StorageManagerHandler() |
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), | |
69 updating_drive_cache_size_(false), | |
70 updating_browsing_data_size_(false), | |
71 updating_arc_size_(false), | |
72 updating_other_users_size_(false), | |
68 weak_ptr_factory_(this) { | 73 weak_ptr_factory_(this) { |
69 } | 74 } |
70 | 75 |
71 StorageManagerHandler::~StorageManagerHandler() { | 76 StorageManagerHandler::~StorageManagerHandler() { |
72 } | 77 } |
73 | 78 |
74 void StorageManagerHandler::GetLocalizedValues( | 79 void StorageManagerHandler::GetLocalizedValues( |
75 base::DictionaryValue* localized_strings) { | 80 base::DictionaryValue* localized_strings) { |
76 DCHECK(localized_strings); | 81 DCHECK(localized_strings); |
77 | 82 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 storage_space_state = STORAGE_SPACE_CRITICALLY_LOW; | 236 storage_space_state = STORAGE_SPACE_CRITICALLY_LOW; |
232 else if (*available_size < kSpaceLowBytes) | 237 else if (*available_size < kSpaceLowBytes) |
233 storage_space_state = STORAGE_SPACE_LOW; | 238 storage_space_state = STORAGE_SPACE_LOW; |
234 size_stat.SetInteger("spaceState", storage_space_state); | 239 size_stat.SetInteger("spaceState", storage_space_state); |
235 | 240 |
236 web_ui()->CallJavascriptFunctionUnsafe( | 241 web_ui()->CallJavascriptFunctionUnsafe( |
237 "options.StorageManager.setSizeStat", size_stat); | 242 "options.StorageManager.setSizeStat", size_stat); |
238 } | 243 } |
239 | 244 |
240 void StorageManagerHandler::UpdateDownloadsSize() { | 245 void StorageManagerHandler::UpdateDownloadsSize() { |
246 if (updating_downloads_size_) | |
247 return; | |
248 updating_downloads_size_ = true; | |
249 | |
241 Profile* const profile = Profile::FromWebUI(web_ui()); | 250 Profile* const profile = Profile::FromWebUI(web_ui()); |
242 const base::FilePath downloads_path = | 251 const base::FilePath downloads_path = |
243 file_manager::util::GetDownloadsFolderForProfile(profile); | 252 file_manager::util::GetDownloadsFolderForProfile(profile); |
244 | 253 |
245 base::PostTaskAndReplyWithResult( | 254 base::PostTaskAndReplyWithResult( |
246 content::BrowserThread::GetBlockingPool(), | 255 content::BrowserThread::GetBlockingPool(), |
247 FROM_HERE, | 256 FROM_HERE, |
248 base::Bind(&base::ComputeDirectorySize, downloads_path), | 257 base::Bind(&base::ComputeDirectorySize, downloads_path), |
249 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, | 258 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, |
250 weak_ptr_factory_.GetWeakPtr())); | 259 weak_ptr_factory_.GetWeakPtr())); |
251 } | 260 } |
252 | 261 |
253 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { | 262 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { |
263 updating_downloads_size_ = false; | |
254 web_ui()->CallJavascriptFunctionUnsafe( | 264 web_ui()->CallJavascriptFunctionUnsafe( |
255 "options.StorageManager.setDownloadsSize", | 265 "options.StorageManager.setDownloadsSize", |
256 base::StringValue(ui::FormatBytes(size))); | 266 base::StringValue(ui::FormatBytes(size))); |
257 } | 267 } |
258 | 268 |
259 void StorageManagerHandler::UpdateDriveCacheSize() { | 269 void StorageManagerHandler::UpdateDriveCacheSize() { |
270 if (updating_drive_cache_size_) | |
271 return; | |
272 updating_drive_cache_size_ = true; | |
273 | |
260 drive::FileSystemInterface* const file_system = | 274 drive::FileSystemInterface* const file_system = |
261 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); | 275 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); |
262 file_system->CalculateCacheSize( | 276 file_system->CalculateCacheSize( |
263 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, | 277 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, |
264 weak_ptr_factory_.GetWeakPtr())); | 278 weak_ptr_factory_.GetWeakPtr())); |
265 } | 279 } |
266 | 280 |
267 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { | 281 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { |
282 updating_drive_cache_size_ = false; | |
268 web_ui()->CallJavascriptFunctionUnsafe( | 283 web_ui()->CallJavascriptFunctionUnsafe( |
269 "options.StorageManager.setDriveCacheSize", | 284 "options.StorageManager.setDriveCacheSize", |
270 base::StringValue(ui::FormatBytes(size))); | 285 base::StringValue(ui::FormatBytes(size))); |
271 } | 286 } |
272 | 287 |
273 void StorageManagerHandler::UpdateBrowsingDataSize() { | 288 void StorageManagerHandler::UpdateBrowsingDataSize() { |
289 if (updating_browsing_data_size_) | |
290 return; | |
291 updating_browsing_data_size_ = true; | |
292 | |
274 has_browser_cache_size_ = false; | 293 has_browser_cache_size_ = false; |
275 has_browser_site_data_size_ = false; | 294 has_browser_site_data_size_ = false; |
276 Profile* const profile = Profile::FromWebUI(web_ui()); | 295 Profile* const profile = Profile::FromWebUI(web_ui()); |
277 // Fetch the size of http cache in browsing data. | 296 // Fetch the size of http cache in browsing data. |
278 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. | 297 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. |
279 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( | 298 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( |
280 content::BrowserContext::GetDefaultStoragePartition(profile), | 299 content::BrowserContext::GetDefaultStoragePartition(profile), |
281 base::Time(), | 300 base::Time(), |
282 base::Time::Max())->Count( | 301 base::Time::Max())->Count( |
283 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize, | 302 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 } | 339 } |
321 if (has_browser_cache_size_ && has_browser_site_data_size_) { | 340 if (has_browser_cache_size_ && has_browser_site_data_size_) { |
322 base::string16 size_string; | 341 base::string16 size_string; |
323 if (browser_cache_size_ >= 0 && browser_site_data_size_ >= 0) { | 342 if (browser_cache_size_ >= 0 && browser_site_data_size_ >= 0) { |
324 size_string = ui::FormatBytes( | 343 size_string = ui::FormatBytes( |
325 browser_site_data_size_ + browser_cache_size_); | 344 browser_site_data_size_ + browser_cache_size_); |
326 } else { | 345 } else { |
327 size_string = l10n_util::GetStringUTF16( | 346 size_string = l10n_util::GetStringUTF16( |
328 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); | 347 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); |
329 } | 348 } |
349 updating_browsing_data_size_ = false; | |
330 web_ui()->CallJavascriptFunctionUnsafe( | 350 web_ui()->CallJavascriptFunctionUnsafe( |
331 "options.StorageManager.setBrowsingDataSize", | 351 "options.StorageManager.setBrowsingDataSize", |
332 base::StringValue(size_string)); | 352 base::StringValue(size_string)); |
333 } | 353 } |
334 } | 354 } |
335 | 355 |
336 void StorageManagerHandler::UpdateOtherUsersSize() { | 356 void StorageManagerHandler::UpdateOtherUsersSize() { |
357 if (updating_other_users_size_) | |
358 return; | |
359 updating_other_users_size_ = true; | |
360 | |
337 other_users_.clear(); | 361 other_users_.clear(); |
338 user_sizes_.clear(); | 362 user_sizes_.clear(); |
339 const user_manager::UserList& users = | 363 const user_manager::UserList& users = |
340 user_manager::UserManager::Get()->GetUsers(); | 364 user_manager::UserManager::Get()->GetUsers(); |
341 for (const auto& user : users) { | 365 for (const auto& user : users) { |
342 if (user->is_active()) | 366 if (user->is_active()) |
343 continue; | 367 continue; |
344 other_users_.push_back(user); | 368 other_users_.push_back(user); |
345 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage( | 369 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage( |
346 cryptohome::Identification(user->GetAccountId()), | 370 cryptohome::Identification(user->GetAccountId()), |
347 base::Bind(&StorageManagerHandler::OnGetOtherUserSize, | 371 base::Bind(&StorageManagerHandler::OnGetOtherUserSize, |
348 weak_ptr_factory_.GetWeakPtr())); | 372 weak_ptr_factory_.GetWeakPtr())); |
349 } | 373 } |
350 } | 374 } |
351 | 375 |
352 void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) { | 376 void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) { |
353 user_sizes_.push_back(success ? size : -1); | 377 user_sizes_.push_back(success ? size : -1); |
354 if (user_sizes_.size() == other_users_.size()) { | 378 if (user_sizes_.size() == other_users_.size()) { |
355 base::string16 size_string; | 379 base::string16 size_string; |
356 // If all the requests succeed, shows the total bytes in the UI. | 380 // If all the requests succeed, shows the total bytes in the UI. |
357 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) { | 381 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) { |
358 size_string = ui::FormatBytes( | 382 size_string = ui::FormatBytes( |
359 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL)); | 383 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL)); |
360 } else { | 384 } else { |
361 size_string = l10n_util::GetStringUTF16( | 385 size_string = l10n_util::GetStringUTF16( |
362 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); | 386 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); |
363 } | 387 } |
388 updating_other_users_size_ = false; | |
364 web_ui()->CallJavascriptFunctionUnsafe( | 389 web_ui()->CallJavascriptFunctionUnsafe( |
365 "options.StorageManager.setOtherUsersSize", | 390 "options.StorageManager.setOtherUsersSize", |
366 base::StringValue(size_string)); | 391 base::StringValue(size_string)); |
367 } | 392 } |
368 } | 393 } |
369 | 394 |
370 void StorageManagerHandler::UpdateArcSize() { | 395 void StorageManagerHandler::UpdateArcSize() { |
396 if (updating_arc_size_) | |
397 return; | |
398 updating_arc_size_ = true; | |
399 | |
371 Profile* const profile = Profile::FromWebUI(web_ui()); | 400 Profile* const profile = Profile::FromWebUI(web_ui()); |
372 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || | 401 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || |
373 arc::ArcAuthService::IsOptInVerificationDisabled() || | 402 arc::ArcAuthService::IsOptInVerificationDisabled() || |
374 !arc::ArcAuthService::Get()->IsArcEnabled()) { | 403 !arc::ArcAuthService::Get()->IsArcEnabled()) { |
375 return; | 404 return; |
376 } | 405 } |
377 | 406 |
378 // Shows the item "Android apps and cache" and start calculating size. | 407 // Shows the item "Android apps and cache" and start calculating size. |
379 web_ui()->CallJavascriptFunctionUnsafe( | 408 web_ui()->CallJavascriptFunctionUnsafe( |
380 "options.StorageManager.showArcItem"); | 409 "options.StorageManager.showArcItem"); |
381 bool success = arc::ArcStorageManager::Get()->GetApplicationsSize( | 410 bool success = arc::ArcStorageManager::Get()->GetApplicationsSize( |
382 base::Bind(&StorageManagerHandler::OnGetArcSize, | 411 base::Bind(&StorageManagerHandler::OnGetArcSize, |
383 base::Unretained(this))); | 412 base::Unretained(this))); |
384 if (!success) { | 413 if (!success) |
385 // TODO(fukino): Retry updating arc size later if the arc bridge service is | 414 updating_arc_size_ = false; |
386 // not ready. | |
387 web_ui()->CallJavascriptFunctionUnsafe( | |
fukino
2016/07/08 10:28:37
As we try to update the Android size every 5 secon
| |
388 "options.StorageManager.setArcSize", | |
389 base::StringValue(l10n_util::GetStringUTF16( | |
390 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN))); | |
391 } | |
392 } | 415 } |
393 | 416 |
394 void StorageManagerHandler::OnGetArcSize(bool succeeded, | 417 void StorageManagerHandler::OnGetArcSize(bool succeeded, |
395 arc::mojom::ApplicationsSizePtr size) { | 418 arc::mojom::ApplicationsSizePtr size) { |
396 base::string16 size_string; | 419 base::string16 size_string; |
397 if (succeeded) { | 420 if (succeeded) { |
398 uint64_t total_bytes = size->total_code_bytes + | 421 uint64_t total_bytes = size->total_code_bytes + |
399 size->total_data_bytes + | 422 size->total_data_bytes + |
400 size->total_cache_bytes; | 423 size->total_cache_bytes; |
401 size_string = ui::FormatBytes(total_bytes); | 424 size_string = ui::FormatBytes(total_bytes); |
402 } else { | 425 } else { |
403 size_string = l10n_util::GetStringUTF16( | 426 size_string = l10n_util::GetStringUTF16( |
404 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); | 427 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); |
405 } | 428 } |
429 updating_arc_size_ = false; | |
406 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", | 430 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", |
407 base::StringValue(size_string)); | 431 base::StringValue(size_string)); |
408 } | 432 } |
409 | 433 |
410 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { | 434 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { |
411 UpdateDriveCacheSize(); | 435 UpdateDriveCacheSize(); |
412 } | 436 } |
413 | 437 |
414 } // namespace options | 438 } // namespace options |
415 } // namespace chromeos | 439 } // namespace chromeos |
OLD | NEW |