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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/download_operation.cc

Issue 16278006: In DownloadOperation use locally modified file info if dirty Drive cache exists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 7 years, 6 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 | chrome/browser/chromeos/drive/file_system/download_operation_unittest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/download_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/download_operation.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 19 matching lines...) Expand all
30 // the path to the JSON file. 30 // the path to the JSON file.
31 // If the resource is a regular file and its local cache is available, 31 // If the resource is a regular file and its local cache is available,
32 // returns FILE_ERROR_OK with |cache_file_path| storing the path to the 32 // returns FILE_ERROR_OK with |cache_file_path| storing the path to the
33 // cache file. 33 // cache file.
34 // If the resource is a regular file but its local cache is NOT available, 34 // If the resource is a regular file but its local cache is NOT available,
35 // returns FILE_ERROR_OK, but |cache_file_path| is kept empty. 35 // returns FILE_ERROR_OK, but |cache_file_path| is kept empty.
36 // Otherwise returns error code. 36 // Otherwise returns error code.
37 FileError CheckPreConditionForEnsureFileDownloaded( 37 FileError CheckPreConditionForEnsureFileDownloaded(
38 internal::ResourceMetadata* metadata, 38 internal::ResourceMetadata* metadata,
39 internal::FileCache* cache, 39 internal::FileCache* cache,
40 const ResourceEntry& entry, 40 ResourceEntry* entry,
41 base::FilePath* cache_file_path) { 41 base::FilePath* cache_file_path) {
42 DCHECK(metadata); 42 DCHECK(metadata);
43 DCHECK(cache); 43 DCHECK(cache);
44 DCHECK(cache_file_path); 44 DCHECK(cache_file_path);
45 45
46 if (entry.file_info().is_directory()) 46 if (entry->file_info().is_directory())
47 return FILE_ERROR_NOT_A_FILE; 47 return FILE_ERROR_NOT_A_FILE;
48 48
49 // The file's entry should have its file specific info. 49 // The file's entry should have its file specific info.
50 DCHECK(entry.has_file_specific_info()); 50 DCHECK(entry->has_file_specific_info());
51 51
52 // For a hosted document, we create a special JSON file to represent the 52 // For a hosted document, we create a special JSON file to represent the
53 // document instead of fetching the document content in one of the exported 53 // document instead of fetching the document content in one of the exported
54 // formats. The JSON file contains the edit URL and resource ID of the 54 // formats. The JSON file contains the edit URL and resource ID of the
55 // document. 55 // document.
56 if (entry.file_specific_info().is_hosted_document()) { 56 if (entry->file_specific_info().is_hosted_document()) {
57 base::FilePath gdoc_file_path; 57 base::FilePath gdoc_file_path;
58 if (!file_util::CreateTemporaryFileInDir( 58 if (!file_util::CreateTemporaryFileInDir(
59 cache->GetCacheDirectoryPath( 59 cache->GetCacheDirectoryPath(
60 internal::FileCache::CACHE_TYPE_TMP_DOCUMENTS), 60 internal::FileCache::CACHE_TYPE_TMP_DOCUMENTS),
61 &gdoc_file_path) || 61 &gdoc_file_path) ||
62 !util::CreateGDocFile(gdoc_file_path, 62 !util::CreateGDocFile(gdoc_file_path,
63 GURL(entry.file_specific_info().alternate_url()), 63 GURL(entry->file_specific_info().alternate_url()),
64 entry.resource_id())) 64 entry->resource_id()))
65 return FILE_ERROR_FAILED; 65 return FILE_ERROR_FAILED;
66 66
67 *cache_file_path = gdoc_file_path; 67 *cache_file_path = gdoc_file_path;
68 return FILE_ERROR_OK; 68 return FILE_ERROR_OK;
69 } 69 }
70 70
71 // Get the cache file path if available. 71 // Get the cache file path if available.
72 cache->GetFile(entry.resource_id(), 72 cache->GetFile(entry->resource_id(),
73 entry.file_specific_info().file_md5(), 73 entry->file_specific_info().file_md5(),
74 cache_file_path); 74 cache_file_path);
75
76 // If the cache file is available and dirty, the modified file info needs to
77 // be stored in |entry|.
78 // TODO(kinaba): crbug.com/246469. The logic below is a duplicate of that in
79 // drive::FileSystem::CheckLocalModificationAndRun. We should merge them once
80 // the drive::FS side is also converted to run fully on blocking pool.
81 if (!cache_file_path->empty()) {
82 FileCacheEntry cache_entry;
83 if (cache->GetCacheEntry(entry->resource_id(),
84 entry->file_specific_info().file_md5(),
85 &cache_entry) &&
86 cache_entry.is_dirty()) {
87 base::PlatformFileInfo file_info;
88 if (file_util::GetFileInfo(*cache_file_path, &file_info)) {
89 PlatformFileInfoProto entry_file_info;
90 util::ConvertPlatformFileInfoToResourceEntry(file_info,
91 &entry_file_info);
92 *entry->mutable_file_info() = entry_file_info;
93 }
94 }
95 }
96
75 return FILE_ERROR_OK; 97 return FILE_ERROR_OK;
76 } 98 }
77 99
78 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by 100 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by
79 // the given ID. 101 // the given ID.
80 FileError CheckPreConditionForEnsureFileDownloadedByResourceId( 102 FileError CheckPreConditionForEnsureFileDownloadedByResourceId(
81 internal::ResourceMetadata* metadata, 103 internal::ResourceMetadata* metadata,
82 internal::FileCache* cache, 104 internal::FileCache* cache,
83 const std::string& resource_id, 105 const std::string& resource_id,
84 base::FilePath* cache_file_path, 106 base::FilePath* cache_file_path,
85 ResourceEntry* entry) { 107 ResourceEntry* entry) {
86 FileError error = metadata->GetResourceEntryById(resource_id, entry); 108 FileError error = metadata->GetResourceEntryById(resource_id, entry);
87 if (error != FILE_ERROR_OK) 109 if (error != FILE_ERROR_OK)
88 return error; 110 return error;
89 return CheckPreConditionForEnsureFileDownloaded( 111 return CheckPreConditionForEnsureFileDownloaded(
90 metadata, cache, *entry, cache_file_path); 112 metadata, cache, entry, cache_file_path);
91 } 113 }
92 114
93 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by 115 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by
94 // the given file path. 116 // the given file path.
95 FileError CheckPreConditionForEnsureFileDownloadedByPath( 117 FileError CheckPreConditionForEnsureFileDownloadedByPath(
96 internal::ResourceMetadata* metadata, 118 internal::ResourceMetadata* metadata,
97 internal::FileCache* cache, 119 internal::FileCache* cache,
98 const base::FilePath& file_path, 120 const base::FilePath& file_path,
99 base::FilePath* cache_file_path, 121 base::FilePath* cache_file_path,
100 ResourceEntry* entry) { 122 ResourceEntry* entry) {
101 FileError error = metadata->GetResourceEntryByPath(file_path, entry); 123 FileError error = metadata->GetResourceEntryByPath(file_path, entry);
102 if (error != FILE_ERROR_OK) 124 if (error != FILE_ERROR_OK)
103 return error; 125 return error;
104 return CheckPreConditionForEnsureFileDownloaded( 126 return CheckPreConditionForEnsureFileDownloaded(
105 metadata, cache, *entry, cache_file_path); 127 metadata, cache, entry, cache_file_path);
106 } 128 }
107 129
108 // Creates a file with unique name in |dir| and stores the path to |temp_file|. 130 // Creates a file with unique name in |dir| and stores the path to |temp_file|.
109 // Additionally, sets the permission of the file to allow read access from 131 // Additionally, sets the permission of the file to allow read access from
110 // others and group member users (i.e, "-rw-r--r--"). 132 // others and group member users (i.e, "-rw-r--r--").
111 // We need this wrapper because Drive cache files may be read from other 133 // We need this wrapper because Drive cache files may be read from other
112 // processes (e.g., cros_disks for mounting zip files). 134 // processes (e.g., cros_disks for mounting zip files).
113 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir, 135 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir,
114 base::FilePath* temp_file) { 136 base::FilePath* temp_file) {
115 if (!file_util::CreateTemporaryFileInDir(dir, temp_file)) 137 if (!file_util::CreateTemporaryFileInDir(dir, temp_file))
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 observer_->OnDirectoryChangedByOperation(file_path.DirName()); 547 observer_->OnDirectoryChangedByOperation(file_path.DirName());
526 callback.OnComplete(*cache_file_path, entry.Pass()); 548 callback.OnComplete(*cache_file_path, entry.Pass());
527 } 549 }
528 550
529 void DownloadOperation::CancelJob(JobID job_id) { 551 void DownloadOperation::CancelJob(JobID job_id) {
530 scheduler_->CancelJob(job_id); 552 scheduler_->CancelJob(job_id);
531 } 553 }
532 554
533 } // namespace file_system 555 } // namespace file_system
534 } // namespace drive 556 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698