OLD | NEW |
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/open_file_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
14 #include "chrome/browser/chromeos/drive/drive.pb.h" | 14 #include "chrome/browser/chromeos/drive/drive.pb.h" |
15 #include "chrome/browser/chromeos/drive/file_cache.h" | 15 #include "chrome/browser/chromeos/drive/file_cache.h" |
16 #include "chrome/browser/chromeos/drive/file_errors.h" | 16 #include "chrome/browser/chromeos/drive/file_errors.h" |
17 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" | 17 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" |
18 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" | 18 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
19 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 19 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" |
20 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 20 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 | 22 |
23 using content::BrowserThread; | 23 using content::BrowserThread; |
24 | 24 |
25 namespace drive { | 25 namespace drive { |
26 namespace file_system { | 26 namespace file_system { |
27 | 27 |
28 OpenFileOperation::OpenFileOperation( | 28 OpenFileOperation::OpenFileOperation( |
29 base::SequencedTaskRunner* blocking_task_runner, | 29 base::SequencedTaskRunner* blocking_task_runner, |
30 OperationObserver* observer, | 30 OperationDelegate* delegate, |
31 JobScheduler* scheduler, | 31 JobScheduler* scheduler, |
32 internal::ResourceMetadata* metadata, | 32 internal::ResourceMetadata* metadata, |
33 internal::FileCache* cache, | 33 internal::FileCache* cache, |
34 const base::FilePath& temporary_file_directory) | 34 const base::FilePath& temporary_file_directory) |
35 : blocking_task_runner_(blocking_task_runner), | 35 : blocking_task_runner_(blocking_task_runner), |
36 observer_(observer), | 36 delegate_(delegate), |
37 cache_(cache), | 37 cache_(cache), |
38 create_file_operation_(new CreateFileOperation( | 38 create_file_operation_(new CreateFileOperation( |
39 blocking_task_runner, observer, metadata)), | 39 blocking_task_runner, delegate, metadata)), |
40 download_operation_(new DownloadOperation( | 40 download_operation_(new DownloadOperation( |
41 blocking_task_runner, observer, scheduler, | 41 blocking_task_runner, delegate, scheduler, |
42 metadata, cache, temporary_file_directory)), | 42 metadata, cache, temporary_file_directory)), |
43 weak_ptr_factory_(this) { | 43 weak_ptr_factory_(this) { |
44 } | 44 } |
45 | 45 |
46 OpenFileOperation::~OpenFileOperation() { | 46 OpenFileOperation::~OpenFileOperation() { |
47 } | 47 } |
48 | 48 |
49 void OpenFileOperation::OpenFile(const base::FilePath& file_path, | 49 void OpenFileOperation::OpenFile(const base::FilePath& file_path, |
50 OpenMode open_mode, | 50 OpenMode open_mode, |
51 const std::string& mime_type, | 51 const std::string& mime_type, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 void OpenFileOperation::CloseFile( | 164 void OpenFileOperation::CloseFile( |
165 const std::string& local_id, | 165 const std::string& local_id, |
166 scoped_ptr<base::ScopedClosureRunner> file_closer) { | 166 scoped_ptr<base::ScopedClosureRunner> file_closer) { |
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
168 DCHECK_GT(open_files_[local_id], 0); | 168 DCHECK_GT(open_files_[local_id], 0); |
169 | 169 |
170 if (--open_files_[local_id] == 0) { | 170 if (--open_files_[local_id] == 0) { |
171 // All clients closes this file, so notify to upload the file. | 171 // All clients closes this file, so notify to upload the file. |
172 open_files_.erase(local_id); | 172 open_files_.erase(local_id); |
173 observer_->OnEntryUpdatedByOperation(local_id); | 173 delegate_->OnEntryUpdatedByOperation(local_id); |
174 | 174 |
175 // Clients may have enlarged the file. By FreeDiskpSpaceIfNeededFor(0), | 175 // Clients may have enlarged the file. By FreeDiskpSpaceIfNeededFor(0), |
176 // we try to ensure (0 + the-minimum-safe-margin = 512MB as of now) space. | 176 // we try to ensure (0 + the-minimum-safe-margin = 512MB as of now) space. |
177 blocking_task_runner_->PostTask( | 177 blocking_task_runner_->PostTask( |
178 FROM_HERE, | 178 FROM_HERE, |
179 base::Bind(base::IgnoreResult( | 179 base::Bind(base::IgnoreResult( |
180 base::Bind(&internal::FileCache::FreeDiskSpaceIfNeededFor, | 180 base::Bind(&internal::FileCache::FreeDiskSpaceIfNeededFor, |
181 base::Unretained(cache_), | 181 base::Unretained(cache_), |
182 0)))); | 182 0)))); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 } // namespace file_system | 186 } // namespace file_system |
187 } // namespace drive | 187 } // namespace drive |
OLD | NEW |