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