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_DRIVE_GDATA_WAPI_SERVICE_H_
6 #define CHROME_BROWSER_DRIVE_GDATA_WAPI_SERVICE_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "chrome/browser/drive/drive_service_interface.h"
15 #include "google_apis/drive/auth_service_interface.h"
16 #include "google_apis/drive/auth_service_observer.h"
17 #include "google_apis/drive/gdata_wapi_requests.h"
18 #include "google_apis/drive/gdata_wapi_url_generator.h"
21 class OAuth2TokenService
;
25 class SequencedTaskRunner
;
28 namespace google_apis
{
33 class URLRequestContextGetter
;
38 // This class provides documents feed service calls for WAPI (codename for
39 // DocumentsList API).
40 // Details of API call are abstracted in each request class and this class
41 // works as a thin wrapper for the API.
42 class GDataWapiService
: public DriveServiceInterface
,
43 public google_apis::AuthServiceObserver
{
45 // |oauth2_token_service| is used for obtaining OAuth2 access tokens.
46 // |url_request_context_getter| is used to initialize URLFetcher.
47 // |blocking_task_runner| is used to run blocking tasks (like parsing JSON).
48 // |base_url| is used to generate URLs for communicating with the WAPI
49 // |base_download_url| is used to generate URLs for downloading file with WAPI
50 // |custom_user_agent| is used for the User-Agent header in HTTP
51 // requests issued through the service if the value is not empty.
52 GDataWapiService(OAuth2TokenService
* oauth2_token_service
,
53 net::URLRequestContextGetter
* url_request_context_getter
,
54 base::SequencedTaskRunner
* blocking_task_runner
,
56 const GURL
& base_download_url
,
57 const std::string
& custom_user_agent
);
58 virtual ~GDataWapiService();
60 // DriveServiceInterface Overrides
61 virtual void Initialize(const std::string
& account_id
) OVERRIDE
;
62 virtual void AddObserver(DriveServiceObserver
* observer
) OVERRIDE
;
63 virtual void RemoveObserver(DriveServiceObserver
* observer
) OVERRIDE
;
64 virtual bool CanSendRequest() const OVERRIDE
;
65 virtual ResourceIdCanonicalizer
GetResourceIdCanonicalizer() const OVERRIDE
;
66 virtual bool HasAccessToken() const OVERRIDE
;
67 virtual void RequestAccessToken(
68 const google_apis::AuthStatusCallback
& callback
) OVERRIDE
;
69 virtual bool HasRefreshToken() const OVERRIDE
;
70 virtual void ClearAccessToken() OVERRIDE
;
71 virtual void ClearRefreshToken() OVERRIDE
;
72 virtual std::string
GetRootResourceId() const OVERRIDE
;
73 virtual google_apis::CancelCallback
GetAllResourceList(
74 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
75 virtual google_apis::CancelCallback
GetResourceListInDirectory(
76 const std::string
& directory_resource_id
,
77 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
78 virtual google_apis::CancelCallback
Search(
79 const std::string
& search_query
,
80 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
81 virtual google_apis::CancelCallback
SearchByTitle(
82 const std::string
& title
,
83 const std::string
& directory_resource_id
,
84 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
85 virtual google_apis::CancelCallback
GetChangeList(
86 int64 start_changestamp
,
87 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
88 virtual google_apis::CancelCallback
GetRemainingChangeList(
89 const GURL
& next_link
,
90 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
91 virtual google_apis::CancelCallback
GetRemainingFileList(
92 const GURL
& next_link
,
93 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
94 virtual google_apis::CancelCallback
GetResourceEntry(
95 const std::string
& resource_id
,
96 const google_apis::GetResourceEntryCallback
& callback
) OVERRIDE
;
97 virtual google_apis::CancelCallback
GetShareUrl(
98 const std::string
& resource_id
,
99 const GURL
& embed_origin
,
100 const google_apis::GetShareUrlCallback
& callback
) OVERRIDE
;
101 virtual google_apis::CancelCallback
GetAboutResource(
102 const google_apis::AboutResourceCallback
& callback
) OVERRIDE
;
103 virtual google_apis::CancelCallback
GetAppList(
104 const google_apis::AppListCallback
& callback
) OVERRIDE
;
105 virtual google_apis::CancelCallback
DeleteResource(
106 const std::string
& resource_id
,
107 const std::string
& etag
,
108 const google_apis::EntryActionCallback
& callback
) OVERRIDE
;
109 virtual google_apis::CancelCallback
TrashResource(
110 const std::string
& resource_id
,
111 const google_apis::EntryActionCallback
& callback
) OVERRIDE
;
112 virtual google_apis::CancelCallback
DownloadFile(
113 const base::FilePath
& local_cache_path
,
114 const std::string
& resource_id
,
115 const google_apis::DownloadActionCallback
& download_action_callback
,
116 const google_apis::GetContentCallback
& get_content_callback
,
117 const google_apis::ProgressCallback
& progress_callback
) OVERRIDE
;
118 virtual google_apis::CancelCallback
CopyResource(
119 const std::string
& resource_id
,
120 const std::string
& parent_resource_id
,
121 const std::string
& new_title
,
122 const base::Time
& last_modified
,
123 const google_apis::GetResourceEntryCallback
& callback
) OVERRIDE
;
124 virtual google_apis::CancelCallback
UpdateResource(
125 const std::string
& resource_id
,
126 const std::string
& parent_resource_id
,
127 const std::string
& new_title
,
128 const base::Time
& last_modified
,
129 const base::Time
& last_viewed_by_me
,
130 const google_apis::GetResourceEntryCallback
& callback
) OVERRIDE
;
131 virtual google_apis::CancelCallback
RenameResource(
132 const std::string
& resource_id
,
133 const std::string
& new_title
,
134 const google_apis::EntryActionCallback
& callback
) OVERRIDE
;
135 virtual google_apis::CancelCallback
AddResourceToDirectory(
136 const std::string
& parent_resource_id
,
137 const std::string
& resource_id
,
138 const google_apis::EntryActionCallback
& callback
) OVERRIDE
;
139 virtual google_apis::CancelCallback
RemoveResourceFromDirectory(
140 const std::string
& parent_resource_id
,
141 const std::string
& resource_id
,
142 const google_apis::EntryActionCallback
& callback
) OVERRIDE
;
143 virtual google_apis::CancelCallback
AddNewDirectory(
144 const std::string
& parent_resource_id
,
145 const std::string
& directory_title
,
146 const AddNewDirectoryOptions
& options
,
147 const google_apis::GetResourceEntryCallback
& callback
) OVERRIDE
;
148 virtual google_apis::CancelCallback
InitiateUploadNewFile(
149 const std::string
& content_type
,
150 int64 content_length
,
151 const std::string
& parent_resource_id
,
152 const std::string
& title
,
153 const InitiateUploadNewFileOptions
& options
,
154 const google_apis::InitiateUploadCallback
& callback
) OVERRIDE
;
155 virtual google_apis::CancelCallback
InitiateUploadExistingFile(
156 const std::string
& content_type
,
157 int64 content_length
,
158 const std::string
& resource_id
,
159 const InitiateUploadExistingFileOptions
& options
,
160 const google_apis::InitiateUploadCallback
& callback
) OVERRIDE
;
161 virtual google_apis::CancelCallback
ResumeUpload(
162 const GURL
& upload_url
,
163 int64 start_position
,
165 int64 content_length
,
166 const std::string
& content_type
,
167 const base::FilePath
& local_file_path
,
168 const google_apis::UploadRangeCallback
& callback
,
169 const google_apis::ProgressCallback
& progress_callback
) OVERRIDE
;
170 virtual google_apis::CancelCallback
GetUploadStatus(
171 const GURL
& upload_url
,
172 int64 content_length
,
173 const google_apis::UploadRangeCallback
& callback
) OVERRIDE
;
174 virtual google_apis::CancelCallback
AuthorizeApp(
175 const std::string
& resource_id
,
176 const std::string
& app_id
,
177 const google_apis::AuthorizeAppCallback
& callback
) OVERRIDE
;
178 virtual google_apis::CancelCallback
UninstallApp(
179 const std::string
& app_id
,
180 const google_apis::EntryActionCallback
& callback
) OVERRIDE
;
181 virtual google_apis::CancelCallback
GetResourceListInDirectoryByWapi(
182 const std::string
& directory_resource_id
,
183 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
184 virtual google_apis::CancelCallback
GetRemainingResourceList(
185 const GURL
& next_link
,
186 const google_apis::GetResourceListCallback
& callback
) OVERRIDE
;
189 // AuthService::Observer override.
190 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE
;
192 OAuth2TokenService
* oauth2_token_service_
; // Not owned.
193 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter_
;
194 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
195 scoped_ptr
<google_apis::RequestSender
> sender_
;
196 ObserverList
<DriveServiceObserver
> observers_
;
197 // Request objects should hold a copy of this, rather than a const
198 // reference, as they may outlive this object.
199 const google_apis::GDataWapiUrlGenerator url_generator_
;
200 const std::string custom_user_agent_
;
202 DISALLOW_COPY_AND_ASSIGN(GDataWapiService
);
207 #endif // CHROME_BROWSER_DRIVE_GDATA_WAPI_SERVICE_H_