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

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: removed AddRef/Release from file_browser_private_api.cc 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 <vector> 8 #include <vector>
9 #include <sys/statvfs.h>
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
18 namespace chromeos { 19 namespace chromeos {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 OnUnmountPath(mount_path, 204 OnUnmountPath(mount_path,
204 MOUNT_METHOD_ERROR_LOCAL, 205 MOUNT_METHOD_ERROR_LOCAL,
205 kLibraryNotLoaded); 206 kLibraryNotLoaded);
206 return; 207 return;
207 } 208 }
208 209
209 libcros_proxy_->CallUnmountPath(mount_path, &UnmountMountPointCallback, 210 libcros_proxy_->CallUnmountPath(mount_path, &UnmountMountPointCallback,
210 this); 211 this);
211 } 212 }
212 213
214 virtual void GetSizeStatsOnFileThread(const char* mount_path,
215 size_t* total_size_kb, size_t* remaining_size_kb) OVERRIDE {
216 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
217
218 uint64_t total_size_uint64 = 0;
219 uint64_t remaining_size_uint64 = 0;
220
221 struct statvfs stat;
222 if (statvfs(mount_path, &stat) == 0) {
223 total_size_uint64 =
224 static_cast<uint64_t>(stat.f_blocks) * stat.f_frsize;
225 remaining_size_uint64 =
226 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize;
227 }
228
229 *total_size_kb = static_cast<size_t>(total_size_uint64 / 1024);
230 *remaining_size_kb = static_cast<size_t>(remaining_size_uint64 / 1024);
231 }
232
213 virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE { 233 virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 if (!CrosLibrary::Get()->EnsureLoaded()) { 235 if (!CrosLibrary::Get()->EnsureLoaded()) {
216 OnFormatDevice(file_path, 236 OnFormatDevice(file_path,
217 false, 237 false,
218 MOUNT_METHOD_ERROR_LOCAL, 238 MOUNT_METHOD_ERROR_LOCAL,
219 kLibraryNotLoaded); 239 kLibraryNotLoaded);
220 return; 240 return;
221 } 241 }
222 for (MountLibrary::DiskMap::iterator it = disks_.begin(); 242 for (MountLibrary::DiskMap::iterator it = disks_.begin();
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 virtual void AddObserver(Observer* observer) OVERRIDE {} 816 virtual void AddObserver(Observer* observer) OVERRIDE {}
797 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 817 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
798 virtual const DiskMap& disks() const OVERRIDE { return disks_; } 818 virtual const DiskMap& disks() const OVERRIDE { return disks_; }
799 virtual const MountPointMap& mount_points() const OVERRIDE { 819 virtual const MountPointMap& mount_points() const OVERRIDE {
800 return mount_points_; 820 return mount_points_;
801 } 821 }
802 virtual void RequestMountInfoRefresh() OVERRIDE {} 822 virtual void RequestMountInfoRefresh() OVERRIDE {}
803 virtual void MountPath(const char* source_path, MountType type, 823 virtual void MountPath(const char* source_path, MountType type,
804 const MountPathOptions& options) OVERRIDE {} 824 const MountPathOptions& options) OVERRIDE {}
805 virtual void UnmountPath(const char* mount_path) OVERRIDE {} 825 virtual void UnmountPath(const char* mount_path) OVERRIDE {}
826 virtual void GetSizeStatsOnFileThread(const char* mount_path,
827 size_t* total_size_kb, size_t* remaining_size_kb) OVERRIDE {}
806 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {} 828 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {}
807 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {} 829 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {}
808 virtual void UnmountDeviceRecursive(const char* device_path, 830 virtual void UnmountDeviceRecursive(const char* device_path,
809 UnmountDeviceRecursiveCallbackType callback, void* user_data) 831 UnmountDeviceRecursiveCallbackType callback, void* user_data)
810 OVERRIDE {} 832 OVERRIDE {}
811 private: 833 private:
812 // The list of disks found. 834 // The list of disks found.
813 DiskMap disks_; 835 DiskMap disks_;
814 MountPointMap mount_points_; 836 MountPointMap mount_points_;
815 837
816 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl); 838 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl);
817 }; 839 };
818 840
819 // static 841 // static
820 MountLibrary* MountLibrary::GetImpl(bool stub) { 842 MountLibrary* MountLibrary::GetImpl(bool stub) {
821 if (stub) 843 if (stub)
822 return new MountLibraryStubImpl(); 844 return new MountLibraryStubImpl();
823 else 845 else
824 return new MountLibraryImpl(); 846 return new MountLibraryImpl();
825 } 847 }
826 848
827 } // namespace chromeos 849 } // namespace chromeos
828 850
829 // Allows InvokeLater without adding refcounting. This class is a Singleton and 851 // Allows InvokeLater without adding refcounting. This class is a Singleton and
830 // won't be deleted until it's last InvokeLater is run. 852 // won't be deleted until it's last InvokeLater is run.
831 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); 853 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);
832 854
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698