OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 return scoped_ptr<FileResource>(); | |
154 scoped_ptr<FileResource> file(new FileResource()); | |
155 | |
156 // FileResource | |
157 file->set_file_id(entry.resource_id()); | |
158 file->set_title(entry.title()); | |
159 file->set_created_date(entry.published_time()); | |
160 | |
161 if (std::find(entry.labels().begin(), entry.labels().end(), | |
162 "shared-with-me") == entry.labels().end()) { | |
163 file->set_shared_with_me_date(base::Time::Now()); | |
hidehiko
2013/09/09 03:51:59
Could you add comment, why this doesn't break the
tzik
2013/09/09 06:22:58
Done.
| |
164 } | |
165 | |
166 file->set_download_url(entry.download_url()); | |
167 file->set_mime_type(entry.content_mime_type()); | |
168 | |
169 file->set_md5_checksum(entry.file_md5()); | |
170 file->set_file_size(entry.file_size()); | |
171 | |
172 file->mutable_labels()->set_trashed(entry.deleted()); | |
173 file->set_etag(entry.etag()); | |
174 | |
175 ScopedVector<ParentReference> parents; | |
176 for (ScopedVector<Link>::const_iterator itr = entry.links().begin(); | |
hidehiko
2013/09/09 03:51:59
IIUC, we use size_t i for iteration of vector in d
tzik
2013/09/09 06:22:58
Done.
| |
177 itr != entry.links().end(); ++itr) { | |
178 const Link& link = **itr; | |
179 switch (link.type()) { | |
180 case Link::LINK_PARENT: { | |
181 scoped_ptr<ParentReference> parent(new ParentReference); | |
182 parent->set_parent_link(link.href()); | |
183 | |
184 std::string file_id = | |
185 drive::util::ExtractResourceIdFromUrl(link.href()); | |
186 parent->set_is_root(file_id == "folder:root"); | |
187 parents.push_back(parent.release()); | |
188 break; | |
189 } | |
190 case Link::LINK_EDIT: | |
191 file->set_self_link(link.href()); | |
192 break; | |
193 case Link::LINK_THUMBNAIL: | |
194 file->set_thumbnail_link(link.href()); | |
195 break; | |
196 case Link::LINK_ALTERNATE: | |
197 file->set_alternate_link(link.href()); | |
198 break; | |
199 case Link::LINK_EMBED: | |
200 file->set_embed_link(link.href()); | |
201 break; | |
202 default: | |
203 break; | |
204 } | |
205 } | |
206 file->set_parents(parents.Pass()); | |
207 | |
208 file->set_modified_date(entry.updated_time()); | |
209 file->set_last_viewed_by_me_date(entry.last_viewed_time()); | |
210 | |
211 return file.Pass(); | |
212 } | |
213 | |
149 void GDataWapiService::Initialize() { | 214 void GDataWapiService::Initialize() { |
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
151 | 216 |
152 std::vector<std::string> scopes; | 217 std::vector<std::string> scopes; |
153 scopes.push_back(util::kDocsListScope); | 218 scopes.push_back(util::kDocsListScope); |
154 scopes.push_back(kSpreadsheetsScope); | 219 scopes.push_back(kSpreadsheetsScope); |
155 scopes.push_back(kUserContentScope); | 220 scopes.push_back(kUserContentScope); |
156 // Drive App scope is required for even WAPI v3 apps access. | 221 // Drive App scope is required for even WAPI v3 apps access. |
157 scopes.push_back(util::kDriveAppsScope); | 222 scopes.push_back(util::kDriveAppsScope); |
158 sender_.reset(new RequestSender( | 223 sender_.reset(new RequestSender( |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 if (CanSendRequest()) { | 731 if (CanSendRequest()) { |
667 FOR_EACH_OBSERVER( | 732 FOR_EACH_OBSERVER( |
668 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 733 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
669 } else if (!HasRefreshToken()) { | 734 } else if (!HasRefreshToken()) { |
670 FOR_EACH_OBSERVER( | 735 FOR_EACH_OBSERVER( |
671 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 736 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
672 } | 737 } |
673 } | 738 } |
674 | 739 |
675 } // namespace drive | 740 } // namespace drive |
OLD | NEW |