| 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" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "google_apis/drive/drive_api_parser.h" | 18 #include "google_apis/drive/drive_api_parser.h" |
| 19 #include "google_apis/drive/gdata_wapi_parser.h" | 19 #include "google_apis/drive/gdata_wapi_parser.h" |
| 20 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 21 #include "third_party/re2/re2/re2.h" | 21 #include "third_party/re2/re2/re2.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 namespace drive { | 24 namespace drive { |
| 25 namespace util { | 25 namespace util { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Returns the argument string. | |
| 29 std::string Identity(const std::string& resource_id) { return resource_id; } | |
| 30 | |
| 31 struct HostedDocumentKind { | 28 struct HostedDocumentKind { |
| 32 const char* mime_type; | 29 const char* mime_type; |
| 33 const char* extension; | 30 const char* extension; |
| 34 }; | 31 }; |
| 35 | 32 |
| 36 const HostedDocumentKind kHostedDocumentKinds[] = { | 33 const HostedDocumentKind kHostedDocumentKinds[] = { |
| 37 {kGoogleDocumentMimeType, ".gdoc"}, | 34 {kGoogleDocumentMimeType, ".gdoc"}, |
| 38 {kGoogleSpreadsheetMimeType, ".gsheet"}, | 35 {kGoogleSpreadsheetMimeType, ".gsheet"}, |
| 39 {kGooglePresentationMimeType, ".gslides"}, | 36 {kGooglePresentationMimeType, ".gslides"}, |
| 40 {kGoogleDrawingMimeType, ".gdraw"}, | 37 {kGoogleDrawingMimeType, ".gdraw"}, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 std::string CanonicalizeResourceId(const std::string& resource_id) { | 129 std::string CanonicalizeResourceId(const std::string& resource_id) { |
| 133 // 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 |
| 134 // "document:", strip it and return the remaining part. | 131 // "document:", strip it and return the remaining part. |
| 135 std::string stripped_resource_id; | 132 std::string stripped_resource_id; |
| 136 if (RE2::FullMatch(resource_id, "^[a-z-]+(?::|%3A)([\\w-]+)$", | 133 if (RE2::FullMatch(resource_id, "^[a-z-]+(?::|%3A)([\\w-]+)$", |
| 137 &stripped_resource_id)) | 134 &stripped_resource_id)) |
| 138 return stripped_resource_id; | 135 return stripped_resource_id; |
| 139 return resource_id; | 136 return resource_id; |
| 140 } | 137 } |
| 141 | 138 |
| 142 ResourceIdCanonicalizer GetIdentityResourceIdCanonicalizer() { | |
| 143 return base::Bind(&Identity); | |
| 144 } | |
| 145 | |
| 146 const char kDocsListScope[] = "https://docs.google.com/feeds/"; | 139 const char kDocsListScope[] = "https://docs.google.com/feeds/"; |
| 147 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; | 140 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; |
| 148 | 141 |
| 149 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, | 142 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, |
| 150 google_apis::GDataErrorCode error, | 143 google_apis::GDataErrorCode error, |
| 151 scoped_ptr<base::Value> value) { | 144 scoped_ptr<base::Value> value) { |
| 152 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 145 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 153 | 146 |
| 154 if (!value) { | 147 if (!value) { |
| 155 callback.Run(error, GURL()); | 148 callback.Run(error, GURL()); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); | 356 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); |
| 364 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { | 357 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { |
| 365 if (extension == kHostedDocumentKinds[i].extension) | 358 if (extension == kHostedDocumentKinds[i].extension) |
| 366 return true; | 359 return true; |
| 367 } | 360 } |
| 368 return extension == kUnknownHostedDocumentExtension; | 361 return extension == kUnknownHostedDocumentExtension; |
| 369 } | 362 } |
| 370 | 363 |
| 371 } // namespace util | 364 } // namespace util |
| 372 } // namespace drive | 365 } // namespace drive |
| OLD | NEW |