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/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" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 std::string stripped_resource_id; | 132 std::string stripped_resource_id; |
133 if (RE2::FullMatch(resource_id, "^[a-z-]+(?::|%3A)([\\w-]+)$", | 133 if (RE2::FullMatch(resource_id, "^[a-z-]+(?::|%3A)([\\w-]+)$", |
134 &stripped_resource_id)) | 134 &stripped_resource_id)) |
135 return stripped_resource_id; | 135 return stripped_resource_id; |
136 return resource_id; | 136 return resource_id; |
137 } | 137 } |
138 | 138 |
139 const char kDocsListScope[] = "https://docs.google.com/feeds/"; | 139 const char kDocsListScope[] = "https://docs.google.com/feeds/"; |
140 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; | 140 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; |
141 | 141 |
142 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, | |
143 google_apis::GDataErrorCode error, | |
144 scoped_ptr<base::Value> value) { | |
145 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
146 | |
147 if (!value) { | |
148 callback.Run(error, GURL()); | |
149 return; | |
150 } | |
151 | |
152 // Parsing ResourceEntry is cheap enough to do on UI thread. | |
153 scoped_ptr<google_apis::ResourceEntry> entry = | |
154 google_apis::ResourceEntry::ExtractAndParse(*value); | |
155 if (!entry) { | |
156 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL()); | |
157 return; | |
158 } | |
159 | |
160 const google_apis::Link* share_link = | |
161 entry->GetLinkByType(google_apis::Link::LINK_SHARE); | |
162 callback.Run(error, share_link ? share_link->href() : GURL()); | |
163 } | |
164 | |
165 scoped_ptr<google_apis::ResourceEntry> | 142 scoped_ptr<google_apis::ResourceEntry> |
166 ConvertFileResourceToResourceEntry( | 143 ConvertFileResourceToResourceEntry( |
167 const google_apis::FileResource& file_resource) { | 144 const google_apis::FileResource& file_resource) { |
168 scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry); | 145 scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry); |
169 | 146 |
170 // ResourceEntry | 147 // ResourceEntry |
171 entry->set_resource_id(file_resource.file_id()); | 148 entry->set_resource_id(file_resource.file_id()); |
172 entry->set_id(file_resource.file_id()); | 149 entry->set_id(file_resource.file_id()); |
173 if (file_resource.IsDirectory()) | 150 if (file_resource.IsDirectory()) |
174 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); | 151 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); | 333 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); |
357 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { | 334 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { |
358 if (extension == kHostedDocumentKinds[i].extension) | 335 if (extension == kHostedDocumentKinds[i].extension) |
359 return true; | 336 return true; |
360 } | 337 } |
361 return extension == kUnknownHostedDocumentExtension; | 338 return extension == kUnknownHostedDocumentExtension; |
362 } | 339 } |
363 | 340 |
364 } // namespace util | 341 } // namespace util |
365 } // namespace drive | 342 } // namespace drive |
OLD | NEW |