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

Side by Side Diff: chrome/browser/drive/drive_api_util.cc

Issue 371883003: Files.app: Add an private API to get a download URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/drive/drive_api_util.h" 5 #include "chrome/browser/drive/drive_api_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return resource_id; 143 return resource_id;
144 } 144 }
145 145
146 ResourceIdCanonicalizer GetIdentityResourceIdCanonicalizer() { 146 ResourceIdCanonicalizer GetIdentityResourceIdCanonicalizer() {
147 return base::Bind(&Identity); 147 return base::Bind(&Identity);
148 } 148 }
149 149
150 const char kDocsListScope[] = "https://docs.google.com/feeds/"; 150 const char kDocsListScope[] = "https://docs.google.com/feeds/";
151 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; 151 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps";
152 152
153 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, 153 void ParseShareUrlAndRun(const google_apis::GetUrlCallback& callback,
154 google_apis::GDataErrorCode error, 154 google_apis::GDataErrorCode error,
155 scoped_ptr<base::Value> value) { 155 scoped_ptr<base::Value> value) {
156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
157 157
158 if (!value) { 158 if (!value) {
159 callback.Run(error, GURL()); 159 callback.Run(error, GURL());
160 return; 160 return;
161 } 161 }
162 162
163 // Parsing ResourceEntry is cheap enough to do on UI thread. 163 // Parsing ResourceEntry is cheap enough to do on UI thread.
164 scoped_ptr<google_apis::ResourceEntry> entry = 164 scoped_ptr<google_apis::ResourceEntry> entry =
165 google_apis::ResourceEntry::ExtractAndParse(*value); 165 google_apis::ResourceEntry::ExtractAndParse(*value);
166 if (!entry) { 166 if (!entry) {
167 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL()); 167 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL());
168 return; 168 return;
169 } 169 }
170 170
171 const google_apis::Link* share_link = 171 const google_apis::Link* share_link =
172 entry->GetLinkByType(google_apis::Link::LINK_SHARE); 172 entry->GetLinkByType(google_apis::Link::LINK_SHARE);
173 callback.Run(error, share_link ? share_link->href() : GURL()); 173 callback.Run(error, share_link ? share_link->href() : GURL());
174 } 174 }
175 175
176 scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource( 176 scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource(
hashimoto 2014/07/09 07:48:57 This function is unused now. Could you remove this
yoshiki 2014/07/11 13:48:50 I'll do it in the separate patch. https://coderevi
177 const google_apis::ResourceEntry& entry) { 177 const google_apis::ResourceEntry& entry) {
178 scoped_ptr<google_apis::FileResource> file(new google_apis::FileResource); 178 scoped_ptr<google_apis::FileResource> file(new google_apis::FileResource);
179 179
180 file->set_file_id(entry.resource_id()); 180 file->set_file_id(entry.resource_id());
181 file->set_title(entry.title()); 181 file->set_title(entry.title());
182 file->set_created_date(entry.published_time()); 182 file->set_created_date(entry.published_time());
183 183
184 if (std::find(entry.labels().begin(), entry.labels().end(), 184 if (std::find(entry.labels().begin(), entry.labels().end(),
185 "shared-with-me") != entry.labels().end()) { 185 "shared-with-me") != entry.labels().end()) {
186 // Set current time to mark the file is shared_with_me, since ResourceEntry 186 // Set current time to mark the file is shared_with_me, since ResourceEntry
187 // doesn't have |shared_with_me_date| equivalent. 187 // doesn't have |shared_with_me_date| equivalent.
188 file->set_shared_with_me_date(base::Time::Now()); 188 file->set_shared_with_me_date(base::Time::Now());
189 } 189 }
190 190
191 file->set_shared(std::find(entry.labels().begin(), entry.labels().end(), 191 file->set_shared(std::find(entry.labels().begin(), entry.labels().end(),
192 "shared") != entry.labels().end()); 192 "shared") != entry.labels().end());
193 193
194 file->set_download_url(entry.download_url());
194 if (entry.is_folder()) { 195 if (entry.is_folder()) {
195 file->set_mime_type(kDriveFolderMimeType); 196 file->set_mime_type(kDriveFolderMimeType);
196 } else { 197 } else {
197 std::string mime_type = GetMimeTypeFromEntryKind(entry.kind()); 198 std::string mime_type = GetMimeTypeFromEntryKind(entry.kind());
198 if (mime_type.empty()) 199 if (mime_type.empty())
199 mime_type = entry.content_mime_type(); 200 mime_type = entry.content_mime_type();
200 file->set_mime_type(mime_type); 201 file->set_mime_type(mime_type);
201 } 202 }
202 203
203 file->set_md5_checksum(entry.file_md5()); 204 file->set_md5_checksum(entry.file_md5());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 std::vector<std::string> labels; 280 std::vector<std::string> labels;
280 if (!file_resource.shared_with_me_date().is_null()) 281 if (!file_resource.shared_with_me_date().is_null())
281 labels.push_back("shared-with-me"); 282 labels.push_back("shared-with-me");
282 if (file_resource.shared()) 283 if (file_resource.shared())
283 labels.push_back("shared"); 284 labels.push_back("shared");
284 entry->set_labels(labels); 285 entry->set_labels(labels);
285 286
286 // This should be the url to download the file_resource. 287 // This should be the url to download the file_resource.
287 { 288 {
288 google_apis::Content content; 289 google_apis::Content content;
290 content.set_url(file_resource.download_url());
289 content.set_mime_type(file_resource.mime_type()); 291 content.set_mime_type(file_resource.mime_type());
290 entry->set_content(content); 292 entry->set_content(content);
291 } 293 }
292 // TODO(kochi): entry->resource_links_ 294 // TODO(kochi): entry->resource_links_
293 295
294 // For file entries 296 // For file entries
295 entry->set_filename(file_resource.title()); 297 entry->set_filename(file_resource.title());
296 entry->set_suggested_filename(file_resource.title()); 298 entry->set_suggested_filename(file_resource.title());
297 entry->set_file_md5(file_resource.md5_checksum()); 299 entry->set_file_md5(file_resource.md5_checksum());
298 entry->set_file_size(file_resource.file_size()); 300 entry->set_file_size(file_resource.file_size());
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 432
431 base::MD5Digest digest; 433 base::MD5Digest digest;
432 base::MD5Final(&digest, &context); 434 base::MD5Final(&digest, &context);
433 return MD5DigestToBase16(digest); 435 return MD5DigestToBase16(digest);
434 } 436 }
435 437
436 const char kWapiRootDirectoryResourceId[] = "folder:root"; 438 const char kWapiRootDirectoryResourceId[] = "folder:root";
437 439
438 } // namespace util 440 } // namespace util
439 } // namespace drive 441 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698