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/gdata/gdata_download_observer.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.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 "chrome/browser/chromeos/gdata/documents_service_interface.h" | 10 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
11 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 11 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
12 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
13 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 13 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
14 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" | 14 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" |
15 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
16 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
17 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
18 #include "chrome/browser/download/download_completion_blocker.h" | 18 #include "chrome/browser/download/download_completion_blocker.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 gdata_dir_path, is_exclusive, is_recursive, | 144 gdata_dir_path, is_exclusive, is_recursive, |
145 base::Bind(&OnCreateDirectory, substitute_callback)); | 145 base::Bind(&OnCreateDirectory, substitute_callback)); |
146 } else if (error == GDATA_FILE_OK) { | 146 } else if (error == GDATA_FILE_OK) { |
147 substitute_callback.Run(); | 147 substitute_callback.Run(); |
148 } else { | 148 } else { |
149 // TODO(achuith): Handle this. | 149 // TODO(achuith): Handle this. |
150 NOTREACHED(); | 150 NOTREACHED(); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 // Callback for DocumentsServiceInterface::Authenticate. | 154 // Callback for DriveServiceInterface::Authenticate. |
155 void OnAuthenticate(Profile* profile, | 155 void OnAuthenticate(Profile* profile, |
156 const FilePath& gdata_path, | 156 const FilePath& gdata_path, |
157 const base::Closure& substitute_callback, | 157 const base::Closure& substitute_callback, |
158 GDataErrorCode error, | 158 GDataErrorCode error, |
159 const std::string& token) { | 159 const std::string& token) { |
160 DVLOG(1) << "OnAuthenticate"; | 160 DVLOG(1) << "OnAuthenticate"; |
161 | 161 |
162 if (error == HTTP_SUCCESS) { | 162 if (error == HTTP_SUCCESS) { |
163 const FilePath gdata_dir_path = | 163 const FilePath gdata_dir_path = |
164 util::ExtractGDataPath(gdata_path.DirName()); | 164 util::ExtractGDataPath(gdata_path.DirName()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 void GDataDownloadObserver::SubstituteGDataDownloadPath(Profile* profile, | 209 void GDataDownloadObserver::SubstituteGDataDownloadPath(Profile* profile, |
210 const FilePath& gdata_path, content::DownloadItem* download, | 210 const FilePath& gdata_path, content::DownloadItem* download, |
211 const SubstituteGDataDownloadPathCallback& callback) { | 211 const SubstituteGDataDownloadPathCallback& callback) { |
212 DVLOG(1) << "SubstituteGDataDownloadPath " << gdata_path.value(); | 212 DVLOG(1) << "SubstituteGDataDownloadPath " << gdata_path.value(); |
213 | 213 |
214 SetDownloadParams(gdata_path, download); | 214 SetDownloadParams(gdata_path, download); |
215 | 215 |
216 if (util::IsUnderGDataMountPoint(gdata_path)) { | 216 if (util::IsUnderGDataMountPoint(gdata_path)) { |
217 // Can't access drive if we're not authenticated. | 217 // Can't access drive if we're not authenticated. |
218 // We set off a chain of callbacks as follows: | 218 // We set off a chain of callbacks as follows: |
219 // DocumentsServiceInterface::Authenticate | 219 // DriveServiceInterface::Authenticate |
220 // OnAuthenticate calls GDataFileSystem::GetEntryInfoByPath | 220 // OnAuthenticate calls GDataFileSystem::GetEntryInfoByPath |
221 // OnEntryFound calls GDataFileSystem::CreateDirectory (if necessary) | 221 // OnEntryFound calls GDataFileSystem::CreateDirectory (if necessary) |
222 // OnCreateDirectory calls SubstituteGDataDownloadPathInternal | 222 // OnCreateDirectory calls SubstituteGDataDownloadPathInternal |
223 GetSystemService(profile)->docs_service()->Authenticate( | 223 GetSystemService(profile)->drive_service()->Authenticate( |
224 base::Bind(&OnAuthenticate, profile, gdata_path, | 224 base::Bind(&OnAuthenticate, profile, gdata_path, |
225 base::Bind(&SubstituteGDataDownloadPathInternal, | 225 base::Bind(&SubstituteGDataDownloadPathInternal, |
226 profile, callback))); | 226 profile, callback))); |
227 } else { | 227 } else { |
228 callback.Run(gdata_path); | 228 callback.Run(gdata_path); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 // static | 232 // static |
233 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path, | 233 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path, |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 // use the final target path when the download item is in COMPLETE state. | 576 // use the final target path when the download item is in COMPLETE state. |
577 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, | 577 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, |
578 upload_data->virtual_dir_path(), | 578 upload_data->virtual_dir_path(), |
579 entry.Pass(), | 579 entry.Pass(), |
580 download->GetTargetFilePath(), | 580 download->GetTargetFilePath(), |
581 GDataCache::FILE_OPERATION_MOVE, | 581 GDataCache::FILE_OPERATION_MOVE, |
582 base::Bind(&base::DoNothing)); | 582 base::Bind(&base::DoNothing)); |
583 } | 583 } |
584 | 584 |
585 } // namespace gdata | 585 } // namespace gdata |
OLD | NEW |