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

Side by Side Diff: chrome/browser/chromeos/drive/download_handler.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/download_handler.h" 5 #include "chrome/browser/chromeos/drive/download_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/supports_user_data.h" 9 #include "base/supports_user_data.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/browser/chromeos/drive/drive.pb.h" 11 #include "chrome/browser/chromeos/drive/drive.pb.h"
12 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 12 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
13 #include "chrome/browser/chromeos/drive/file_system_interface.h" 13 #include "chrome/browser/chromeos/drive/file_system_interface.h"
14 #include "chrome/browser/chromeos/drive/file_system_util.h" 14 #include "chrome/browser/chromeos/drive/file_system_util.h"
15 #include "chrome/browser/chromeos/drive/file_write_helper.h" 15 #include "chrome/browser/chromeos/drive/write_on_cache_file.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 17
18 using content::BrowserThread; 18 using content::BrowserThread;
19 using content::DownloadManager; 19 using content::DownloadManager;
20 using content::DownloadItem; 20 using content::DownloadItem;
21 21
22 namespace drive { 22 namespace drive {
23 namespace { 23 namespace {
24 24
25 // Key for base::SupportsUserData::Data. 25 // Key for base::SupportsUserData::Data.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 bool IsPersistedDriveDownload(const base::FilePath& drive_tmp_download_path, 88 bool IsPersistedDriveDownload(const base::FilePath& drive_tmp_download_path,
89 DownloadItem* download) { 89 DownloadItem* download) {
90 // Persisted downloads are not in IN_PROGRESS state when created, while newly 90 // Persisted downloads are not in IN_PROGRESS state when created, while newly
91 // created downloads are. 91 // created downloads are.
92 return drive_tmp_download_path.IsParent(download->GetTargetFilePath()) && 92 return drive_tmp_download_path.IsParent(download->GetTargetFilePath()) &&
93 download->GetState() != DownloadItem::IN_PROGRESS; 93 download->GetState() != DownloadItem::IN_PROGRESS;
94 } 94 }
95 95
96 } // namespace 96 } // namespace
97 97
98 DownloadHandler::DownloadHandler( 98 DownloadHandler::DownloadHandler(FileSystemInterface* file_system)
99 FileWriteHelper* file_write_helper, 99 : file_system_(file_system),
100 FileSystemInterface* file_system)
101 : file_write_helper_(file_write_helper),
102 file_system_(file_system),
103 weak_ptr_factory_(this) { 100 weak_ptr_factory_(this) {
104 } 101 }
105 102
106 DownloadHandler::~DownloadHandler() { 103 DownloadHandler::~DownloadHandler() {
107 } 104 }
108 105
109 // static 106 // static
110 DownloadHandler* DownloadHandler::GetForProfile(Profile* profile) { 107 DownloadHandler* DownloadHandler::GetForProfile(Profile* profile) {
111 DriveIntegrationService* integration_service = 108 DriveIntegrationService* integration_service =
112 DriveIntegrationServiceFactory::FindForProfile(profile); 109 DriveIntegrationServiceFactory::FindForProfile(profile);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 callback); 293 callback);
297 } else { 294 } else {
298 LOG(WARNING) << "Failed to create directory, error = " 295 LOG(WARNING) << "Failed to create directory, error = "
299 << FileErrorToString(error); 296 << FileErrorToString(error);
300 callback.Run(base::FilePath()); 297 callback.Run(base::FilePath());
301 } 298 }
302 } 299 }
303 300
304 void DownloadHandler::UploadDownloadItem(DownloadItem* download) { 301 void DownloadHandler::UploadDownloadItem(DownloadItem* download) {
305 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); 302 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState());
306 file_write_helper_->PrepareWritableFileAndRun( 303 WriteOnCacheFile(
304 file_system_,
307 util::ExtractDrivePath(GetTargetPath(download)), 305 util::ExtractDrivePath(GetTargetPath(download)),
308 base::Bind(&MoveDownloadedFile, download->GetTargetFilePath())); 306 base::Bind(&MoveDownloadedFile, download->GetTargetFilePath()));
309 } 307 }
310 308
311 } // namespace drive 309 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/download_handler.h ('k') | chrome/browser/chromeos/drive/download_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698