Home | History | Annotate | Download | only in drive
      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/drive/drive_service_interface.h"
     12 #include "google_apis/drive/drive_common_callbacks.h"
     13 #include "google_apis/drive/drive_entry_kinds.h"
     14 #include "google_apis/drive/gdata_errorcode.h"
     15 
     16 class GURL;
     17 
     18 namespace base {
     19 class FilePath;
     20 class Value;
     21 }  // namespace base
     22 
     23 namespace google_apis {
     24 class AccountMetadata;
     25 class AppIcon;
     26 class AppList;
     27 class AppResource;
     28 class ChangeList;
     29 class ChangeResource;
     30 class DriveAppIcon;
     31 class FileList;
     32 class FileResource;
     33 class InstalledApp;
     34 class ResourceEntry;
     35 class ResourceList;
     36 }  // namespace google_apis
     37 
     38 namespace drive {
     39 namespace util {
     40 
     41 // Returns true if Drive v2 API is enabled via commandline switch.
     42 bool IsDriveV2ApiEnabled();
     43 
     44 // Escapes ' to \' in the |str|. This is designed to use for string value of
     45 // search parameter on Drive API v2.
     46 // See also: https://developers.google.com/drive/search-parameters
     47 std::string EscapeQueryStringValue(const std::string& str);
     48 
     49 // Parses the query, and builds a search query for Drive API v2.
     50 // This only supports:
     51 //   Regular query (e.g. dog => fullText contains 'dog')
     52 //   Conjunctions
     53 //     (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat')
     54 //   Exclusion query (e.g. -cat => not fullText contains 'cat').
     55 //   Quoted query (e.g. "dog cat" => fullText contains 'dog cat').
     56 // See also: https://developers.google.com/drive/search-parameters
     57 std::string TranslateQuery(const std::string& original_query);
     58 
     59 // Extracts resource_id out of edit url.
     60 std::string ExtractResourceIdFromUrl(const GURL& url);
     61 
     62 // If |resource_id| is in the old resource ID format used by WAPI, converts it
     63 // into the new format.
     64 std::string CanonicalizeResourceId(const std::string& resource_id);
     65 
     66 // Returns a ResourceIdCanonicalizer which returns the argument.
     67 ResourceIdCanonicalizer GetIdentityResourceIdCanonicalizer();
     68 
     69 // Note: Following constants and a function are used to support GetShareUrl on
     70 // Drive API v2. Unfortunately, there is no support on Drive API v2, so we need
     71 // to fall back to GData WAPI for the GetShareUrl. Thus, these are shared by
     72 // both GDataWapiService and DriveAPIService.
     73 // TODO(hidehiko): Remove these from here, when Drive API v2 supports
     74 // GetShareUrl.
     75 
     76 // OAuth2 scopes for the GData WAPI.
     77 extern const char kDocsListScope[];
     78 extern const char kDriveAppsScope[];
     79 
     80 // Extracts an url to the sharing dialog and returns it via |callback|. If
     81 // the share url doesn't exist, then an empty url is returned.
     82 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback,
     83                          google_apis::GDataErrorCode error,
     84                          scoped_ptr<base::Value> value);
     85 
     86 // Converts AccountMetadata to AboutResource.
     87 // Here, |root_resource_id| is also needed, as it is contained by AboutResource
     88 // but not by AccountMetadata.
     89 scoped_ptr<google_apis::AboutResource>
     90 ConvertAccountMetadataToAboutResource(
     91     const google_apis::AccountMetadata& account_metadata,
     92     const std::string& root_resource_id);
     93 
     94 // Converts AccountMetadata to AppList.
     95 scoped_ptr<google_apis::AppList>
     96 ConvertAccountMetadataToAppList(
     97     const google_apis::AccountMetadata& account_metadata);
     98 
     99 // Converts ResourceEntry to FileResource.
    100 scoped_ptr<google_apis::FileResource>
    101 ConvertResourceEntryToFileResource(const google_apis::ResourceEntry& entry);
    102 
    103 // Returns the GData WAPI's Kind of the FileResource.
    104 google_apis::DriveEntryKind GetKind(
    105     const google_apis::FileResource& file_resource);
    106 
    107 // Converts FileResource to ResourceEntry.
    108 scoped_ptr<google_apis::ResourceEntry>
    109 ConvertFileResourceToResourceEntry(
    110     const google_apis::FileResource& file_resource);
    111 
    112 // Converts ChangeResource to ResourceEntry.
    113 scoped_ptr<google_apis::ResourceEntry>
    114 ConvertChangeResourceToResourceEntry(
    115     const google_apis::ChangeResource& change_resource);
    116 
    117 // Converts FileList to ResourceList.
    118 scoped_ptr<google_apis::ResourceList>
    119 ConvertFileListToResourceList(const google_apis::FileList& file_list);
    120 
    121 // Converts ChangeList to ResourceList.
    122 scoped_ptr<google_apis::ResourceList>
    123 ConvertChangeListToResourceList(const google_apis::ChangeList& change_list);
    124 
    125 // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
    126 // or an empty string if an error is found.
    127 std::string GetMd5Digest(const base::FilePath& file_path);
    128 
    129 // The resource ID for the root directory for WAPI is defined in the spec:
    130 // https://developers.google.com/google-apps/documents-list/
    131 extern const char kWapiRootDirectoryResourceId[];
    132 
    133 }  // namespace util
    134 }  // namespace drive
    135 
    136 #endif  // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
    137