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

Side by Side Diff: chrome/browser/chromeos/cros/mount_library.cc

Issue 7826037: Adding support to retrieve remaining and total space on disk/file shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a Created 9 years, 3 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/cros/mount_library.h" 5 #include "chrome/browser/chromeos/cros/mount_library.h"
6 6
7 #include <set> 7 #include <set>
8 #include <sys/statvfs.h>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
13 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
14 15
15 const char* kLibraryNotLoaded = "Cros Library not loaded"; 16 const char* kLibraryNotLoaded = "Cros Library not loaded";
16 const char* kDeviceNotFound = "Device could not be found"; 17 const char* kDeviceNotFound = "Device could not be found";
17 18
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 libcros_proxy_->CallMountPath(source_path, type, options, 196 libcros_proxy_->CallMountPath(source_path, type, options,
196 &MountCompletedHandler, this); 197 &MountCompletedHandler, this);
197 } 198 }
198 199
199 virtual void UnmountPath(const char* mount_path) OVERRIDE { 200 virtual void UnmountPath(const char* mount_path) OVERRIDE {
200 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
201 libcros_proxy_->CallUnmountPath(mount_path, &UnmountMountPointCallback, 202 libcros_proxy_->CallUnmountPath(mount_path, &UnmountMountPointCallback,
202 this); 203 this);
203 } 204 }
204 205
206 virtual void GetSizeStatsOnFileThread(const char* mount_path,
207 size_t* total_size_kb, size_t* remaining_size_kb) OVERRIDE {
208 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
209
210 uint64_t total_size_uint64 = 0;
211 uint64_t remaining_size_uint64 = 0;
212
213 struct statvfs stat;
214 if (statvfs(mount_path, &stat) == 0) {
215 total_size_uint64 =
216 static_cast<uint64_t>(stat.f_blocks) * stat.f_frsize;
217 remaining_size_uint64 =
218 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize;
219 }
220
221 *total_size_kb = static_cast<size_t>(total_size_uint64 / 1024);
222 *remaining_size_kb = static_cast<size_t>(remaining_size_uint64 / 1024);
223 }
224
205 virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE { 225 virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE {
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
207 for (MountLibrary::DiskMap::iterator it = disks_.begin(); 227 for (MountLibrary::DiskMap::iterator it = disks_.begin();
208 it != disks_.end(); ++it) { 228 it != disks_.end(); ++it) {
209 if (it->second->file_path().compare(file_path) == 0 && 229 if (it->second->file_path().compare(file_path) == 0 &&
210 !it->second->mount_path().empty()) { 230 !it->second->mount_path().empty()) {
211 OnFormatDevice(file_path, 231 OnFormatDevice(file_path,
212 false, 232 false,
213 MOUNT_METHOD_ERROR_LOCAL, 233 MOUNT_METHOD_ERROR_LOCAL,
214 "Device is still mounted."); 234 "Device is still mounted.");
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 virtual void AddObserver(Observer* observer) OVERRIDE {} 802 virtual void AddObserver(Observer* observer) OVERRIDE {}
783 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 803 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
784 virtual const DiskMap& disks() const OVERRIDE { return disks_; } 804 virtual const DiskMap& disks() const OVERRIDE { return disks_; }
785 virtual const MountPointMap& mount_points() const OVERRIDE { 805 virtual const MountPointMap& mount_points() const OVERRIDE {
786 return mount_points_; 806 return mount_points_;
787 } 807 }
788 virtual void RequestMountInfoRefresh() OVERRIDE {} 808 virtual void RequestMountInfoRefresh() OVERRIDE {}
789 virtual void MountPath(const char* source_path, MountType type, 809 virtual void MountPath(const char* source_path, MountType type,
790 const MountPathOptions& options) OVERRIDE {} 810 const MountPathOptions& options) OVERRIDE {}
791 virtual void UnmountPath(const char* mount_path) OVERRIDE {} 811 virtual void UnmountPath(const char* mount_path) OVERRIDE {}
812 virtual void GetSizeStatsOnFileThread(const char* mount_path,
813 size_t* total_size_kb, size_t* remaining_size_kb) OVERRIDE {}
792 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {} 814 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {}
793 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {} 815 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {}
794 virtual void UnmountDeviceRecursive(const char* device_path, 816 virtual void UnmountDeviceRecursive(const char* device_path,
795 UnmountDeviceRecursiveCallbackType callback, void* user_data) 817 UnmountDeviceRecursiveCallbackType callback, void* user_data)
796 OVERRIDE {} 818 OVERRIDE {}
797 private: 819 private:
798 // The list of disks found. 820 // The list of disks found.
799 DiskMap disks_; 821 DiskMap disks_;
800 MountPointMap mount_points_; 822 MountPointMap mount_points_;
801 823
802 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl); 824 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl);
803 }; 825 };
804 826
805 // static 827 // static
806 MountLibrary* MountLibrary::GetImpl(bool stub) { 828 MountLibrary* MountLibrary::GetImpl(bool stub) {
807 MountLibrary* impl; 829 MountLibrary* impl;
808 if (stub) 830 if (stub)
809 impl = new MountLibraryStubImpl(); 831 impl = new MountLibraryStubImpl();
810 else 832 else
811 impl = new MountLibraryImpl(); 833 impl = new MountLibraryImpl();
812 impl->Init(); 834 impl->Init();
813 return impl; 835 return impl;
814 } 836 }
815 837
816 } // namespace chromeos 838 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/mount_library.h ('k') | chrome/browser/extensions/extension_file_browser_private_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698