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