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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_download_observer.cc

Issue 10874028: Rename GDataFileSystem* to DriveFileSystem* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 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/gdata/gdata_download_observer.h" 5 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/supports_user_data.h" 11 #include "base/supports_user_data.h"
12 #include "chrome/browser/chromeos/gdata/drive.pb.h" 12 #include "chrome/browser/chromeos/gdata/drive.pb.h"
13 #include "chrome/browser/chromeos/gdata/drive_file_system_interface.h"
13 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" 14 #include "chrome/browser/chromeos/gdata/drive_service_interface.h"
14 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h"
15 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 15 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
16 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" 16 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h"
17 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" 17 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
18 #include "chrome/browser/chromeos/gdata/gdata_util.h" 18 #include "chrome/browser/chromeos/gdata/gdata_util.h"
19 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" 19 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
20 #include "chrome/browser/download/download_completion_blocker.h" 20 #include "chrome/browser/download/download_completion_blocker.h"
21 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
23 23
24 using content::BrowserThread; 24 using content::BrowserThread;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 BrowserThread::GetBlockingPool()->PostTaskAndReply( 126 BrowserThread::GetBlockingPool()->PostTaskAndReply(
127 FROM_HERE, 127 FROM_HERE,
128 base::Bind(&GDataDownloadObserver::GetGDataTempDownloadPath, 128 base::Bind(&GDataDownloadObserver::GetGDataTempDownloadPath,
129 gdata_tmp_download_dir, 129 gdata_tmp_download_dir,
130 gdata_tmp_download_path), 130 gdata_tmp_download_path),
131 base::Bind(&RunSubstituteGDataDownloadCallback, 131 base::Bind(&RunSubstituteGDataDownloadCallback,
132 callback, 132 callback,
133 base::Owned(gdata_tmp_download_path))); 133 base::Owned(gdata_tmp_download_path)));
134 } 134 }
135 135
136 // Callback for GDataFileSystem::CreateDirectory. 136 // Callback for DriveFileSystem::CreateDirectory.
137 void OnCreateDirectory(const base::Closure& substitute_callback, 137 void OnCreateDirectory(const base::Closure& substitute_callback,
138 DriveFileError error) { 138 DriveFileError error) {
139 DVLOG(1) << "OnCreateDirectory " << error; 139 DVLOG(1) << "OnCreateDirectory " << error;
140 if (error == DRIVE_FILE_OK) { 140 if (error == DRIVE_FILE_OK) {
141 substitute_callback.Run(); 141 substitute_callback.Run();
142 } else { 142 } else {
143 // TODO(achuith): Handle this. 143 // TODO(achuith): Handle this.
144 NOTREACHED(); 144 NOTREACHED();
145 } 145 }
146 } 146 }
147 147
148 // Callback for GDataFileSystem::GetEntryInfoByPath. 148 // Callback for DriveFileSystem::GetEntryInfoByPath.
149 void OnEntryFound(Profile* profile, 149 void OnEntryFound(Profile* profile,
150 const FilePath& gdata_dir_path, 150 const FilePath& gdata_dir_path,
151 const base::Closure& substitute_callback, 151 const base::Closure& substitute_callback,
152 DriveFileError error, 152 DriveFileError error,
153 scoped_ptr<DriveEntryProto> entry_proto) { 153 scoped_ptr<DriveEntryProto> entry_proto) {
154 if (error == DRIVE_FILE_ERROR_NOT_FOUND) { 154 if (error == DRIVE_FILE_ERROR_NOT_FOUND) {
155 // Destination gdata directory doesn't exist, so create it. 155 // Destination gdata directory doesn't exist, so create it.
156 const bool is_exclusive = false, is_recursive = true; 156 const bool is_exclusive = false, is_recursive = true;
157 GetSystemService(profile)->file_system()->CreateDirectory( 157 GetSystemService(profile)->file_system()->CreateDirectory(
158 gdata_dir_path, is_exclusive, is_recursive, 158 gdata_dir_path, is_exclusive, is_recursive,
(...skipping 10 matching lines...) Expand all
169 void OnAuthenticate(Profile* profile, 169 void OnAuthenticate(Profile* profile,
170 const FilePath& gdata_path, 170 const FilePath& gdata_path,
171 const base::Closure& substitute_callback, 171 const base::Closure& substitute_callback,
172 GDataErrorCode error, 172 GDataErrorCode error,
173 const std::string& token) { 173 const std::string& token) {
174 DVLOG(1) << "OnAuthenticate"; 174 DVLOG(1) << "OnAuthenticate";
175 175
176 if (error == HTTP_SUCCESS) { 176 if (error == HTTP_SUCCESS) {
177 const FilePath gdata_dir_path = 177 const FilePath gdata_dir_path =
178 util::ExtractGDataPath(gdata_path.DirName()); 178 util::ExtractGDataPath(gdata_path.DirName());
179 // Ensure the directory exists. This also forces GDataFileSystem to 179 // Ensure the directory exists. This also forces DriveFileSystem to
180 // initialize GDataRootDirectory. 180 // initialize GDataRootDirectory.
181 GetSystemService(profile)->file_system()->GetEntryInfoByPath( 181 GetSystemService(profile)->file_system()->GetEntryInfoByPath(
182 gdata_dir_path, 182 gdata_dir_path,
183 base::Bind(&OnEntryFound, profile, gdata_dir_path, 183 base::Bind(&OnEntryFound, profile, gdata_dir_path,
184 substitute_callback)); 184 substitute_callback));
185 } else { 185 } else {
186 // TODO(achuith): Handle this. 186 // TODO(achuith): Handle this.
187 NOTREACHED(); 187 NOTREACHED();
188 } 188 }
189 } 189 }
190 190
191 } // namespace 191 } // namespace
192 192
193 GDataDownloadObserver::GDataDownloadObserver( 193 GDataDownloadObserver::GDataDownloadObserver(
194 GDataUploader* uploader, 194 GDataUploader* uploader,
195 GDataFileSystemInterface* file_system) 195 DriveFileSystemInterface* file_system)
196 : gdata_uploader_(uploader), 196 : gdata_uploader_(uploader),
197 file_system_(file_system), 197 file_system_(file_system),
198 download_manager_(NULL), 198 download_manager_(NULL),
199 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 199 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
200 } 200 }
201 201
202 GDataDownloadObserver::~GDataDownloadObserver() { 202 GDataDownloadObserver::~GDataDownloadObserver() {
203 if (download_manager_) 203 if (download_manager_)
204 download_manager_->RemoveObserver(this); 204 download_manager_->RemoveObserver(this);
205 205
(...skipping 18 matching lines...) Expand all
224 const FilePath& gdata_path, content::DownloadItem* download, 224 const FilePath& gdata_path, content::DownloadItem* download,
225 const SubstituteGDataDownloadPathCallback& callback) { 225 const SubstituteGDataDownloadPathCallback& callback) {
226 DVLOG(1) << "SubstituteGDataDownloadPath " << gdata_path.value(); 226 DVLOG(1) << "SubstituteGDataDownloadPath " << gdata_path.value();
227 227
228 SetDownloadParams(gdata_path, download); 228 SetDownloadParams(gdata_path, download);
229 229
230 if (util::IsUnderGDataMountPoint(gdata_path)) { 230 if (util::IsUnderGDataMountPoint(gdata_path)) {
231 // Can't access drive if we're not authenticated. 231 // Can't access drive if we're not authenticated.
232 // We set off a chain of callbacks as follows: 232 // We set off a chain of callbacks as follows:
233 // DriveServiceInterface::Authenticate 233 // DriveServiceInterface::Authenticate
234 // OnAuthenticate calls GDataFileSystem::GetEntryInfoByPath 234 // OnAuthenticate calls DriveFileSystem::GetEntryInfoByPath
235 // OnEntryFound calls GDataFileSystem::CreateDirectory (if necessary) 235 // OnEntryFound calls DriveFileSystem::CreateDirectory (if necessary)
236 // OnCreateDirectory calls SubstituteGDataDownloadPathInternal 236 // OnCreateDirectory calls SubstituteGDataDownloadPathInternal
237 GetSystemService(profile)->drive_service()->Authenticate( 237 GetSystemService(profile)->drive_service()->Authenticate(
238 base::Bind(&OnAuthenticate, profile, gdata_path, 238 base::Bind(&OnAuthenticate, profile, gdata_path,
239 base::Bind(&SubstituteGDataDownloadPathInternal, 239 base::Bind(&SubstituteGDataDownloadPathInternal,
240 profile, callback))); 240 profile, callback)));
241 } else { 241 } else {
242 callback.Run(gdata_path); 242 callback.Run(gdata_path);
243 } 243 }
244 } 244 }
245 245
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 DVLOG(1) << "Pending download not found" << download_id; 621 DVLOG(1) << "Pending download not found" << download_id;
622 return; 622 return;
623 } 623 }
624 DVLOG(1) << "Completing upload for download ID " << download_id; 624 DVLOG(1) << "Completing upload for download ID " << download_id;
625 DownloadItem* download_item = iter->second; 625 DownloadItem* download_item = iter->second;
626 626
627 UploadingUserData* upload_data = GetUploadingUserData(download_item); 627 UploadingUserData* upload_data = GetUploadingUserData(download_item);
628 DCHECK(upload_data); 628 DCHECK(upload_data);
629 629
630 // Take ownership of the DocumentEntry from UploadFileInfo. This is used by 630 // Take ownership of the DocumentEntry from UploadFileInfo. This is used by
631 // GDataFileSystem::AddUploadedFile() to add the entry to DriveCache after the 631 // DriveFileSystem::AddUploadedFile() to add the entry to DriveCache after the
632 // upload completes. 632 // upload completes.
633 upload_data->set_entry(upload_file_info->entry.Pass()); 633 upload_data->set_entry(upload_file_info->entry.Pass());
634 634
635 // Allow the download item to complete. 635 // Allow the download item to complete.
636 upload_data->CompleteDownload(); 636 upload_data->CompleteDownload();
637 } 637 }
638 638
639 void GDataDownloadObserver::MoveFileToDriveCache(DownloadItem* download) { 639 void GDataDownloadObserver::MoveFileToDriveCache(DownloadItem* download) {
640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
641 641
(...skipping 23 matching lines...) Expand all
665 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, 665 file_system_->AddUploadedFile(UPLOAD_NEW_FILE,
666 upload_data->virtual_dir_path(), 666 upload_data->virtual_dir_path(),
667 entry.Pass(), 667 entry.Pass(),
668 download->GetTargetFilePath(), 668 download->GetTargetFilePath(),
669 DriveCache::FILE_OPERATION_MOVE, 669 DriveCache::FILE_OPERATION_MOVE,
670 base::Bind(&base::DoNothing)); 670 base::Bind(&base::DoNothing));
671 } 671 }
672 } 672 }
673 673
674 } // namespace gdata 674 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_download_observer.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698