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

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 // FileResource
hidehiko 2013/09/09 06:30:08 nit: you don't need this comment.
tzik 2013/09/09 06:50:59 Done.
166 file->set_file_id(entry.resource_id());
167 file->set_title(entry.title());
168 file->set_created_date(entry.published_time());
169
170 if (std::find(entry.labels().begin(), entry.labels().end(),
171 "shared-with-me") == entry.labels().end()) {
172 // Set current time to mark the file is shared_with_me, since ResourceEntry
173 // doesn't have |shared_with_me_date| equivalent.
174 file->set_shared_with_me_date(base::Time::Now());
175 }
176
177 file->set_download_url(entry.download_url());
178 file->set_mime_type(entry.content_mime_type());
179
180 file->set_md5_checksum(entry.file_md5());
181 file->set_file_size(entry.file_size());
182
183 file->mutable_labels()->set_trashed(entry.deleted());
184 file->set_etag(entry.etag());
185
186 ScopedVector<google_apis::ParentReference> parents;
187 for (size_t i = 0; i < entry.links().size(); ++i) {
188 using google_apis::Link;
189 const Link& link = *entry.links()[i];
190 switch (link.type()) {
191 case Link::LINK_PARENT: {
192 scoped_ptr<google_apis::ParentReference> parent(
193 new google_apis::ParentReference);
194 parent->set_parent_link(link.href());
195
196 std::string file_id =
197 drive::util::ExtractResourceIdFromUrl(link.href());
198 parent->set_is_root(file_id == kWapiRootDirectoryResourceId);
199 parents.push_back(parent.release());
200 break;
201 }
202 case Link::LINK_EDIT:
203 file->set_self_link(link.href());
204 break;
205 case Link::LINK_THUMBNAIL:
206 file->set_thumbnail_link(link.href());
207 break;
208 case Link::LINK_ALTERNATE:
209 file->set_alternate_link(link.href());
210 break;
211 case Link::LINK_EMBED:
212 file->set_embed_link(link.href());
213 break;
214 default:
215 break;
216 }
217 }
218 file->set_parents(parents.Pass());
219
220 file->set_modified_date(entry.updated_time());
221 file->set_last_viewed_by_me_date(entry.last_viewed_time());
222
223 return file.Pass();
224 }
225
160 const char kWapiRootDirectoryResourceId[] = "folder:root"; 226 const char kWapiRootDirectoryResourceId[] = "folder:root";
161 227
162 } // namespace util 228 } // namespace util
163 } // namespace drive 229 } // 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