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.
5 #ifndef CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_SERVICE_H_
6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_SERVICE_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "chrome/browser/google_apis/auth_service_observer.h"
13 #include "chrome/browser/google_apis/drive_api_url_generator.h"
14 #include "chrome/browser/google_apis/drive_service_interface.h"
15 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
25 class URLRequestContextGetter
;
28 namespace google_apis
{
29 class OperationRunner
;
31 // This class provides Drive operation calls using Drive V2 API.
32 // Details of API call are abstracted in each operation class and this class
33 // works as a thin wrapper for the API.
34 class DriveAPIService
: public DriveServiceInterface
,
35 public AuthServiceObserver
,
36 public OperationRegistryObserver
{
38 // Instance is usually created by DriveSystemServiceFactory and owned by
41 // |url_request_context_getter| is used to initialize URLFetcher.
42 // |base_url| is used to generate URLs for communication with the drive API.
43 // |wapi_base_url| is used to generate URLs for communication with
44 // the GData WAPI server. Note that this should only be used for the hacky
45 // workaround for the operations which is not-yet supported on Drive API v2.
46 // |custom_user_agent| will be used for the User-Agent header in HTTP
47 // requests issues through the service if the value is not empty.
49 net::URLRequestContextGetter
* url_request_context_getter
,
51 const GURL
& wapi_base_url
,
52 const std::string
& custom_user_agent
);
53 virtual ~DriveAPIService();
55 // DriveServiceInterface Overrides
56 virtual void Initialize(Profile
* profile
) OVERRIDE
;
57 virtual void AddObserver(DriveServiceObserver
* observer
) OVERRIDE
;
58 virtual void RemoveObserver(DriveServiceObserver
* observer
) OVERRIDE
;
59 virtual bool CanStartOperation() const OVERRIDE
;
60 virtual void CancelAll() OVERRIDE
;
61 virtual bool CancelForFilePath(const base::FilePath
& file_path
) OVERRIDE
;
62 virtual OperationProgressStatusList
GetProgressStatusList() const OVERRIDE
;
63 virtual bool HasAccessToken() const OVERRIDE
;
64 virtual bool HasRefreshToken() const OVERRIDE
;
65 virtual void ClearAccessToken() OVERRIDE
;
66 virtual void ClearRefreshToken() OVERRIDE
;
67 virtual std::string
GetRootResourceId() const OVERRIDE
;
68 virtual void GetAllResourceList(
69 const GetResourceListCallback
& callback
) OVERRIDE
;
70 virtual void GetResourceListInDirectory(
71 const std::string
& directory_resource_id
,
72 const GetResourceListCallback
& callback
) OVERRIDE
;
74 const std::string
& search_query
,
75 const GetResourceListCallback
& callback
) OVERRIDE
;
76 virtual void SearchInDirectory(
77 const std::string
& search_query
,
78 const std::string
& directory_resource_id
,
79 const GetResourceListCallback
& callback
) OVERRIDE
;
80 virtual void GetChangeList(
81 int64 start_changestamp
,
82 const GetResourceListCallback
& callback
) OVERRIDE
;
83 virtual void ContinueGetResourceList(
84 const GURL
& override_url
,
85 const GetResourceListCallback
& callback
) OVERRIDE
;
86 virtual void GetResourceEntry(
87 const std::string
& resource_id
,
88 const GetResourceEntryCallback
& callback
) OVERRIDE
;
89 virtual void GetAccountMetadata(
90 const GetAccountMetadataCallback
& callback
) OVERRIDE
;
91 virtual void GetAboutResource(
92 const GetAboutResourceCallback
& callback
) OVERRIDE
;
93 virtual void GetAppList(const GetAppListCallback
& callback
) OVERRIDE
;
94 virtual void DeleteResource(
95 const std::string
& resource_id
,
96 const std::string
& etag
,
97 const EntryActionCallback
& callback
) OVERRIDE
;
98 virtual void DownloadFile(
99 const base::FilePath
& virtual_path
,
100 const base::FilePath
& local_cache_path
,
101 const GURL
& download_url
,
102 const DownloadActionCallback
& download_action_callback
,
103 const GetContentCallback
& get_content_callback
,
104 const ProgressCallback
& progress_callback
) OVERRIDE
;
105 virtual void CopyHostedDocument(
106 const std::string
& resource_id
,
107 const std::string
& new_name
,
108 const GetResourceEntryCallback
& callback
) OVERRIDE
;
109 virtual void RenameResource(
110 const std::string
& resource_id
,
111 const std::string
& new_name
,
112 const EntryActionCallback
& callback
) OVERRIDE
;
113 virtual void AddResourceToDirectory(
114 const std::string
& parent_resource_id
,
115 const std::string
& resource_id
,
116 const EntryActionCallback
& callback
) OVERRIDE
;
117 virtual void RemoveResourceFromDirectory(
118 const std::string
& parent_resource_id
,
119 const std::string
& resource_id
,
120 const EntryActionCallback
& callback
) OVERRIDE
;
121 virtual void AddNewDirectory(
122 const std::string
& parent_resource_id
,
123 const std::string
& directory_name
,
124 const GetResourceEntryCallback
& callback
) OVERRIDE
;
125 virtual void InitiateUploadNewFile(
126 const base::FilePath
& drive_file_path
,
127 const std::string
& content_type
,
128 int64 content_length
,
129 const std::string
& parent_resource_id
,
130 const std::string
& title
,
131 const InitiateUploadCallback
& callback
) OVERRIDE
;
132 virtual void InitiateUploadExistingFile(
133 const base::FilePath
& drive_file_path
,
134 const std::string
& content_type
,
135 int64 content_length
,
136 const std::string
& resource_id
,
137 const std::string
& etag
,
138 const InitiateUploadCallback
& callback
) OVERRIDE
;
139 virtual void ResumeUpload(
140 UploadMode upload_mode
,
141 const base::FilePath
& drive_file_path
,
142 const GURL
& upload_url
,
143 int64 start_position
,
145 int64 content_length
,
146 const std::string
& content_type
,
147 const scoped_refptr
<net::IOBuffer
>& buf
,
148 const UploadRangeCallback
& callback
,
149 const ProgressCallback
& progress_callback
) OVERRIDE
;
150 virtual void GetUploadStatus(
151 UploadMode upload_mode
,
152 const base::FilePath
& drive_file_path
,
153 const GURL
& upload_url
,
154 int64 content_length
,
155 const UploadRangeCallback
& callback
) OVERRIDE
;
156 virtual void AuthorizeApp(
157 const std::string
& resource_id
,
158 const std::string
& app_id
,
159 const AuthorizeAppCallback
& callback
) OVERRIDE
;
162 OperationRegistry
* operation_registry() const;
164 // AuthServiceObserver override.
165 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE
;
167 // DriveServiceObserver Overrides
168 virtual void OnProgressUpdate(
169 const OperationProgressStatusList
& list
) OVERRIDE
;
171 net::URLRequestContextGetter
* url_request_context_getter_
;
173 scoped_ptr
<OperationRunner
> runner_
;
174 ObserverList
<DriveServiceObserver
> observers_
;
175 DriveApiUrlGenerator url_generator_
;
176 GDataWapiUrlGenerator wapi_url_generator_
;
177 const std::string custom_user_agent_
;
179 DISALLOW_COPY_AND_ASSIGN(DriveAPIService
);
182 } // namespace google_apis
184 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_SERVICE_H_