OLD | NEW |
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/file_write_helper.h" | 5 #include "chrome/browser/chromeos/drive/file_write_helper.h" |
6 | 6 |
7 #include "base/threading/sequenced_worker_pool.h" | 7 #include "base/threading/sequenced_worker_pool.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 | 9 |
10 using content::BrowserThread; | 10 using content::BrowserThread; |
11 | 11 |
12 namespace gdata { | 12 namespace drive { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Emits debug log when DriveFileSystem::CloseFile() is complete. | 16 // Emits debug log when DriveFileSystem::CloseFile() is complete. |
17 void EmitDebugLogForCloseFile(const FilePath& file_path, | 17 void EmitDebugLogForCloseFile(const FilePath& file_path, |
18 DriveFileError file_error) { | 18 DriveFileError file_error) { |
19 if (file_error != DRIVE_FILE_OK) { | 19 if (file_error != DRIVE_FILE_OK) { |
20 LOG(WARNING) << "CloseFile failed: " << file_path.AsUTF8Unsafe() << ": " | 20 LOG(WARNING) << "CloseFile failed: " << file_path.AsUTF8Unsafe() << ": " |
21 << file_error; | 21 << file_error; |
22 } | 22 } |
(...skipping 26 matching lines...) Expand all Loading... |
49 file_path, | 49 file_path, |
50 callback)); | 50 callback)); |
51 } | 51 } |
52 | 52 |
53 void FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile( | 53 void FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile( |
54 const FilePath& file_path, | 54 const FilePath& file_path, |
55 const OpenFileCallback& callback, | 55 const OpenFileCallback& callback, |
56 DriveFileError error) { | 56 DriveFileError error) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 | 58 |
59 if (error != gdata::DRIVE_FILE_OK) { | 59 if (error != DRIVE_FILE_OK) { |
60 if (!callback.is_null()) { | 60 if (!callback.is_null()) { |
61 content::BrowserThread::GetBlockingPool()->PostTask( | 61 content::BrowserThread::GetBlockingPool()->PostTask( |
62 FROM_HERE, | 62 FROM_HERE, |
63 base::Bind(callback, error, FilePath())); | 63 base::Bind(callback, error, FilePath())); |
64 } | 64 } |
65 return; | 65 return; |
66 } | 66 } |
67 file_system_->OpenFile( | 67 file_system_->OpenFile( |
68 file_path, | 68 file_path, |
69 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile, | 69 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile, |
70 weak_ptr_factory_.GetWeakPtr(), | 70 weak_ptr_factory_.GetWeakPtr(), |
71 file_path, | 71 file_path, |
72 callback)); | 72 callback)); |
73 } | 73 } |
74 | 74 |
75 void FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile( | 75 void FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile( |
76 const FilePath& file_path, | 76 const FilePath& file_path, |
77 const OpenFileCallback& callback, | 77 const OpenFileCallback& callback, |
78 DriveFileError error, | 78 DriveFileError error, |
79 const FilePath& local_cache_path) { | 79 const FilePath& local_cache_path) { |
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
81 | 81 |
82 if (error != gdata::DRIVE_FILE_OK) { | 82 if (error != DRIVE_FILE_OK) { |
83 if (!callback.is_null()) { | 83 if (!callback.is_null()) { |
84 content::BrowserThread::GetBlockingPool()->PostTask( | 84 content::BrowserThread::GetBlockingPool()->PostTask( |
85 FROM_HERE, | 85 FROM_HERE, |
86 base::Bind(callback, error, FilePath())); | 86 base::Bind(callback, error, FilePath())); |
87 } | 87 } |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 if (!callback.is_null()) { | 91 if (!callback.is_null()) { |
92 content::BrowserThread::GetBlockingPool()->PostTaskAndReply( | 92 content::BrowserThread::GetBlockingPool()->PostTaskAndReply( |
93 FROM_HERE, | 93 FROM_HERE, |
94 base::Bind(callback, DRIVE_FILE_OK, local_cache_path), | 94 base::Bind(callback, DRIVE_FILE_OK, local_cache_path), |
95 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCallback, | 95 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCallback, |
96 weak_ptr_factory_.GetWeakPtr(), | 96 weak_ptr_factory_.GetWeakPtr(), |
97 file_path)); | 97 file_path)); |
98 } else { | 98 } else { |
99 PrepareWritableFileAndRunAfterCallback(file_path); | 99 PrepareWritableFileAndRunAfterCallback(file_path); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void FileWriteHelper::PrepareWritableFileAndRunAfterCallback( | 103 void FileWriteHelper::PrepareWritableFileAndRunAfterCallback( |
104 const FilePath& file_path) { | 104 const FilePath& file_path) { |
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
106 file_system_->CloseFile(file_path, | 106 file_system_->CloseFile(file_path, |
107 base::Bind(&EmitDebugLogForCloseFile, file_path)); | 107 base::Bind(&EmitDebugLogForCloseFile, file_path)); |
108 } | 108 } |
109 | 109 |
110 } // namespace gdata | 110 } // namespace drive |
OLD | NEW |