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

Side by Side Diff: chrome/browser/chromeos/file_manager/snapshot_manager.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/file_manager/snapshot_manager.h" 5 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/sys_info.h" 8 #include "base/sys_info.h"
9 #include "chrome/browser/chromeos/file_manager/app_id.h" 9 #include "chrome/browser/chromeos/file_manager/app_id.h"
10 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 10 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "google_apis/drive/task_util.h" 13 #include "google_apis/drive/task_util.h"
14 #include "third_party/cros_system_api/constants/cryptohome.h" 14 #include "third_party/cros_system_api/constants/cryptohome.h"
15 #include "webkit/browser/fileapi/file_system_context.h" 15 #include "storage/browser/fileapi/file_system_context.h"
16 #include "webkit/common/blob/shareable_file_reference.h" 16 #include "storage/common/blob/shareable_file_reference.h"
17 17
18 namespace file_manager { 18 namespace file_manager {
19 namespace { 19 namespace {
20 20
21 typedef base::Callback<void(int64)> GetNecessaryFreeSpaceCallback; 21 typedef base::Callback<void(int64)> GetNecessaryFreeSpaceCallback;
22 22
23 // Part of ComputeSpaceNeedToBeFreed. 23 // Part of ComputeSpaceNeedToBeFreed.
24 int64 ComputeSpaceNeedToBeFreedAfterGetMetadataOnBlockingPool( 24 int64 ComputeSpaceNeedToBeFreedAfterGetMetadataOnBlockingPool(
25 const base::FilePath& path, 25 const base::FilePath& path,
26 int64 snapshot_size) { 26 int64 snapshot_size) {
(...skipping 22 matching lines...) Expand all
49 base::PostTaskAndReplyWithResult( 49 base::PostTaskAndReplyWithResult(
50 content::BrowserThread::GetBlockingPool(), 50 content::BrowserThread::GetBlockingPool(),
51 FROM_HERE, 51 FROM_HERE,
52 base::Bind(&ComputeSpaceNeedToBeFreedAfterGetMetadataOnBlockingPool, 52 base::Bind(&ComputeSpaceNeedToBeFreedAfterGetMetadataOnBlockingPool,
53 path, file_info.size), 53 path, file_info.size),
54 callback); 54 callback);
55 } 55 }
56 56
57 // Part of ComputeSpaceNeedToBeFreed. 57 // Part of ComputeSpaceNeedToBeFreed.
58 void GetMetadataOnIOThread(const base::FilePath& path, 58 void GetMetadataOnIOThread(const base::FilePath& path,
59 scoped_refptr<fileapi::FileSystemContext> context, 59 scoped_refptr<storage::FileSystemContext> context,
60 const fileapi::FileSystemURL& url, 60 const storage::FileSystemURL& url,
61 const GetNecessaryFreeSpaceCallback& callback) { 61 const GetNecessaryFreeSpaceCallback& callback) {
62 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 62 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
63 context->operation_runner()->GetMetadata( 63 context->operation_runner()->GetMetadata(
64 url, 64 url,
65 base::Bind(&ComputeSpaceNeedToBeFreedAfterGetMetadata, path, callback)); 65 base::Bind(&ComputeSpaceNeedToBeFreedAfterGetMetadata, path, callback));
66 } 66 }
67 67
68 // Computes the size of space that need to be __additionally__ made available 68 // Computes the size of space that need to be __additionally__ made available
69 // in the |profile|'s data directory for taking the snapshot of |url|. 69 // in the |profile|'s data directory for taking the snapshot of |url|.
70 // Returns 0 if no additional space is required, or -1 in the case of an error. 70 // Returns 0 if no additional space is required, or -1 in the case of an error.
71 void ComputeSpaceNeedToBeFreed( 71 void ComputeSpaceNeedToBeFreed(
72 Profile* profile, 72 Profile* profile,
73 scoped_refptr<fileapi::FileSystemContext> context, 73 scoped_refptr<storage::FileSystemContext> context,
74 const fileapi::FileSystemURL& url, 74 const storage::FileSystemURL& url,
75 const GetNecessaryFreeSpaceCallback& callback) { 75 const GetNecessaryFreeSpaceCallback& callback) {
76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
77 content::BrowserThread::PostTask( 77 content::BrowserThread::PostTask(
78 content::BrowserThread::IO, 78 content::BrowserThread::IO,
79 FROM_HERE, 79 FROM_HERE,
80 base::Bind(&GetMetadataOnIOThread, profile->GetPath(), context, url, 80 base::Bind(&GetMetadataOnIOThread, profile->GetPath(), context, url,
81 google_apis::CreateRelayCallback(callback))); 81 google_apis::CreateRelayCallback(callback)));
82 } 82 }
83 83
84 // Part of CreateManagedSnapshot. Runs CreateSnapshotFile method of fileapi. 84 // Part of CreateManagedSnapshot. Runs CreateSnapshotFile method of fileapi.
85 void CreateSnapshotFileOnIOThread( 85 void CreateSnapshotFileOnIOThread(
86 scoped_refptr<fileapi::FileSystemContext> context, 86 scoped_refptr<storage::FileSystemContext> context,
87 const fileapi::FileSystemURL& url, 87 const storage::FileSystemURL& url,
88 const fileapi::FileSystemOperation::SnapshotFileCallback& callback) { 88 const storage::FileSystemOperation::SnapshotFileCallback& callback) {
89 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 89 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
90 context->operation_runner()->CreateSnapshotFile(url, callback); 90 context->operation_runner()->CreateSnapshotFile(url, callback);
91 } 91 }
92 92
93 // Utility for destructing the bound |file_refs| on IO thread. This is meant 93 // Utility for destructing the bound |file_refs| on IO thread. This is meant
94 // to be used together with base::Bind. After this function finishes, the 94 // to be used together with base::Bind. After this function finishes, the
95 // Bind callback should destruct the bound argument. 95 // Bind callback should destruct the bound argument.
96 void FreeReferenceOnIOThread( 96 void FreeReferenceOnIOThread(
97 const std::deque<SnapshotManager::FileReferenceWithSizeInfo>& file_refs) { 97 const std::deque<SnapshotManager::FileReferenceWithSizeInfo>& file_refs) {
98 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 98 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 SnapshotManager::FileReferenceWithSizeInfo::FileReferenceWithSizeInfo( 103 SnapshotManager::FileReferenceWithSizeInfo::FileReferenceWithSizeInfo(
104 scoped_refptr<webkit_blob::ShareableFileReference> ref, 104 scoped_refptr<storage::ShareableFileReference> ref,
105 int64 size) : file_ref(ref), file_size(size) { 105 int64 size)
106 : file_ref(ref), file_size(size) {
106 } 107 }
107 108
108 SnapshotManager::FileReferenceWithSizeInfo::~FileReferenceWithSizeInfo() { 109 SnapshotManager::FileReferenceWithSizeInfo::~FileReferenceWithSizeInfo() {
109 } 110 }
110 111
111 SnapshotManager::SnapshotManager(Profile* profile) 112 SnapshotManager::SnapshotManager(Profile* profile)
112 : profile_(profile), weak_ptr_factory_(this) { 113 : profile_(profile), weak_ptr_factory_(this) {
113 } 114 }
114 115
115 SnapshotManager::~SnapshotManager() { 116 SnapshotManager::~SnapshotManager() {
116 if (!file_refs_.empty()) { 117 if (!file_refs_.empty()) {
117 bool posted = content::BrowserThread::PostTask( 118 bool posted = content::BrowserThread::PostTask(
118 content::BrowserThread::IO, 119 content::BrowserThread::IO,
119 FROM_HERE, 120 FROM_HERE,
120 base::Bind(&FreeReferenceOnIOThread, file_refs_)); 121 base::Bind(&FreeReferenceOnIOThread, file_refs_));
121 DCHECK(posted); 122 DCHECK(posted);
122 } 123 }
123 } 124 }
124 125
125 void SnapshotManager::CreateManagedSnapshot( 126 void SnapshotManager::CreateManagedSnapshot(
126 const base::FilePath& absolute_file_path, 127 const base::FilePath& absolute_file_path,
127 const LocalPathCallback& callback) { 128 const LocalPathCallback& callback) {
128 scoped_refptr<fileapi::FileSystemContext> context( 129 scoped_refptr<storage::FileSystemContext> context(
129 util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId)); 130 util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId));
130 DCHECK(context); 131 DCHECK(context);
131 132
132 GURL url; 133 GURL url;
133 if (!util::ConvertAbsoluteFilePathToFileSystemUrl( 134 if (!util::ConvertAbsoluteFilePathToFileSystemUrl(
134 profile_, absolute_file_path, kFileManagerAppId, &url)) { 135 profile_, absolute_file_path, kFileManagerAppId, &url)) {
135 callback.Run(base::FilePath()); 136 callback.Run(base::FilePath());
136 return; 137 return;
137 } 138 }
138 fileapi::FileSystemURL filesystem_url = context->CrackURL(url); 139 storage::FileSystemURL filesystem_url = context->CrackURL(url);
139 140
140 ComputeSpaceNeedToBeFreed(profile_, context, filesystem_url, 141 ComputeSpaceNeedToBeFreed(profile_, context, filesystem_url,
141 base::Bind(&SnapshotManager::CreateManagedSnapshotAfterSpaceComputed, 142 base::Bind(&SnapshotManager::CreateManagedSnapshotAfterSpaceComputed,
142 weak_ptr_factory_.GetWeakPtr(), 143 weak_ptr_factory_.GetWeakPtr(),
143 filesystem_url, 144 filesystem_url,
144 callback)); 145 callback));
145 } 146 }
146 147
147 void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed( 148 void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed(
148 const fileapi::FileSystemURL& filesystem_url, 149 const storage::FileSystemURL& filesystem_url,
149 const LocalPathCallback& callback, 150 const LocalPathCallback& callback,
150 int64 needed_space) { 151 int64 needed_space) {
151 scoped_refptr<fileapi::FileSystemContext> context( 152 scoped_refptr<storage::FileSystemContext> context(
152 util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId)); 153 util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId));
153 DCHECK(context); 154 DCHECK(context);
154 155
155 if (needed_space < 0) { 156 if (needed_space < 0) {
156 callback.Run(base::FilePath()); 157 callback.Run(base::FilePath());
157 return; 158 return;
158 } 159 }
159 160
160 // Free up to the required size. 161 // Free up to the required size.
161 std::deque<FileReferenceWithSizeInfo> to_free; 162 std::deque<FileReferenceWithSizeInfo> to_free;
(...skipping 27 matching lines...) Expand all
189 base::Bind(&SnapshotManager::OnCreateSnapshotFile, 190 base::Bind(&SnapshotManager::OnCreateSnapshotFile,
190 weak_ptr_factory_.GetWeakPtr(), 191 weak_ptr_factory_.GetWeakPtr(),
191 callback)))); 192 callback))));
192 } 193 }
193 194
194 void SnapshotManager::OnCreateSnapshotFile( 195 void SnapshotManager::OnCreateSnapshotFile(
195 const LocalPathCallback& callback, 196 const LocalPathCallback& callback,
196 base::File::Error result, 197 base::File::Error result,
197 const base::File::Info& file_info, 198 const base::File::Info& file_info,
198 const base::FilePath& platform_path, 199 const base::FilePath& platform_path,
199 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { 200 const scoped_refptr<storage::ShareableFileReference>& file_ref) {
200 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 201 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
201 202
202 if (result != base::File::FILE_OK) { 203 if (result != base::File::FILE_OK) {
203 callback.Run(base::FilePath()); 204 callback.Run(base::FilePath());
204 return; 205 return;
205 } 206 }
206 207
207 file_refs_.push_back(FileReferenceWithSizeInfo(file_ref, file_info.size)); 208 file_refs_.push_back(FileReferenceWithSizeInfo(file_ref, file_info.size));
208 callback.Run(platform_path); 209 callback.Run(platform_path);
209 } 210 }
210 211
211 } // namespace file_manager 212 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/snapshot_manager.h ('k') | chrome/browser/chromeos/file_manager/volume_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698