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

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

Issue 10072003: gdata: Change permissions of cache persistent directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « no previous file | no next file » | 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_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h>
8 9
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/chromeos/chromeos_version.h" 13 #include "base/chromeos/chromeos_version.h"
13 #include "base/eintr_wrapper.h" 14 #include "base/eintr_wrapper.h"
14 #include "base/file_util.h" 15 #include "base/file_util.h"
15 #include "base/json/json_file_value_serializer.h" 16 #include "base/json/json_file_value_serializer.h"
16 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
17 #include "base/json/json_writer.h" 18 #include "base/json/json_writer.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 << ": \"" << strerror(errno) 201 << ": \"" << strerror(errno)
201 << "\", " << error; 202 << "\", " << error;
202 } else { 203 } else {
203 DVLOG(1) << "Created dir " << paths_to_create[i].value(); 204 DVLOG(1) << "Created dir " << paths_to_create[i].value();
204 } 205 }
205 } 206 }
206 207
207 return error; 208 return error;
208 } 209 }
209 210
211 // Changes the permissions of |file_path| to |permissions|.
212 // Returns the platform error code of the operation.
213 base::PlatformFileError ChangeFilePermissions(const FilePath& file_path,
214 mode_t permissions) {
215 base::PlatformFileError error = base::PLATFORM_FILE_OK;
216
217 if (chmod(file_path.value().c_str(), permissions) != 0) {
218 error = SystemToPlatformError(errno);
219 PLOG(ERROR) << "Error changing permissions of " << file_path.value();
kuan 2012/04/13 02:12:13 if u want more informative log, u can append strer
Ben Chan 2012/04/13 03:05:21 PLOG() actually does that but is preferred because
kuan 2012/04/13 03:30:59 i didn't know that, gd to know, thanks :)
220 } else {
221 DVLOG(1) << "Changed permissions of " << file_path.value();
222 }
223
224 return error;
225 }
226
210 // Modifies cache state of file on IO thread pool, which involves: 227 // Modifies cache state of file on IO thread pool, which involves:
211 // - moving or copying file (per |file_operation_type|) from |source_path| to 228 // - moving or copying file (per |file_operation_type|) from |source_path| to
212 // |dest_path| if they're different 229 // |dest_path| if they're different
213 // - deleting symlink if |symlink_path| is not empty 230 // - deleting symlink if |symlink_path| is not empty
214 // - creating symlink if |symlink_path| is not empty and |create_symlink| is 231 // - creating symlink if |symlink_path| is not empty and |create_symlink| is
215 // true. 232 // true.
216 base::PlatformFileError ModifyCacheState( 233 base::PlatformFileError ModifyCacheState(
217 const FilePath& source_path, 234 const FilePath& source_path,
218 const FilePath& dest_path, 235 const FilePath& dest_path,
219 GDataFileSystem::FileOperationType file_operation_type, 236 GDataFileSystem::FileOperationType file_operation_type,
(...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after
3245 void GDataFileSystem::InitializeCacheIfNecessary() { 3262 void GDataFileSystem::InitializeCacheIfNecessary() {
3246 // Lock to access cache_initialization_started_; 3263 // Lock to access cache_initialization_started_;
3247 base::AutoLock lock(lock_); 3264 base::AutoLock lock(lock_);
3248 UnsafeInitializeCacheIfNecessary(); 3265 UnsafeInitializeCacheIfNecessary();
3249 } 3266 }
3250 3267
3251 //========= GDataFileSystem: Cache tasks that ran on io thread pool ============ 3268 //========= GDataFileSystem: Cache tasks that ran on io thread pool ============
3252 3269
3253 void GDataFileSystem::InitializeCacheOnIOThreadPool() { 3270 void GDataFileSystem::InitializeCacheOnIOThreadPool() {
3254 base::PlatformFileError error = CreateCacheDirectories(cache_paths_); 3271 base::PlatformFileError error = CreateCacheDirectories(cache_paths_);
3255
3256 if (error != base::PLATFORM_FILE_OK) 3272 if (error != base::PLATFORM_FILE_OK)
3257 return; 3273 return;
3258 3274
3275 // Change permissions of cache persistent directory to u+rwx,og+x in order to
3276 // allow archive files in that directory to be mounted by cros-disks.
3277 error = ChangeFilePermissions(
3278 gdata_cache_path_.Append(kGDataCachePersistentDir),
kuan 2012/04/13 02:12:13 u can use cache_paths_[GDataRootDirectory::CACHE_T
Ben Chan 2012/04/13 03:05:21 Done.
3279 S_IRWXU | S_IXGRP | S_IXOTH);
3280 if (error != base::PLATFORM_FILE_OK)
3281 return;
3282
3259 // Scan cache persistent and tmp directories to enumerate all files and create 3283 // Scan cache persistent and tmp directories to enumerate all files and create
3260 // corresponding entries for cache map. 3284 // corresponding entries for cache map.
3261 GDataRootDirectory::CacheMap cache_map; 3285 GDataRootDirectory::CacheMap cache_map;
3262 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_PERSISTENT, &cache_map); 3286 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_PERSISTENT, &cache_map);
3263 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_TMP, &cache_map); 3287 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_TMP, &cache_map);
3264 3288
3265 // Then scan pinned and outgoing directories to update existing entries in 3289 // Then scan pinned and outgoing directories to update existing entries in
3266 // cache map, or create new ones for pinned symlinks to /dev/null which target 3290 // cache map, or create new ones for pinned symlinks to /dev/null which target
3267 // nothing. 3291 // nothing.
3268 // Pinned and outgoing directories should be scanned after the persistent 3292 // Pinned and outgoing directories should be scanned after the persistent
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
4143 pref_registrar_->Init(profile_->GetPrefs()); 4167 pref_registrar_->Init(profile_->GetPrefs());
4144 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4168 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4145 } 4169 }
4146 4170
4147 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4171 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4148 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4172 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4149 global_free_disk_getter_for_testing = getter; 4173 global_free_disk_getter_for_testing = getter;
4150 } 4174 }
4151 4175
4152 } // namespace gdata 4176 } // namespace gdata
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698