| 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 |
| 139 scoped_ptr<google_apis::ResourceEntry> | 162 scoped_ptr<google_apis::ResourceEntry> |
| 140 ConvertFileResourceToResourceEntry( | 163 ConvertFileResourceToResourceEntry( |
| 141 const google_apis::FileResource& file_resource) { | 164 const google_apis::FileResource& file_resource) { |
| 142 scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry); | 165 scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry); |
| 143 | 166 |
| 144 // ResourceEntry | 167 // ResourceEntry |
| 145 entry->set_resource_id(file_resource.file_id()); | 168 entry->set_resource_id(file_resource.file_id()); |
| 146 entry->set_id(file_resource.file_id()); | 169 entry->set_id(file_resource.file_id()); |
| 147 if (file_resource.IsDirectory()) | 170 if (file_resource.IsDirectory()) |
| 148 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); | 171 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); | 353 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); |
| 331 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { | 354 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { |
| 332 if (extension == kHostedDocumentKinds[i].extension) | 355 if (extension == kHostedDocumentKinds[i].extension) |
| 333 return true; | 356 return true; |
| 334 } | 357 } |
| 335 return extension == kUnknownHostedDocumentExtension; | 358 return extension == kUnknownHostedDocumentExtension; |
| 336 } | 359 } |
| 337 | 360 |
| 338 } // namespace util | 361 } // namespace util |
| 339 } // namespace drive | 362 } // namespace drive |
| OLD | NEW |