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

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

Issue 10831363: Remove unnecessary gdata::, fix typos. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for comment. 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 "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/gdata.pb.h" 10 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return static_cast<GDataUserData*>( 82 return static_cast<GDataUserData*>(
83 download->GetUserData(&kGDataPathKey)); 83 download->GetUserData(&kGDataPathKey));
84 } 84 }
85 85
86 void RunSubstituteGDataDownloadCallback( 86 void RunSubstituteGDataDownloadCallback(
87 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& callback, 87 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& callback,
88 const FilePath* file_path) { 88 const FilePath* file_path) {
89 callback.Run(*file_path); 89 callback.Run(*file_path);
90 } 90 }
91 91
92 gdata::GDataSystemService* GetSystemService(Profile* profile) { 92 GDataSystemService* GetSystemService(Profile* profile) {
93 gdata::GDataSystemService* system_service = 93 GDataSystemService* system_service =
94 gdata::GDataSystemServiceFactory::GetForProfile( 94 GDataSystemServiceFactory::GetForProfile(
95 profile ? profile : ProfileManager::GetDefaultProfile()); 95 profile ? profile : ProfileManager::GetDefaultProfile());
96 DCHECK(system_service); 96 DCHECK(system_service);
97 return system_service; 97 return system_service;
98 } 98 }
99 99
100 // Substitutes virtual gdata path for local temporary path. 100 // Substitutes virtual gdata path for local temporary path.
101 void SubstituteGDataDownloadPathInternal(Profile* profile, 101 void SubstituteGDataDownloadPathInternal(Profile* profile,
102 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& 102 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback&
103 callback) { 103 callback) {
104 DVLOG(1) << "SubstituteGDataDownloadPathInternal"; 104 DVLOG(1) << "SubstituteGDataDownloadPathInternal";
105 105
106 const FilePath gdata_tmp_download_dir = GetSystemService(profile)->cache()-> 106 const FilePath gdata_tmp_download_dir = GetSystemService(profile)->cache()->
107 GetCacheDirectoryPath(gdata::GDataCache::CACHE_TYPE_TMP_DOWNLOADS); 107 GetCacheDirectoryPath(GDataCache::CACHE_TYPE_TMP_DOWNLOADS);
108 108
109 // Swap the gdata path with a local path. Local path must be created 109 // Swap the gdata path with a local path. Local path must be created
110 // on a blocking thread. 110 // on a blocking thread.
111 FilePath* gdata_tmp_download_path(new FilePath()); 111 FilePath* gdata_tmp_download_path(new FilePath());
112 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, 112 BrowserThread::GetBlockingPool()->PostTaskAndReply(
113 base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath, 113 FROM_HERE,
114 base::Bind(&GDataDownloadObserver::GetGDataTempDownloadPath,
114 gdata_tmp_download_dir, 115 gdata_tmp_download_dir,
115 gdata_tmp_download_path), 116 gdata_tmp_download_path),
116 base::Bind(&RunSubstituteGDataDownloadCallback, 117 base::Bind(&RunSubstituteGDataDownloadCallback,
117 callback, 118 callback,
118 base::Owned(gdata_tmp_download_path))); 119 base::Owned(gdata_tmp_download_path)));
119 } 120 }
120 121
121 // Callback for GDataFileSystem::CreateDirectory. 122 // Callback for GDataFileSystem::CreateDirectory.
122 void OnCreateDirectory(const base::Closure& substitute_callback, 123 void OnCreateDirectory(const base::Closure& substitute_callback,
123 GDataFileError error) { 124 GDataFileError error) {
124 DVLOG(1) << "OnCreateDirectory " << error; 125 DVLOG(1) << "OnCreateDirectory " << error;
125 if (error == GDATA_FILE_OK) { 126 if (error == GDATA_FILE_OK) {
126 substitute_callback.Run(); 127 substitute_callback.Run();
127 } else { 128 } else {
128 // TODO(achuith): Handle this. 129 // TODO(achuith): Handle this.
129 NOTREACHED(); 130 NOTREACHED();
130 } 131 }
131 } 132 }
132 133
133 // Callback for GDataFileSystem::GetEntryInfoByPath. 134 // Callback for GDataFileSystem::GetEntryInfoByPath.
134 void OnEntryFound(Profile* profile, 135 void OnEntryFound(Profile* profile,
135 const FilePath& gdata_dir_path, 136 const FilePath& gdata_dir_path,
136 const base::Closure& substitute_callback, 137 const base::Closure& substitute_callback,
137 GDataFileError error, 138 GDataFileError error,
138 scoped_ptr<gdata::GDataEntryProto> entry_proto) { 139 scoped_ptr<GDataEntryProto> entry_proto) {
139 if (error == GDATA_FILE_ERROR_NOT_FOUND) { 140 if (error == GDATA_FILE_ERROR_NOT_FOUND) {
140 // Destination gdata directory doesn't exist, so create it. 141 // Destination gdata directory doesn't exist, so create it.
141 const bool is_exclusive = false, is_recursive = true; 142 const bool is_exclusive = false, is_recursive = true;
142 GetSystemService(profile)->file_system()->CreateDirectory( 143 GetSystemService(profile)->file_system()->CreateDirectory(
143 gdata_dir_path, is_exclusive, is_recursive, 144 gdata_dir_path, is_exclusive, is_recursive,
144 base::Bind(&OnCreateDirectory, substitute_callback)); 145 base::Bind(&OnCreateDirectory, substitute_callback));
145 } else if (error == GDATA_FILE_OK) { 146 } else if (error == GDATA_FILE_OK) {
146 substitute_callback.Run(); 147 substitute_callback.Run();
147 } else { 148 } else {
148 // TODO(achuith): Handle this. 149 // TODO(achuith): Handle this.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 206 }
206 207
207 // static 208 // static
208 void GDataDownloadObserver::SubstituteGDataDownloadPath(Profile* profile, 209 void GDataDownloadObserver::SubstituteGDataDownloadPath(Profile* profile,
209 const FilePath& gdata_path, content::DownloadItem* download, 210 const FilePath& gdata_path, content::DownloadItem* download,
210 const SubstituteGDataDownloadPathCallback& callback) { 211 const SubstituteGDataDownloadPathCallback& callback) {
211 DVLOG(1) << "SubstituteGDataDownloadPath " << gdata_path.value(); 212 DVLOG(1) << "SubstituteGDataDownloadPath " << gdata_path.value();
212 213
213 SetDownloadParams(gdata_path, download); 214 SetDownloadParams(gdata_path, download);
214 215
215 if (gdata::util::IsUnderGDataMountPoint(gdata_path)) { 216 if (util::IsUnderGDataMountPoint(gdata_path)) {
216 // Can't access drive if we're not authenticated. 217 // Can't access drive if we're not authenticated.
217 // We set off a chain of callbacks as follows: 218 // We set off a chain of callbacks as follows:
218 // DocumentsService::Authenticate 219 // DocumentsService::Authenticate
219 // OnAuthenticate calls GDataFileSystem::GetEntryInfoByPath 220 // OnAuthenticate calls GDataFileSystem::GetEntryInfoByPath
220 // OnEntryFound calls GDataFileSystem::CreateDirectory (if necessary) 221 // OnEntryFound calls GDataFileSystem::CreateDirectory (if necessary)
221 // OnCreateDirectory calls SubstituteGDataDownloadPathInternal 222 // OnCreateDirectory calls SubstituteGDataDownloadPathInternal
222 GetSystemService(profile)->docs_service()->Authenticate( 223 GetSystemService(profile)->docs_service()->Authenticate(
223 base::Bind(&OnAuthenticate, profile, gdata_path, 224 base::Bind(&OnAuthenticate, profile, gdata_path,
224 base::Bind(&SubstituteGDataDownloadPathInternal, 225 base::Bind(&SubstituteGDataDownloadPathInternal,
225 profile, callback))); 226 profile, callback)));
226 } else { 227 } else {
227 callback.Run(gdata_path); 228 callback.Run(gdata_path);
228 } 229 }
229 } 230 }
230 231
231 // static 232 // static
232 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path, 233 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path,
233 DownloadItem* download) { 234 DownloadItem* download) {
234 if (!download) 235 if (!download)
235 return; 236 return;
236 237
237 if (gdata::util::IsUnderGDataMountPoint(gdata_path)) { 238 if (util::IsUnderGDataMountPoint(gdata_path)) {
238 download->SetUserData(&kGDataPathKey, 239 download->SetUserData(&kGDataPathKey,
239 new GDataUserData(gdata_path)); 240 new GDataUserData(gdata_path));
240 download->SetDisplayName(gdata_path.BaseName()); 241 download->SetDisplayName(gdata_path.BaseName());
241 download->SetIsTemporary(true); 242 download->SetIsTemporary(true);
242 } else if (IsGDataDownload(download)) { 243 } else if (IsGDataDownload(download)) {
243 // This may have been previously set if the default download folder is 244 // This may have been previously set if the default download folder is
244 // /drive, and the user has now changed the download target to a local 245 // /drive, and the user has now changed the download target to a local
245 // folder. 246 // folder.
246 download->SetUserData(&kGDataPathKey, NULL); 247 download->SetUserData(&kGDataPathKey, NULL);
247 download->SetDisplayName(gdata_path); 248 download->SetDisplayName(gdata_path);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // 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.
576 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, 577 file_system_->AddUploadedFile(UPLOAD_NEW_FILE,
577 upload_data->virtual_dir_path(), 578 upload_data->virtual_dir_path(),
578 entry.Pass(), 579 entry.Pass(),
579 download->GetTargetFilePath(), 580 download->GetTargetFilePath(),
580 GDataCache::FILE_OPERATION_MOVE, 581 GDataCache::FILE_OPERATION_MOVE,
581 base::Bind(&base::DoNothing)); 582 base::Bind(&base::DoNothing));
582 } 583 }
583 584
584 } // namespace gdata 585 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_task_executor.cc ('k') | chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698