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

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: Fix styles 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
« no previous file with comments | « base/file_util_posix.cc ('k') | webkit/chromeos/fileapi/cros_mount_point_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/sys_info.h" 15 #include "base/sys_info.h"
15 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 16 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
16 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" 17 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h"
17 #include "chrome/browser/chromeos/gdata/gdata_util.h" 18 #include "chrome/browser/chromeos/gdata/gdata_util.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_paths_internal.h" 21 #include "chrome/common/chrome_paths_internal.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 23
23 using content::BrowserThread; 24 using content::BrowserThread;
24 25
25 namespace gdata { 26 namespace gdata {
26 namespace { 27 namespace {
27 28
28 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); 29 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1");
29 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); 30 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta");
30 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); 31 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned");
31 const FilePath::CharType kGDataCacheOutgoingDir[] = 32 const FilePath::CharType kGDataCacheOutgoingDir[] =
32 FILE_PATH_LITERAL("outgoing"); 33 FILE_PATH_LITERAL("outgoing");
33 const FilePath::CharType kGDataCachePersistentDir[] = 34 const FilePath::CharType kGDataCachePersistentDir[] =
34 FILE_PATH_LITERAL("persistent"); 35 FILE_PATH_LITERAL("persistent");
35 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp"); 36 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
36 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 37 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
37 FILE_PATH_LITERAL("tmp/downloads"); 38 FILE_PATH_LITERAL("tmp/downloads");
38 const FilePath::CharType kGDataCacheTmpDocumentsDir[] = 39 const FilePath::CharType kGDataCacheTmpDocumentsDir[] =
39 FILE_PATH_LITERAL("tmp/documents"); 40 FILE_PATH_LITERAL("tmp/documents");
40 41
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. 42 // Used to tweak GetAmountOfFreeDiskSpace() behavior for testing.
56 FreeDiskSpaceGetterInterface* global_free_disk_getter_for_testing = NULL; 43 FreeDiskSpaceGetterInterface* global_free_disk_getter_for_testing = NULL;
57 44
58 // Gets the amount of free disk space. Use 45 // Gets the amount of free disk space. Use
59 // |global_free_disk_getter_for_testing| if set. 46 // |global_free_disk_getter_for_testing| if set.
60 int64 GetAmountOfFreeDiskSpace() { 47 int64 GetAmountOfFreeDiskSpace() {
61 if (global_free_disk_getter_for_testing) 48 if (global_free_disk_getter_for_testing)
62 return global_free_disk_getter_for_testing->AmountOfFreeDiskSpace(); 49 return global_free_disk_getter_for_testing->AmountOfFreeDiskSpace();
63 50
64 return base::SysInfo::AmountOfFreeDiskSpace( 51 FilePath path;
65 FilePath::FromUTF8Unsafe(GetHomeDirectory())); 52 if (!PathService::Get(base::DIR_HOME, &path)) {
53 LOG(ERROR) << "Home directory not found";
54 return -1;
55 }
56 return base::SysInfo::AmountOfFreeDiskSpace(path);
66 } 57 }
67 58
68 // Returns true if we have sufficient space to store the given number of 59 // Returns true if we have sufficient space to store the given number of
69 // bytes, while keeping kMinFreeSpace bytes on the disk. 60 // bytes, while keeping kMinFreeSpace bytes on the disk.
70 bool HasEnoughSpaceFor(int64 num_bytes) { 61 bool HasEnoughSpaceFor(int64 num_bytes) {
71 int64 free_space = GetAmountOfFreeDiskSpace(); 62 int64 free_space = GetAmountOfFreeDiskSpace();
72 // Subtract this as if this portion does not exist. 63 // Subtract this as if this portion does not exist.
73 free_space -= kMinFreeSpace; 64 free_space -= kMinFreeSpace;
74 return (free_space >= num_bytes); 65 return (free_space >= num_bytes);
75 } 66 }
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 const GDataCacheEntry& cache_entry) { 1564 const GDataCacheEntry& cache_entry) {
1574 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; 1565 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
1575 } 1566 }
1576 1567
1577 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1568 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1578 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1569 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1579 global_free_disk_getter_for_testing = getter; 1570 global_free_disk_getter_for_testing = getter;
1580 } 1571 }
1581 1572
1582 } // namespace gdata 1573 } // namespace gdata
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | webkit/chromeos/fileapi/cros_mount_point_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698