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

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

Issue 23437026: [Drive] Add converter from ResourceEntry to FileResource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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') | no next file » | 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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/drive/drive_switches.h" 16 #include "chrome/browser/drive/drive_switches.h"
17 #include "chrome/browser/google_apis/drive_api_parser.h"
17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "net/base/escape.h" 20 #include "net/base/escape.h"
20 #include "third_party/re2/re2/re2.h" 21 #include "third_party/re2/re2/re2.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 namespace drive { 24 namespace drive {
24 namespace util { 25 namespace util {
25 26
26 bool IsDriveV2ApiEnabled() { 27 bool IsDriveV2ApiEnabled() {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (!entry) { 151 if (!entry) {
151 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL()); 152 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL());
152 return; 153 return;
153 } 154 }
154 155
155 const google_apis::Link* share_link = 156 const google_apis::Link* share_link =
156 entry->GetLinkByType(google_apis::Link::LINK_SHARE); 157 entry->GetLinkByType(google_apis::Link::LINK_SHARE);
157 callback.Run(error, share_link ? share_link->href() : GURL()); 158 callback.Run(error, share_link ? share_link->href() : GURL());
158 } 159 }
159 160
161 scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource(
162 const google_apis::ResourceEntry& entry) {
163 scoped_ptr<google_apis::FileResource> file(new google_apis::FileResource);
164
165 file->set_file_id(entry.resource_id());
166 file->set_title(entry.title());
167 file->set_created_date(entry.published_time());
168
169 if (std::find(entry.labels().begin(), entry.labels().end(),
170 "shared-with-me") == entry.labels().end()) {
171 // Set current time to mark the file is shared_with_me, since ResourceEntry
172 // doesn't have |shared_with_me_date| equivalent.
173 file->set_shared_with_me_date(base::Time::Now());
174 }
175
176 file->set_download_url(entry.download_url());
177 file->set_mime_type(entry.content_mime_type());
178
179 file->set_md5_checksum(entry.file_md5());
180 file->set_file_size(entry.file_size());
181
182 file->mutable_labels()->set_trashed(entry.deleted());
183 file->set_etag(entry.etag());
184
185 ScopedVector<google_apis::ParentReference> parents;
186 for (size_t i = 0; i < entry.links().size(); ++i) {
187 using google_apis::Link;
188 const Link& link = *entry.links()[i];
189 switch (link.type()) {
190 case Link::LINK_PARENT: {
191 scoped_ptr<google_apis::ParentReference> parent(
192 new google_apis::ParentReference);
193 parent->set_parent_link(link.href());
194
195 std::string file_id =
196 drive::util::ExtractResourceIdFromUrl(link.href());
197 parent->set_is_root(file_id == kWapiRootDirectoryResourceId);
198 parents.push_back(parent.release());
199 break;
200 }
201 case Link::LINK_EDIT:
202 file->set_self_link(link.href());
203 break;
204 case Link::LINK_THUMBNAIL:
205 file->set_thumbnail_link(link.href());
206 break;
207 case Link::LINK_ALTERNATE:
208 file->set_alternate_link(link.href());
209 break;
210 case Link::LINK_EMBED:
211 file->set_embed_link(link.href());
212 break;
213 default:
214 break;
215 }
216 }
217 file->set_parents(parents.Pass());
218
219 file->set_modified_date(entry.updated_time());
220 file->set_last_viewed_by_me_date(entry.last_viewed_time());
221
222 return file.Pass();
223 }
224
160 const char kWapiRootDirectoryResourceId[] = "folder:root"; 225 const char kWapiRootDirectoryResourceId[] = "folder:root";
161 226
162 } // namespace util 227 } // namespace util
163 } // namespace drive 228 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_api_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698