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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ 6 #define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ 7 8 #include <string> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "chrome/browser/google_apis/drive_common_callbacks.h" 12 #include "chrome/browser/google_apis/gdata_errorcode.h" 13 14 class GURL; 15 16 namespace base { 17 class Value; 18 } // namespace base 19 20 namespace drive { 21 namespace util { 22 23 // Returns true if Drive v2 API is enabled via commandline switch. 24 bool IsDriveV2ApiEnabled(); 25 26 // Escapes ' to \' in the |str|. This is designed to use for string value of 27 // search parameter on Drive API v2. 28 // See also: https://developers.google.com/drive/search-parameters 29 std::string EscapeQueryStringValue(const std::string& str); 30 31 // Parses the query, and builds a search query for Drive API v2. 32 // This only supports: 33 // Regular query (e.g. dog => fullText contains 'dog') 34 // Conjunctions 35 // (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat') 36 // Exclusion query (e.g. -cat => not fullText contains 'cat'). 37 // Quoted query (e.g. "dog cat" => fullText contains 'dog cat'). 38 // See also: https://developers.google.com/drive/search-parameters 39 std::string TranslateQuery(const std::string& original_query); 40 41 // Extracts resource_id out of edit url. 42 std::string ExtractResourceIdFromUrl(const GURL& url); 43 44 // If |resource_id| is in the old resource ID format used by WAPI, converts it 45 // into the new format. 46 std::string CanonicalizeResourceId(const std::string& resource_id); 47 48 // Note: Following constants and a function are used to support GetShareUrl on 49 // Drive API v2. Unfortunately, there is no support on Drive API v2, so we need 50 // to fall back to GData WAPI for the GetShareUrl. Thus, these are shared by 51 // both GDataWapiService and DriveAPIService. 52 // TODO(hidehiko): Remove these from here, when Drive API v2 supports 53 // GetShareUrl. 54 55 // OAuth2 scopes for the GData WAPI. 56 extern const char kDocsListScope[]; 57 extern const char kDriveAppsScope[]; 58 59 // Extracts an url to the sharing dialog and returns it via |callback|. If 60 // the share url doesn't exist, then an empty url is returned. 61 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, 62 google_apis::GDataErrorCode error, 63 scoped_ptr<base::Value> value); 64 65 } // namespace util 66 } // namespace drive 67 68 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ 69