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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_cache.cc

Issue 10843041: Add OS_CHROMEOS case in file_util::GetHomeDir() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 (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/gdata/gdata_cache.h" 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/chromeos/chromeos_version.h" 9 #include "base/chromeos/chromeos_version.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 20 matching lines...) Expand all
31 const FilePath::CharType kGDataCacheOutgoingDir[] = 31 const FilePath::CharType kGDataCacheOutgoingDir[] =
32 FILE_PATH_LITERAL("outgoing"); 32 FILE_PATH_LITERAL("outgoing");
33 const FilePath::CharType kGDataCachePersistentDir[] = 33 const FilePath::CharType kGDataCachePersistentDir[] =
34 FILE_PATH_LITERAL("persistent"); 34 FILE_PATH_LITERAL("persistent");
35 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp"); 35 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
36 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 36 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
37 FILE_PATH_LITERAL("tmp/downloads"); 37 FILE_PATH_LITERAL("tmp/downloads");
38 const FilePath::CharType kGDataCacheTmpDocumentsDir[] = 38 const FilePath::CharType kGDataCacheTmpDocumentsDir[] =
39 FILE_PATH_LITERAL("tmp/documents"); 39 FILE_PATH_LITERAL("tmp/documents");
40 40
41 // Returns the home directory path, or an empty string if the home directory
42 // is not found.
43 // Copied from webkit/chromeos/cros_mount_point_provider.h.
44 // TODO(satorux): Share the code.
45 std::string GetHomeDirectory() {
46 if (base::chromeos::IsRunningOnChromeOS())
47 return "/home/chronos/user";
48
49 const char* home = getenv("HOME");
50 if (home)
51 return home;
52 return "";
53 }
54
55 // Used to tweak GetAmountOfFreeDiskSpace() behavior for testing. 41 // Used to tweak GetAmountOfFreeDiskSpace() behavior for testing.
56 FreeDiskSpaceGetterInterface* global_free_disk_getter_for_testing = NULL; 42 FreeDiskSpaceGetterInterface* global_free_disk_getter_for_testing = NULL;
57 43
58 // Gets the amount of free disk space. Use 44 // Gets the amount of free disk space. Use
59 // |global_free_disk_getter_for_testing| if set. 45 // |global_free_disk_getter_for_testing| if set.
60 int64 GetAmountOfFreeDiskSpace() { 46 int64 GetAmountOfFreeDiskSpace() {
61 if (global_free_disk_getter_for_testing) 47 if (global_free_disk_getter_for_testing)
62 return global_free_disk_getter_for_testing->AmountOfFreeDiskSpace(); 48 return global_free_disk_getter_for_testing->AmountOfFreeDiskSpace();
63 49
64 return base::SysInfo::AmountOfFreeDiskSpace( 50 return base::SysInfo::AmountOfFreeDiskSpace(
65 FilePath::FromUTF8Unsafe(GetHomeDirectory())); 51 FilePath::FromUTF8Unsafe(base::chromeos::GetHomeDirectory()));
66 } 52 }
67 53
68 // Returns true if we have sufficient space to store the given number of 54 // Returns true if we have sufficient space to store the given number of
69 // bytes, while keeping kMinFreeSpace bytes on the disk. 55 // bytes, while keeping kMinFreeSpace bytes on the disk.
70 bool HasEnoughSpaceFor(int64 num_bytes) { 56 bool HasEnoughSpaceFor(int64 num_bytes) {
71 int64 free_space = GetAmountOfFreeDiskSpace(); 57 int64 free_space = GetAmountOfFreeDiskSpace();
72 // Subtract this as if this portion does not exist. 58 // Subtract this as if this portion does not exist.
73 free_space -= kMinFreeSpace; 59 free_space -= kMinFreeSpace;
74 return (free_space >= num_bytes); 60 return (free_space >= num_bytes);
75 } 61 }
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 const GDataCacheEntry& cache_entry) { 1534 const GDataCacheEntry& cache_entry) {
1549 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; 1535 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
1550 } 1536 }
1551 1537
1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1538 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1539 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1554 global_free_disk_getter_for_testing = getter; 1540 global_free_disk_getter_for_testing = getter;
1555 } 1541 }
1556 1542
1557 } // namespace gdata 1543 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698