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

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

Issue 23050014: Convert drive::FileWriteHelper to a single function for simplification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | 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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/file_enumerator.h" 13 #include "base/files/file_enumerator.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/scoped_platform_file_closer.h" 15 #include "base/files/scoped_platform_file_closer.h"
16 #include "base/i18n/icu_string_conversions.h" 16 #include "base/i18n/icu_string_conversions.h"
17 #include "base/json/json_file_value_serializer.h" 17 #include "base/json/json_file_value_serializer.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/md5.h" 19 #include "base/md5.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/message_loop/message_loop_proxy.h" 21 #include "base/message_loop/message_loop_proxy.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/threading/sequenced_worker_pool.h" 25 #include "base/threading/sequenced_worker_pool.h"
26 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chromeos/drive/drive.pb.h" 27 #include "chrome/browser/chromeos/drive/drive.pb.h"
28 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 28 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
29 #include "chrome/browser/chromeos/drive/file_system_interface.h" 29 #include "chrome/browser/chromeos/drive/file_system_interface.h"
30 #include "chrome/browser/chromeos/drive/file_write_helper.h"
31 #include "chrome/browser/chromeos/drive/job_list.h" 30 #include "chrome/browser/chromeos/drive/job_list.h"
31 #include "chrome/browser/chromeos/drive/write_on_cache_file.h"
32 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 32 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
33 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/profiles/profile_manager.h" 34 #include "chrome/browser/profiles/profile_manager.h"
35 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
36 #include "chrome/common/chrome_paths_internal.h" 36 #include "chrome/common/chrome_paths_internal.h"
37 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
38 #include "chromeos/chromeos_constants.h" 38 #include "chromeos/chromeos_constants.h"
39 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
40 #include "net/base/escape.h" 40 #include "net/base/escape.h"
41 #include "webkit/browser/fileapi/file_system_url.h" 41 #include "webkit/browser/fileapi/file_system_url.h"
(...skipping 24 matching lines...) Expand all
66 (kDriveMyDriveMountPointPath)); 66 (kDriveMyDriveMountPointPath));
67 return drive_mydrive_mount_path; 67 return drive_mydrive_mount_path;
68 } 68 }
69 69
70 FileSystemInterface* GetFileSystem(Profile* profile) { 70 FileSystemInterface* GetFileSystem(Profile* profile) {
71 DriveIntegrationService* integration_service = 71 DriveIntegrationService* integration_service =
72 DriveIntegrationServiceFactory::GetForProfile(profile); 72 DriveIntegrationServiceFactory::GetForProfile(profile);
73 return integration_service ? integration_service->file_system() : NULL; 73 return integration_service ? integration_service->file_system() : NULL;
74 } 74 }
75 75
76 FileWriteHelper* GetFileWriteHelper(Profile* profile) {
77 DriveIntegrationService* integration_service =
78 DriveIntegrationServiceFactory::GetForProfile(profile);
79 return integration_service ? integration_service->file_write_helper() : NULL;
80 }
81
82 std::string ReadStringFromGDocFile(const base::FilePath& file_path, 76 std::string ReadStringFromGDocFile(const base::FilePath& file_path,
83 const std::string& key) { 77 const std::string& key) {
84 const int64 kMaxGDocSize = 4096; 78 const int64 kMaxGDocSize = 4096;
85 int64 file_size = 0; 79 int64 file_size = 0;
86 if (!file_util::GetFileSize(file_path, &file_size) || 80 if (!file_util::GetFileSize(file_path, &file_size) ||
87 file_size > kMaxGDocSize) { 81 file_size > kMaxGDocSize) {
88 DLOG(INFO) << "File too large to be a GDoc file " << file_path.value(); 82 DLOG(INFO) << "File too large to be a GDoc file " << file_path.value();
89 return std::string(); 83 return std::string();
90 } 84 }
91 85
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Move all files inside "persistent" to "files". 314 // Move all files inside "persistent" to "files".
321 MoveAllFilesFromDirectory(persistent_directory, cache_file_directory); 315 MoveAllFilesFromDirectory(persistent_directory, cache_file_directory);
322 base::DeleteFile(persistent_directory, true /* recursive */); 316 base::DeleteFile(persistent_directory, true /* recursive */);
323 317
324 // Move all files inside "tmp" to "files". 318 // Move all files inside "tmp" to "files".
325 MoveAllFilesFromDirectory(tmp_directory, cache_file_directory); 319 MoveAllFilesFromDirectory(tmp_directory, cache_file_directory);
326 } 320 }
327 321
328 void PrepareWritableFileAndRun(Profile* profile, 322 void PrepareWritableFileAndRun(Profile* profile,
329 const base::FilePath& path, 323 const base::FilePath& path,
330 const OpenFileCallback& callback) { 324 const PrepareWritableFileCallback& callback) {
331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
332 DCHECK(!callback.is_null()); 326 DCHECK(!callback.is_null());
333 if (IsUnderDriveMountPoint(path)) { 327
334 FileWriteHelper* file_write_helper = GetFileWriteHelper(profile); 328 FileSystemInterface* file_system = GetFileSystem(profile);
335 if (!file_write_helper) 329 if (!file_system || !IsUnderDriveMountPoint(path)) {
336 return;
337 base::FilePath remote_path(ExtractDrivePath(path));
338 file_write_helper->PrepareWritableFileAndRun(remote_path, callback);
339 } else {
340 content::BrowserThread::GetBlockingPool()->PostTask( 330 content::BrowserThread::GetBlockingPool()->PostTask(
341 FROM_HERE, base::Bind(callback, FILE_ERROR_OK, path)); 331 FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath()));
332 return;
342 } 333 }
334
335 const base::FilePath drive_path = ExtractDrivePath(path);
336 WriteOnCacheFile(file_system, drive_path, callback);
343 } 337 }
344 338
345 void EnsureDirectoryExists(Profile* profile, 339 void EnsureDirectoryExists(Profile* profile,
346 const base::FilePath& directory, 340 const base::FilePath& directory,
347 const FileOperationCallback& callback) { 341 const FileOperationCallback& callback) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
349 DCHECK(!callback.is_null()); 343 DCHECK(!callback.is_null());
350 if (IsUnderDriveMountPoint(directory)) { 344 if (IsUnderDriveMountPoint(directory)) {
351 FileSystemInterface* file_system = GetFileSystem(profile); 345 FileSystemInterface* file_system = GetFileSystem(profile);
352 DCHECK(file_system); 346 DCHECK(file_system);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 base::MD5Update(&context, base::StringPiece(buffer.get(), result)); 413 base::MD5Update(&context, base::StringPiece(buffer.get(), result));
420 } 414 }
421 415
422 base::MD5Digest digest; 416 base::MD5Digest digest;
423 base::MD5Final(&digest, &context); 417 base::MD5Final(&digest, &context);
424 return MD5DigestToBase16(digest); 418 return MD5DigestToBase16(digest);
425 } 419 }
426 420
427 } // namespace util 421 } // namespace util
428 } // namespace drive 422 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util.h ('k') | chrome/browser/chromeos/drive/file_write_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698