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

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

Issue 23437026: [Drive] Add converter from ResourceEntry to FileResource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix 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
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/gdata_wapi_service.h" 5 #include "chrome/browser/drive/gdata_wapi_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 20 matching lines...) Expand all
31 using google_apis::AuthStatusCallback; 31 using google_apis::AuthStatusCallback;
32 using google_apis::AuthorizeAppCallback; 32 using google_apis::AuthorizeAppCallback;
33 using google_apis::AuthorizeAppRequest; 33 using google_apis::AuthorizeAppRequest;
34 using google_apis::CancelCallback; 34 using google_apis::CancelCallback;
35 using google_apis::CopyHostedDocumentRequest; 35 using google_apis::CopyHostedDocumentRequest;
36 using google_apis::CreateDirectoryRequest; 36 using google_apis::CreateDirectoryRequest;
37 using google_apis::DeleteResourceRequest; 37 using google_apis::DeleteResourceRequest;
38 using google_apis::DownloadActionCallback; 38 using google_apis::DownloadActionCallback;
39 using google_apis::DownloadFileRequest; 39 using google_apis::DownloadFileRequest;
40 using google_apis::EntryActionCallback; 40 using google_apis::EntryActionCallback;
41 using google_apis::FileResource;
41 using google_apis::GDATA_PARSE_ERROR; 42 using google_apis::GDATA_PARSE_ERROR;
42 using google_apis::GDataErrorCode; 43 using google_apis::GDataErrorCode;
43 using google_apis::GetAccountMetadataRequest; 44 using google_apis::GetAccountMetadataRequest;
44 using google_apis::GetContentCallback; 45 using google_apis::GetContentCallback;
45 using google_apis::GetResourceEntryCallback; 46 using google_apis::GetResourceEntryCallback;
46 using google_apis::GetResourceEntryRequest; 47 using google_apis::GetResourceEntryRequest;
47 using google_apis::GetResourceListCallback; 48 using google_apis::GetResourceListCallback;
48 using google_apis::GetResourceListRequest; 49 using google_apis::GetResourceListRequest;
49 using google_apis::GetShareUrlCallback; 50 using google_apis::GetShareUrlCallback;
50 using google_apis::GetUploadStatusRequest; 51 using google_apis::GetUploadStatusRequest;
51 using google_apis::HTTP_NOT_IMPLEMENTED; 52 using google_apis::HTTP_NOT_IMPLEMENTED;
52 using google_apis::InitiateUploadCallback; 53 using google_apis::InitiateUploadCallback;
53 using google_apis::InitiateUploadExistingFileRequest; 54 using google_apis::InitiateUploadExistingFileRequest;
54 using google_apis::InitiateUploadNewFileRequest; 55 using google_apis::InitiateUploadNewFileRequest;
55 using google_apis::Link; 56 using google_apis::Link;
57 using google_apis::ParentReference;
56 using google_apis::ProgressCallback; 58 using google_apis::ProgressCallback;
57 using google_apis::RemoveResourceFromDirectoryRequest; 59 using google_apis::RemoveResourceFromDirectoryRequest;
58 using google_apis::RenameResourceRequest; 60 using google_apis::RenameResourceRequest;
59 using google_apis::RequestSender; 61 using google_apis::RequestSender;
60 using google_apis::ResourceEntry; 62 using google_apis::ResourceEntry;
61 using google_apis::ResumeUploadRequest; 63 using google_apis::ResumeUploadRequest;
62 using google_apis::SearchByTitleRequest; 64 using google_apis::SearchByTitleRequest;
63 using google_apis::UploadRangeCallback; 65 using google_apis::UploadRangeCallback;
64 66
65 namespace drive { 67 namespace drive {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 custom_user_agent_(custom_user_agent) { 141 custom_user_agent_(custom_user_agent) {
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
141 } 143 }
142 144
143 GDataWapiService::~GDataWapiService() { 145 GDataWapiService::~GDataWapiService() {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
145 if (sender_.get()) 147 if (sender_.get())
146 sender_->auth_service()->RemoveObserver(this); 148 sender_->auth_service()->RemoveObserver(this);
147 } 149 }
148 150
151 scoped_ptr<FileResource> GDataWapiService::ConvertResourceEntryToFileResource(
152 const ResourceEntry& entry) {
153 scoped_ptr<FileResource> file(new FileResource());
154
155 // FileResource
156 file->set_file_id(entry.resource_id());
157 file->set_title(entry.title());
158 file->set_created_date(entry.published_time());
159
160 if (std::find(entry.labels().begin(), entry.labels().end(),
161 "shared-with-me") == entry.labels().end()) {
162 file->set_shared_with_me_date(base::Time::Now());
163 }
164
165 file->set_download_url(entry.download_url());
166 file->set_mime_type(entry.content_mime_type());
167
168 file->set_md5_checksum(entry.file_md5());
169 file->set_file_size(entry.file_size());
170
171 file->mutable_labels()->set_trashed(entry.deleted());
172 file->set_etag(entry.etag());
173
174 ScopedVector<ParentReference> parents;
175 for (ScopedVector<Link>::const_iterator itr = entry.links().begin();
176 itr != entry.links().end(); ++itr) {
177 const Link& link = **itr;
178 switch (link.type()) {
179 case Link::LINK_PARENT: {
180 scoped_ptr<ParentReference> parent(new ParentReference);
181 parent->set_parent_link(link.href());
182
183 std::string file_id =
184 drive::util::ExtractResourceIdFromUrl(link.href());
185 parent->set_is_root(file_id == "folder:root");
186 parents.push_back(parent.release());
187 break;
188 }
189 case Link::LINK_EDIT:
190 file->set_self_link(link.href());
191 break;
192 case Link::LINK_THUMBNAIL:
193 file->set_thumbnail_link(link.href());
194 break;
195 case Link::LINK_ALTERNATE:
196 file->set_alternate_link(link.href());
197 break;
198 case Link::LINK_EMBED:
199 file->set_embed_link(link.href());
200 break;
201 default:
202 break;
203 }
204 }
205 file->set_parents(parents.Pass());
206
207 file->set_modified_date(entry.updated_time());
208 file->set_last_viewed_by_me_date(entry.last_viewed_time());
209
210 return file.Pass();
211 }
212
149 void GDataWapiService::Initialize() { 213 void GDataWapiService::Initialize() {
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
151 215
152 std::vector<std::string> scopes; 216 std::vector<std::string> scopes;
153 scopes.push_back(util::kDocsListScope); 217 scopes.push_back(util::kDocsListScope);
154 scopes.push_back(kSpreadsheetsScope); 218 scopes.push_back(kSpreadsheetsScope);
155 scopes.push_back(kUserContentScope); 219 scopes.push_back(kUserContentScope);
156 // Drive App scope is required for even WAPI v3 apps access. 220 // Drive App scope is required for even WAPI v3 apps access.
157 scopes.push_back(util::kDriveAppsScope); 221 scopes.push_back(util::kDriveAppsScope);
158 sender_.reset(new RequestSender( 222 sender_.reset(new RequestSender(
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 if (CanSendRequest()) { 730 if (CanSendRequest()) {
667 FOR_EACH_OBSERVER( 731 FOR_EACH_OBSERVER(
668 DriveServiceObserver, observers_, OnReadyToSendRequests()); 732 DriveServiceObserver, observers_, OnReadyToSendRequests());
669 } else if (!HasRefreshToken()) { 733 } else if (!HasRefreshToken()) {
670 FOR_EACH_OBSERVER( 734 FOR_EACH_OBSERVER(
671 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); 735 DriveServiceObserver, observers_, OnRefreshTokenInvalid());
672 } 736 }
673 } 737 }
674 738
675 } // namespace drive 739 } // namespace drive
OLDNEW
« chrome/browser/drive/gdata_wapi_service.h ('K') | « chrome/browser/drive/gdata_wapi_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698