| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/extensions/file_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
| 6 | 6 |
| 7 #include <sys/statvfs.h> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/base64.h" | 10 #include "base/base64.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 15 #include "base/string_split.h" | 16 #include "base/string_split.h" |
| 16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "chrome/browser/chromeos/cros/cros_library.h" | 20 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 20 #include "chrome/browser/chromeos/cros/network_library.h" | 21 #include "chrome/browser/chromeos/cros/network_library.h" |
| 21 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | |
| 22 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 22 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
| 23 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 23 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 24 #include "chrome/browser/chromeos/gdata/drive.pb.h" | 24 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
| 25 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 25 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
| 26 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 26 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
| 27 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 27 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 28 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 28 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 29 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 29 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
| 30 #include "chrome/browser/chromeos/gdata/operation_registry.h" | 30 #include "chrome/browser/chromeos/gdata/operation_registry.h" |
| 31 #include "chrome/browser/chromeos/system/statistics_provider.h" | 31 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 32 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 32 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 33 #include "chrome/browser/extensions/extension_process_manager.h" | 33 #include "chrome/browser/extensions/extension_process_manager.h" |
| 34 #include "chrome/browser/extensions/extension_service.h" | 34 #include "chrome/browser/extensions/extension_service.h" |
| 35 #include "chrome/browser/extensions/extension_tab_util.h" | 35 #include "chrome/browser/extensions/extension_tab_util.h" |
| 36 #include "chrome/browser/extensions/process_map.h" | 36 #include "chrome/browser/extensions/process_map.h" |
| 37 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
| 38 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_window.h" | 39 #include "chrome/browser/ui/browser_window.h" |
| 40 #include "chrome/browser/ui/views/select_file_dialog_extension.h" | 40 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
| 41 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 41 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 42 #include "chrome/common/chrome_version_info.h" | 42 #include "chrome/common/chrome_version_info.h" |
| 43 #include "chrome/common/extensions/extension.h" | 43 #include "chrome/common/extensions/extension.h" |
| 44 #include "chrome/common/extensions/extension_constants.h" | 44 #include "chrome/common/extensions/extension_constants.h" |
| 45 #include "chrome/common/extensions/extension_icon_set.h" | 45 #include "chrome/common/extensions/extension_icon_set.h" |
| 46 #include "chrome/common/extensions/file_browser_handler.h" | 46 #include "chrome/common/extensions/file_browser_handler.h" |
| 47 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
| 48 #include "chromeos/disks/disk_mount_manager.h" |
| 48 #include "content/public/browser/child_process_security_policy.h" | 49 #include "content/public/browser/child_process_security_policy.h" |
| 49 #include "content/public/browser/render_process_host.h" | 50 #include "content/public/browser/render_process_host.h" |
| 50 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
| 51 #include "googleurl/src/gurl.h" | 52 #include "googleurl/src/gurl.h" |
| 52 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
| 53 #include "grit/platform_locale_settings.h" | 54 #include "grit/platform_locale_settings.h" |
| 54 #include "net/base/escape.h" | 55 #include "net/base/escape.h" |
| 55 #include "ui/base/dialogs/selected_file_info.h" | 56 #include "ui/base/dialogs/selected_file_info.h" |
| 56 #include "ui/base/l10n/l10n_util.h" | 57 #include "ui/base/l10n/l10n_util.h" |
| 57 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 58 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 if (icons.empty()) | 247 if (icons.empty()) |
| 247 return result; | 248 return result; |
| 248 result = icons.rbegin()->second; | 249 result = icons.rbegin()->second; |
| 249 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); | 250 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); |
| 250 iter != icons.rend() && iter->first >= preferred_size; ++iter) { | 251 iter != icons.rend() && iter->first >= preferred_size; ++iter) { |
| 251 result = iter->second; | 252 result = iter->second; |
| 252 } | 253 } |
| 253 return result; | 254 return result; |
| 254 } | 255 } |
| 255 | 256 |
| 257 // Retrieves total and remaining available size on |mount_path|. |
| 258 void GetSizeStatsOnFileThread(const std::string& mount_path, |
| 259 size_t* total_size_kb, |
| 260 size_t* remaining_size_kb) { |
| 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 262 |
| 263 uint64_t total_size_in_bytes = 0; |
| 264 uint64_t remaining_size_in_bytes = 0; |
| 265 |
| 266 struct statvfs stat = {}; // Zero-clear |
| 267 if (statvfs(mount_path.c_str(), &stat) == 0) { |
| 268 total_size_in_bytes = |
| 269 static_cast<uint64_t>(stat.f_blocks) * stat.f_frsize; |
| 270 remaining_size_in_bytes = |
| 271 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize; |
| 272 } |
| 273 *total_size_kb = static_cast<size_t>(total_size_in_bytes / 1024); |
| 274 *remaining_size_kb = static_cast<size_t>(remaining_size_in_bytes / 1024); |
| 275 } |
| 276 |
| 256 } // namespace | 277 } // namespace |
| 257 | 278 |
| 258 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 279 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
| 259 public: | 280 public: |
| 260 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 281 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
| 261 RequestLocalFileSystemFunction* function, | 282 RequestLocalFileSystemFunction* function, |
| 262 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 283 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
| 263 int child_id, | 284 int child_id, |
| 264 scoped_refptr<const Extension> extension) { | 285 scoped_refptr<const Extension> extension) { |
| 265 return base::Bind( | 286 return base::Bind( |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 SendResponse(false); | 1282 SendResponse(false); |
| 1262 } | 1283 } |
| 1263 } | 1284 } |
| 1264 | 1285 |
| 1265 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( | 1286 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( |
| 1266 const std::string& mount_path) { | 1287 const std::string& mount_path) { |
| 1267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1268 | 1289 |
| 1269 size_t total_size_kb = 0; | 1290 size_t total_size_kb = 0; |
| 1270 size_t remaining_size_kb = 0; | 1291 size_t remaining_size_kb = 0; |
| 1271 DiskMountManager::GetInstance()-> | 1292 GetSizeStatsOnFileThread(mount_path, &total_size_kb, &remaining_size_kb); |
| 1272 GetSizeStatsOnFileThread(mount_path, &total_size_kb, &remaining_size_kb); | |
| 1273 | 1293 |
| 1274 BrowserThread::PostTask( | 1294 BrowserThread::PostTask( |
| 1275 BrowserThread::UI, FROM_HERE, | 1295 BrowserThread::UI, FROM_HERE, |
| 1276 base::Bind( | 1296 base::Bind( |
| 1277 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread, | 1297 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread, |
| 1278 this, | 1298 this, |
| 1279 total_size_kb, remaining_size_kb)); | 1299 total_size_kb, remaining_size_kb)); |
| 1280 } | 1300 } |
| 1281 | 1301 |
| 1282 void GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread( | 1302 void GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread( |
| (...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 gdata::GDataSystemService* system_service = | 2440 gdata::GDataSystemService* system_service = |
| 2421 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 2441 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 2422 if (!system_service || !system_service->file_system()) | 2442 if (!system_service || !system_service->file_system()) |
| 2423 return false; | 2443 return false; |
| 2424 | 2444 |
| 2425 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2445 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
| 2426 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2446 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
| 2427 | 2447 |
| 2428 return true; | 2448 return true; |
| 2429 } | 2449 } |
| OLD | NEW |