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

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: 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|.
hashimoto 2013/06/03 10:33:27 nit: Could you make a note about the fact that thi
kinaba 2013/06/04 03:30:17 Done.
78 if (!cache_file_path->empty()) {
79 FileCacheEntry cache_entry;
80 if (cache->GetCacheEntry(entry->resource_id(),
81 entry->file_specific_info().file_md5(),
82 &cache_entry) &&
83 cache_entry.is_dirty()) {
84 base::PlatformFileInfo file_info;
85 if (file_util::GetFileInfo(*cache_file_path, &file_info)) {
86 PlatformFileInfoProto entry_file_info;
87 util::ConvertPlatformFileInfoToResourceEntry(file_info,
88 &entry_file_info);
89 *entry->mutable_file_info() = entry_file_info;
90 }
91 }
92 }
93
75 return FILE_ERROR_OK; 94 return FILE_ERROR_OK;
76 } 95 }
77 96
78 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by 97 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by
79 // the given ID. 98 // the given ID.
80 FileError CheckPreConditionForEnsureFileDownloadedByResourceId( 99 FileError CheckPreConditionForEnsureFileDownloadedByResourceId(
81 internal::ResourceMetadata* metadata, 100 internal::ResourceMetadata* metadata,
82 internal::FileCache* cache, 101 internal::FileCache* cache,
83 const std::string& resource_id, 102 const std::string& resource_id,
84 base::FilePath* cache_file_path, 103 base::FilePath* cache_file_path,
85 ResourceEntry* entry) { 104 ResourceEntry* entry) {
86 FileError error = metadata->GetResourceEntryById(resource_id, entry); 105 FileError error = metadata->GetResourceEntryById(resource_id, entry);
87 if (error != FILE_ERROR_OK) 106 if (error != FILE_ERROR_OK)
88 return error; 107 return error;
89 return CheckPreConditionForEnsureFileDownloaded( 108 return CheckPreConditionForEnsureFileDownloaded(
90 metadata, cache, *entry, cache_file_path); 109 metadata, cache, entry, cache_file_path);
91 } 110 }
92 111
93 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by 112 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by
94 // the given file path. 113 // the given file path.
95 FileError CheckPreConditionForEnsureFileDownloadedByPath( 114 FileError CheckPreConditionForEnsureFileDownloadedByPath(
96 internal::ResourceMetadata* metadata, 115 internal::ResourceMetadata* metadata,
97 internal::FileCache* cache, 116 internal::FileCache* cache,
98 const base::FilePath& file_path, 117 const base::FilePath& file_path,
99 base::FilePath* cache_file_path, 118 base::FilePath* cache_file_path,
100 ResourceEntry* entry) { 119 ResourceEntry* entry) {
101 FileError error = metadata->GetResourceEntryByPath(file_path, entry); 120 FileError error = metadata->GetResourceEntryByPath(file_path, entry);
102 if (error != FILE_ERROR_OK) 121 if (error != FILE_ERROR_OK)
103 return error; 122 return error;
104 return CheckPreConditionForEnsureFileDownloaded( 123 return CheckPreConditionForEnsureFileDownloaded(
105 metadata, cache, *entry, cache_file_path); 124 metadata, cache, entry, cache_file_path);
106 } 125 }
107 126
108 // Creates a file with unique name in |dir| and stores the path to |temp_file|. 127 // 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 128 // Additionally, sets the permission of the file to allow read access from
110 // others and group member users (i.e, "-rw-r--r--"). 129 // others and group member users (i.e, "-rw-r--r--").
111 // We need this wrapper because Drive cache files may be read from other 130 // We need this wrapper because Drive cache files may be read from other
112 // processes (e.g., cros_disks for mounting zip files). 131 // processes (e.g., cros_disks for mounting zip files).
113 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir, 132 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir,
114 base::FilePath* temp_file) { 133 base::FilePath* temp_file) {
115 if (!file_util::CreateTemporaryFileInDir(dir, temp_file)) 134 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()); 544 observer_->OnDirectoryChangedByOperation(file_path.DirName());
526 callback.OnComplete(*cache_file_path, entry.Pass()); 545 callback.OnComplete(*cache_file_path, entry.Pass());
527 } 546 }
528 547
529 void DownloadOperation::CancelJob(JobID job_id) { 548 void DownloadOperation::CancelJob(JobID job_id) {
530 scheduler_->CancelJob(job_id); 549 scheduler_->CancelJob(job_id);
531 } 550 }
532 551
533 } // namespace file_system 552 } // namespace file_system
534 } // namespace drive 553 } // 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