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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_util.cc

Issue 23523022: Replace GetForProfile by Get{FileSystem,DriveAppRegistry,DriveService)ByProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 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/drive/file_system_util.h" 5 #include "chrome/browser/chromeos/drive/file_system_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 const char kSlash[] = "/"; 64 const char kSlash[] = "/";
65 const char kEscapedSlash[] = "\xE2\x88\x95"; 65 const char kEscapedSlash[] = "\xE2\x88\x95";
66 66
67 const base::FilePath& GetDriveMyDriveMountPointPath() { 67 const base::FilePath& GetDriveMyDriveMountPointPath() {
68 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_mydrive_mount_path, 68 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_mydrive_mount_path,
69 (kDriveMyDriveMountPointPath)); 69 (kDriveMyDriveMountPointPath));
70 return drive_mydrive_mount_path; 70 return drive_mydrive_mount_path;
71 } 71 }
72 72
73 FileSystemInterface* GetFileSystem(Profile* profile) {
74 DriveIntegrationService* integration_service =
75 DriveIntegrationServiceFactory::GetForProfile(profile);
76 return integration_service ? integration_service->file_system() : NULL;
77 }
78
79 std::string ReadStringFromGDocFile(const base::FilePath& file_path, 73 std::string ReadStringFromGDocFile(const base::FilePath& file_path,
80 const std::string& key) { 74 const std::string& key) {
81 const int64 kMaxGDocSize = 4096; 75 const int64 kMaxGDocSize = 4096;
82 int64 file_size = 0; 76 int64 file_size = 0;
83 if (!file_util::GetFileSize(file_path, &file_size) || 77 if (!file_util::GetFileSize(file_path, &file_size) ||
84 file_size > kMaxGDocSize) { 78 file_size > kMaxGDocSize) {
85 DLOG(INFO) << "File too large to be a GDoc file " << file_path.value(); 79 DLOG(INFO) << "File too large to be a GDoc file " << file_path.value();
86 return std::string(); 80 return std::string();
87 } 81 }
88 82
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 (util::kDriveMyDriveRootPath)); 127 (util::kDriveMyDriveRootPath));
134 return drive_root_path; 128 return drive_root_path;
135 } 129 }
136 130
137 const base::FilePath& GetDriveMountPointPath() { 131 const base::FilePath& GetDriveMountPointPath() {
138 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_mount_path, 132 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_mount_path,
139 (base::FilePath::FromUTF8Unsafe(kDriveMountPointPath))); 133 (base::FilePath::FromUTF8Unsafe(kDriveMountPointPath)));
140 return drive_mount_path; 134 return drive_mount_path;
141 } 135 }
142 136
137 FileSystemInterface* GetFileSystemByProfile(Profile* profile) {
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
139
140 DriveIntegrationService* integration_service =
141 DriveIntegrationServiceFactory::GetForProfile(profile);
kinaba 2013/09/04 08:57:42 How about implementing (as an anonymous-namespace
hidehiko 2013/09/04 09:35:42 Done.
142 // TODO(hidehiko): GetForProfile will return DriveIntegrationService
143 // regardless of mounting state. Needs to check the mounting state
144 // later. crbug.com/284972.
145 return integration_service ? integration_service->file_system() : NULL;
146 }
147
143 FileSystemInterface* GetFileSystemByProfileId(void* profile_id) { 148 FileSystemInterface* GetFileSystemByProfileId(void* profile_id) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
145 150
146 // |profile_id| needs to be checked with ProfileManager::IsValidProfile 151 // |profile_id| needs to be checked with ProfileManager::IsValidProfile
147 // before using it. 152 // before using it.
148 Profile* profile = reinterpret_cast<Profile*>(profile_id); 153 Profile* profile = reinterpret_cast<Profile*>(profile_id);
149 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 154 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
150 return NULL; 155 return NULL;
151 return GetFileSystem(profile); 156 return GetFileSystemByProfile(profile);
157 }
158
159 DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
161
162 DriveIntegrationService* integration_service =
163 DriveIntegrationServiceFactory::GetForProfile(profile);
kinaba 2013/09/04 08:57:42 ditto
hidehiko 2013/09/04 09:35:42 Done.
164 // TODO(hidehiko): GetForProfile will return DriveIntegrationService
165 // regardless of mounting state. Needs to check the mounting state
166 // later. crbug.com/284972.
167 return integration_service ?
168 integration_service->drive_app_registry() :
169 NULL;
170 }
171
172 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile) {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
174
175 DriveIntegrationService* integration_service =
176 DriveIntegrationServiceFactory::GetForProfile(profile);
kinaba 2013/09/04 08:57:42 ditto
hidehiko 2013/09/04 09:35:42 Done.
177 // TODO(hidehiko): GetForProfile will return DriveIntegrationService
178 // regardless of mounting state. Needs to check the mounting state
179 // later. crbug.com/284972.
180 return integration_service ? integration_service->drive_service() : NULL;
152 } 181 }
153 182
154 bool IsSpecialResourceId(const std::string& resource_id) { 183 bool IsSpecialResourceId(const std::string& resource_id) {
155 return resource_id == kDriveGrandRootSpecialResourceId || 184 return resource_id == kDriveGrandRootSpecialResourceId ||
156 resource_id == kDriveOtherDirSpecialResourceId; 185 resource_id == kDriveOtherDirSpecialResourceId;
157 } 186 }
158 187
159 ResourceEntry CreateMyDriveRootEntry(const std::string& root_resource_id) { 188 ResourceEntry CreateMyDriveRootEntry(const std::string& root_resource_id) {
160 ResourceEntry mydrive_root; 189 ResourceEntry mydrive_root;
161 mydrive_root.mutable_file_info()->set_is_directory(true); 190 mydrive_root.mutable_file_info()->set_is_directory(true);
(...skipping 23 matching lines...) Expand all
185 url.path(), net::UnescapeRule::NORMAL); 214 url.path(), net::UnescapeRule::NORMAL);
186 return base::FilePath::FromUTF8Unsafe(path_string); 215 return base::FilePath::FromUTF8Unsafe(path_string);
187 } 216 }
188 217
189 void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) { 218 void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
191 220
192 if (!IsUnderDriveMountPoint(path)) 221 if (!IsUnderDriveMountPoint(path))
193 return; 222 return;
194 223
195 FileSystemInterface* file_system = GetFileSystem(profile); 224 FileSystemInterface* file_system = GetFileSystemByProfile(profile);
196 if (!file_system) 225 if (!file_system)
197 return; 226 return;
198 227
199 *url = FilePathToDriveURL(util::ExtractDrivePath(path)); 228 *url = FilePathToDriveURL(util::ExtractDrivePath(path));
200 } 229 }
201 230
202 bool IsUnderDriveMountPoint(const base::FilePath& path) { 231 bool IsUnderDriveMountPoint(const base::FilePath& path) {
203 return GetDriveMountPointPath() == path || 232 return GetDriveMountPointPath() == path ||
204 GetDriveMountPointPath().IsParent(path); 233 GetDriveMountPointPath().IsParent(path);
205 } 234 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // Move all files inside "tmp" to "files". 341 // Move all files inside "tmp" to "files".
313 MoveAllFilesFromDirectory(tmp_directory, cache_file_directory); 342 MoveAllFilesFromDirectory(tmp_directory, cache_file_directory);
314 } 343 }
315 344
316 void PrepareWritableFileAndRun(Profile* profile, 345 void PrepareWritableFileAndRun(Profile* profile,
317 const base::FilePath& path, 346 const base::FilePath& path,
318 const PrepareWritableFileCallback& callback) { 347 const PrepareWritableFileCallback& callback) {
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
320 DCHECK(!callback.is_null()); 349 DCHECK(!callback.is_null());
321 350
322 FileSystemInterface* file_system = GetFileSystem(profile); 351 FileSystemInterface* file_system = GetFileSystemByProfile(profile);
323 if (!file_system || !IsUnderDriveMountPoint(path)) { 352 if (!file_system || !IsUnderDriveMountPoint(path)) {
324 content::BrowserThread::GetBlockingPool()->PostTask( 353 content::BrowserThread::GetBlockingPool()->PostTask(
325 FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath())); 354 FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath()));
326 return; 355 return;
327 } 356 }
328 357
329 WriteOnCacheFile(file_system, 358 WriteOnCacheFile(file_system,
330 ExtractDrivePath(path), 359 ExtractDrivePath(path),
331 std::string(), // mime_type 360 std::string(), // mime_type
332 callback); 361 callback);
333 } 362 }
334 363
335 void EnsureDirectoryExists(Profile* profile, 364 void EnsureDirectoryExists(Profile* profile,
336 const base::FilePath& directory, 365 const base::FilePath& directory,
337 const FileOperationCallback& callback) { 366 const FileOperationCallback& callback) {
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
339 DCHECK(!callback.is_null()); 368 DCHECK(!callback.is_null());
340 if (IsUnderDriveMountPoint(directory)) { 369 if (IsUnderDriveMountPoint(directory)) {
341 FileSystemInterface* file_system = GetFileSystem(profile); 370 FileSystemInterface* file_system = GetFileSystemByProfile(profile);
342 DCHECK(file_system); 371 DCHECK(file_system);
343 file_system->CreateDirectory( 372 file_system->CreateDirectory(
344 ExtractDrivePath(directory), 373 ExtractDrivePath(directory),
345 true /* is_exclusive */, 374 true /* is_exclusive */,
346 true /* is_recursive */, 375 true /* is_recursive */,
347 callback); 376 callback);
348 } else { 377 } else {
349 base::MessageLoopProxy::current()->PostTask( 378 base::MessageLoopProxy::current()->PostTask(
350 FROM_HERE, base::Bind(callback, FILE_ERROR_OK)); 379 FROM_HERE, base::Bind(callback, FILE_ERROR_OK));
351 } 380 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // Disable Drive if preference is set. This can happen with commandline flag 452 // Disable Drive if preference is set. This can happen with commandline flag
424 // --disable-drive or enterprise policy, or with user settings. 453 // --disable-drive or enterprise policy, or with user settings.
425 if (profile->GetPrefs()->GetBoolean(prefs::kDisableDrive)) 454 if (profile->GetPrefs()->GetBoolean(prefs::kDisableDrive))
426 return false; 455 return false;
427 456
428 return true; 457 return true;
429 } 458 }
430 459
431 } // namespace util 460 } // namespace util
432 } // namespace drive 461 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util.h ('k') | chrome/browser/chromeos/extensions/file_manager/file_tasks.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698