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

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

Issue 381423002: [WIP] Files.app: Remove unused methods in drive_api_util.cc 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
« no previous file with comments | « chrome/browser/drive/drive_api_util.h ('k') | chrome/browser/drive/drive_api_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/md5.h" 11 #include "base/md5.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "google_apis/drive/drive_api_parser.h" 18 #include "google_apis/drive/drive_api_parser.h"
19 #include "google_apis/drive/gdata_wapi_parser.h" 19 #include "google_apis/drive/gdata_wapi_parser.h"
20 #include "net/base/escape.h" 20 #include "net/base/escape.h"
21 #include "third_party/re2/re2/re2.h" 21 #include "third_party/re2/re2/re2.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace drive { 24 namespace drive {
25 namespace util { 25 namespace util {
26 namespace { 26 namespace {
27 27
28 std::string GetMimeTypeFromEntryKind(google_apis::DriveEntryKind kind) {
29 switch (kind) {
30 case google_apis::ENTRY_KIND_DOCUMENT:
31 return kGoogleDocumentMimeType;
32 case google_apis::ENTRY_KIND_SPREADSHEET:
33 return kGoogleSpreadsheetMimeType;
34 case google_apis::ENTRY_KIND_PRESENTATION:
35 return kGooglePresentationMimeType;
36 case google_apis::ENTRY_KIND_DRAWING:
37 return kGoogleDrawingMimeType;
38 case google_apis::ENTRY_KIND_TABLE:
39 return kGoogleTableMimeType;
40 case google_apis::ENTRY_KIND_FORM:
41 return kGoogleFormMimeType;
42 default:
43 return std::string();
44 }
45 }
46
47 // Returns the argument string. 28 // Returns the argument string.
48 std::string Identity(const std::string& resource_id) { return resource_id; } 29 std::string Identity(const std::string& resource_id) { return resource_id; }
49 30
50 } // namespace 31 } // namespace
51 32
52 33
53 std::string EscapeQueryStringValue(const std::string& str) { 34 std::string EscapeQueryStringValue(const std::string& str) {
54 std::string result; 35 std::string result;
55 result.reserve(str.size()); 36 result.reserve(str.size());
56 for (size_t i = 0; i < str.size(); ++i) { 37 for (size_t i = 0; i < str.size(); ++i) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (!entry) { 147 if (!entry) {
167 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL()); 148 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL());
168 return; 149 return;
169 } 150 }
170 151
171 const google_apis::Link* share_link = 152 const google_apis::Link* share_link =
172 entry->GetLinkByType(google_apis::Link::LINK_SHARE); 153 entry->GetLinkByType(google_apis::Link::LINK_SHARE);
173 callback.Run(error, share_link ? share_link->href() : GURL()); 154 callback.Run(error, share_link ? share_link->href() : GURL());
174 } 155 }
175 156
176 scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource(
177 const google_apis::ResourceEntry& entry) {
178 scoped_ptr<google_apis::FileResource> file(new google_apis::FileResource);
179
180 file->set_file_id(entry.resource_id());
181 file->set_title(entry.title());
182 file->set_created_date(entry.published_time());
183
184 if (std::find(entry.labels().begin(), entry.labels().end(),
185 "shared-with-me") != entry.labels().end()) {
186 // Set current time to mark the file is shared_with_me, since ResourceEntry
187 // doesn't have |shared_with_me_date| equivalent.
188 file->set_shared_with_me_date(base::Time::Now());
189 }
190
191 file->set_shared(std::find(entry.labels().begin(), entry.labels().end(),
192 "shared") != entry.labels().end());
193
194 if (entry.is_folder()) {
195 file->set_mime_type(kDriveFolderMimeType);
196 } else {
197 std::string mime_type = GetMimeTypeFromEntryKind(entry.kind());
198 if (mime_type.empty())
199 mime_type = entry.content_mime_type();
200 file->set_mime_type(mime_type);
201 }
202
203 file->set_md5_checksum(entry.file_md5());
204 file->set_file_size(entry.file_size());
205
206 file->mutable_labels()->set_trashed(entry.deleted());
207 file->set_etag(entry.etag());
208
209 google_apis::ImageMediaMetadata* image_media_metadata =
210 file->mutable_image_media_metadata();
211 image_media_metadata->set_width(entry.image_width());
212 image_media_metadata->set_height(entry.image_height());
213 image_media_metadata->set_rotation(entry.image_rotation());
214
215 std::vector<google_apis::ParentReference>* parents = file->mutable_parents();
216 for (size_t i = 0; i < entry.links().size(); ++i) {
217 using google_apis::Link;
218 const Link& link = *entry.links()[i];
219 switch (link.type()) {
220 case Link::LINK_PARENT: {
221 google_apis::ParentReference parent;
222 parent.set_parent_link(link.href());
223
224 std::string file_id =
225 drive::util::ExtractResourceIdFromUrl(link.href());
226 parent.set_file_id(file_id);
227 parents->push_back(parent);
228 break;
229 }
230 case Link::LINK_ALTERNATE:
231 file->set_alternate_link(link.href());
232 break;
233 default:
234 break;
235 }
236 }
237
238 file->set_modified_date(entry.updated_time());
239 file->set_last_viewed_by_me_date(entry.last_viewed_time());
240
241 return file.Pass();
242 }
243
244 google_apis::DriveEntryKind GetKind( 157 google_apis::DriveEntryKind GetKind(
245 const google_apis::FileResource& file_resource) { 158 const google_apis::FileResource& file_resource) {
246 if (file_resource.IsDirectory()) 159 if (file_resource.IsDirectory())
247 return google_apis::ENTRY_KIND_FOLDER; 160 return google_apis::ENTRY_KIND_FOLDER;
248 161
249 const std::string& mime_type = file_resource.mime_type(); 162 const std::string& mime_type = file_resource.mime_type();
250 if (mime_type == kGoogleDocumentMimeType) 163 if (mime_type == kGoogleDocumentMimeType)
251 return google_apis::ENTRY_KIND_DOCUMENT; 164 return google_apis::ENTRY_KIND_DOCUMENT;
252 if (mime_type == kGoogleSpreadsheetMimeType) 165 if (mime_type == kGoogleSpreadsheetMimeType)
253 return google_apis::ENTRY_KIND_SPREADSHEET; 166 return google_apis::ENTRY_KIND_SPREADSHEET;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 343
431 base::MD5Digest digest; 344 base::MD5Digest digest;
432 base::MD5Final(&digest, &context); 345 base::MD5Final(&digest, &context);
433 return MD5DigestToBase16(digest); 346 return MD5DigestToBase16(digest);
434 } 347 }
435 348
436 const char kWapiRootDirectoryResourceId[] = "folder:root"; 349 const char kWapiRootDirectoryResourceId[] = "folder:root";
437 350
438 } // namespace util 351 } // namespace util
439 } // namespace drive 352 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_api_util.h ('k') | chrome/browser/drive/drive_api_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698