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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 std::string CanonicalizeResourceId(const std::string& resource_id) { | 129 std::string CanonicalizeResourceId(const std::string& resource_id) { |
130 // If resource ID is in the old WAPI format starting with a prefix like | 130 // If resource ID is in the old WAPI format starting with a prefix like |
131 // "document:", strip it and return the remaining part. | 131 // "document:", strip it and return the remaining part. |
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 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, | |
140 google_apis::GDataErrorCode error, | |
141 scoped_ptr<base::Value> value) { | |
142 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
143 | |
144 if (!value) { | |
145 callback.Run(error, GURL()); | |
146 return; | |
147 } | |
148 | |
149 // Parsing ResourceEntry is cheap enough to do on UI thread. | |
150 scoped_ptr<google_apis::ResourceEntry> entry = | |
151 google_apis::ResourceEntry::ExtractAndParse(*value); | |
152 if (!entry) { | |
153 callback.Run(google_apis::GDATA_PARSE_ERROR, GURL()); | |
154 return; | |
155 } | |
156 | |
157 const google_apis::Link* share_link = | |
158 entry->GetLinkByType(google_apis::Link::LINK_SHARE); | |
159 callback.Run(error, share_link ? share_link->href() : GURL()); | |
160 } | |
161 | |
162 scoped_ptr<google_apis::ResourceEntry> | 139 scoped_ptr<google_apis::ResourceEntry> |
163 ConvertFileResourceToResourceEntry( | 140 ConvertFileResourceToResourceEntry( |
164 const google_apis::FileResource& file_resource) { | 141 const google_apis::FileResource& file_resource) { |
165 scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry); | 142 scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry); |
166 | 143 |
167 // ResourceEntry | 144 // ResourceEntry |
168 entry->set_resource_id(file_resource.file_id()); | 145 entry->set_resource_id(file_resource.file_id()); |
169 entry->set_id(file_resource.file_id()); | 146 entry->set_id(file_resource.file_id()); |
170 if (file_resource.IsDirectory()) | 147 if (file_resource.IsDirectory()) |
171 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); | 148 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); | 330 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); |
354 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { | 331 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { |
355 if (extension == kHostedDocumentKinds[i].extension) | 332 if (extension == kHostedDocumentKinds[i].extension) |
356 return true; | 333 return true; |
357 } | 334 } |
358 return extension == kUnknownHostedDocumentExtension; | 335 return extension == kUnknownHostedDocumentExtension; |
359 } | 336 } |
360 | 337 |
361 } // namespace util | 338 } // namespace util |
362 } // namespace drive | 339 } // namespace drive |
OLD | NEW |