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_GDATA_WAPI_SERVICE_H_
6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_SERVICE_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/observer_list.h"
13 #include "chrome/browser/google_apis/auth_service_observer.h"
14 #include "chrome/browser/google_apis/drive_service_interface.h"
15 #include "chrome/browser/google_apis/gdata_wapi_operations.h"
16 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
26 class URLRequestContextGetter
;
29 namespace google_apis
{
31 class OperationRunner
;
33 // This class provides documents feed service calls for WAPI (codename for
34 // DocumentsList API).
35 // Details of API call are abstracted in each operation class and this class
36 // works as a thin wrapper for the API.
37 class GDataWapiService
: public DriveServiceInterface
,
38 public AuthServiceObserver
,
39 public OperationRegistryObserver
{
41 // Instance is usually created by DriveSystemServiceFactory and owned by
44 // |url_request_context_getter| is used to initialize URLFetcher.
45 // |base_url| is used to generate URLs for communicating with the WAPI
46 // |custom_user_agent| is used for the User-Agent header in HTTP
47 // requests issued through the service if the value is not empty.
48 GDataWapiService(net::URLRequestContextGetter
* url_request_context_getter
,
50 const std::string
& custom_user_agent
);
51 virtual ~GDataWapiService();
53 AuthService
* auth_service_for_testing();
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(const std::string
& resource_id
,
95 const std::string
& etag
,
96 const EntryActionCallback
& callback
) OVERRIDE
;
97 virtual void DownloadFile(
98 const base::FilePath
& virtual_path
,
99 const base::FilePath
& local_cache_path
,
100 const GURL
& download_url
,
101 const DownloadActionCallback
& download_action_callback
,
102 const GetContentCallback
& get_content_callback
,
103 const ProgressCallback
& progress_callback
) OVERRIDE
;
104 virtual void CopyHostedDocument(
105 const std::string
& resource_id
,
106 const std::string
& new_name
,
107 const GetResourceEntryCallback
& callback
) OVERRIDE
;
108 virtual void RenameResource(
109 const std::string
& resource_id
,
110 const std::string
& new_name
,
111 const EntryActionCallback
& callback
) OVERRIDE
;
112 virtual void AddResourceToDirectory(
113 const std::string
& parent_resource_id
,
114 const std::string
& resource_id
,
115 const EntryActionCallback
& callback
) OVERRIDE
;
116 virtual void RemoveResourceFromDirectory(
117 const std::string
& parent_resource_id
,
118 const std::string
& resource_id
,
119 const EntryActionCallback
& callback
) OVERRIDE
;
120 virtual void AddNewDirectory(
121 const std::string
& parent_resource_id
,
122 const std::string
& directory_name
,
123 const GetResourceEntryCallback
& callback
) OVERRIDE
;
124 virtual void InitiateUploadNewFile(
125 const base::FilePath
& drive_file_path
,
126 const std::string
& content_type
,
127 int64 content_length
,
128 const std::string
& parent_resource_id
,
129 const std::string
& title
,
130 const InitiateUploadCallback
& callback
) OVERRIDE
;
131 virtual void InitiateUploadExistingFile(
132 const base::FilePath
& drive_file_path
,
133 const std::string
& content_type
,
134 int64 content_length
,
135 const std::string
& resource_id
,
136 const std::string
& etag
,
137 const InitiateUploadCallback
& callback
) OVERRIDE
;
138 virtual void ResumeUpload(
139 UploadMode upload_mode
,
140 const base::FilePath
& drive_file_path
,
141 const GURL
& upload_url
,
142 int64 start_position
,
144 int64 content_length
,
145 const std::string
& content_type
,
146 const scoped_refptr
<net::IOBuffer
>& buf
,
147 const UploadRangeCallback
& callback
,
148 const ProgressCallback
& progress_callback
) OVERRIDE
;
149 virtual void GetUploadStatus(
150 UploadMode upload_mode
,
151 const base::FilePath
& drive_file_path
,
152 const GURL
& upload_url
,
153 int64 content_length
,
154 const UploadRangeCallback
& callback
) OVERRIDE
;
155 virtual void AuthorizeApp(
156 const std::string
& resource_id
,
157 const std::string
& app_id
,
158 const AuthorizeAppCallback
& callback
) OVERRIDE
;
161 OperationRegistry
* operation_registry() const;
163 // AuthService::Observer override.
164 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE
;
166 // DriveServiceObserver Overrides
167 virtual void OnProgressUpdate(
168 const OperationProgressStatusList
& list
) OVERRIDE
;
170 net::URLRequestContextGetter
* url_request_context_getter_
; // Not owned.
171 scoped_ptr
<OperationRunner
> runner_
;
172 ObserverList
<DriveServiceObserver
> observers_
;
173 // Operation objects should hold a copy of this, rather than a const
174 // reference, as they may outlive this object.
175 const GDataWapiUrlGenerator url_generator_
;
176 const std::string custom_user_agent_
;
178 DISALLOW_COPY_AND_ASSIGN(GDataWapiService
);
181 } // namespace google_apis
183 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_SERVICE_H_